mercredi 7 février 2018

Mock method from the same class that tested method is using

I have following code:

class Foo() {
    public function someMethod() {
        ...
        if ($this->otherMethod($lorem, $ipsum)) {
            ...
        }
        ...
    }
}

and I'm trying to test the someMethod(), I don't want to test otherMethod() since it's quite complex and I have dedicated tests - here I would only like to mock it and return specific values. So I tried to:

$fooMock = Mockery::mock(Foo::class)
    ->makePartial();
$fooMock->shouldReceive('otherMethod')
    ->with($lorem, $ipsum)
    ->andReturn($otherMethodReturnValue);

and in test I'm calling

$fooMock->someMethod()

But it's using the original (not mocked) method otherMethod() and prints errors.

Could you help me please?

Aucun commentaire:

Enregistrer un commentaire