In unit tests, this doesn't work:
class SomeClassCest
{
public function tryToTest(UnitTester $I)
{
$mock = Mockery::mock(MyClass::class);
$mock->shouldReceive('action')->once()->andReturn(true);
$I->haveInstance(MyClass::class, $mock);
$classToTest = app(SomeClass::class);
// this method calls the MyClass action method
$classToTest->run();
// some asserts here
}
}
The mock doesn't take effect, the $mock->action
is never called, the real implementation is called instead. How to mock classes on unit tests with Codeception and the Laravel 5 module?
from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/2tIwd3U
via IFTTT
Aucun commentaire:
Enregistrer un commentaire