Hello lets say I want to test the function run from Class A and I'm using Mockery to mock external dependencies:
class A {
protected myB;
public function __construct(B $param) {
$this->myB = $param;
}
protected function doStuff() {
return "done";
}
public function run() {
$this->doStuff();
$this->myB->doOtherStuff();
return "finished";
}
}
class B {
public function doOtherStuff() {
return "done";
}
}
So I wrote the test like this:
public function testRun() {
$mockB = Mockery::mock('overload:B');
$mockB->shouldReceive('doOtherStuff')
->andReturn("not done");
$mockA = Mockery::mock(A::class)->makePartial()->shouldAllowMockingProtectedMethods();
$mockA->shouldReceive('doStuff')->andReturns("done");
$mockA->run();
}
This throws me an exception like this: Error: Call to a member function doStuff() on null
I tried diffrent variations of mocking the internal dependency B which is getting called in the run function but I always endend up in an exception.
What am I doing wrong here?