I have problems when testing an Abstract type class. Currently I do things like this:
$coche = new class extends CocheAbstract {
public function hasRuedas(){}
public function setColor(MyColor $color){}
public function getErrors(){}
};
This is because my AbstractCar class has the hasWheels, setColor and getErrors methods of abstract type. This method of getting an abstract class "object" has worked fine for me so far. But I have found myself in the situation that another abstract class has a built-in constructor:
abstract class MetodosPagoAbstract
{
// aqui unos metodos abstractos
public function __construct($param1, $param2)
{
// codigo del constructor
}
}
The method I have used so far does not allow me to send parameters when creating an object of that class to test it. I have tried with:
$metodosPago = (new class extends metodosPagoAbstract {
// aqui los metodos abstractos
}($param1, $param2);
But the test complains because the constructor of the object is not called:
Time: 425 ms, Memory: 6.00 MB
There was 1 error:
1) tests\Coches\Handler\MetodosPagoAbstractTest::testConstructor
ArgumentCountError: Too few arguments to function CochesBundle\Handler\Pagos\MetodosPagosAbstract::__construct(), 0 passed in /tests/CochesBundle/Handler/MetodosPagoAbstractTest.php on line 22 and exactly 2 expected
Has anyone encountered a similar situation? Do you know how this object can be created in order to test it?