lundi 1 juin 2015

How to mock a constructor with Mockery

I need to test, that the code creates a new instance of a class with certain parameters:

$bar = new ProgressBar($output, $size);

I tried to create an alias mock and set an expectation for the __construct method, but it didn't work:

$progressBar = \Mockery::mock('alias:' . ProgressBar::class);
$progressBar->shouldReceive('__construct')
    ->with(\Mockery::type(OutputInterface::class), 3)
    ->once();

This expectation is never met: Mockery\Exception\InvalidCountException: Method __construct(object(Mockery\Matcher\Type), 3) from Symfony\Component\Console\Helper\ProgressBar should be called exactly 1 times but called 0 times.

Do you know any other way how to test this with Mockery?

Aucun commentaire:

Enregistrer un commentaire