mercredi 27 juin 2018

Mock classes on unit tests with Codeception and Laravel 5 module

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?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire