Inside my Export class I have created this method:
public static function getBranches()
{
return Branch::all();
}
I want to Mock this Method. Now I have the following piece of code in a testcase:
$mock = $this->partialMock(Export::class, function (MockInterface $mock) use ($employee) {
$mock->shouldReceive('getBranches')->andReturn(collect([]));
});
$this->instance(Export::class, $mock);
self::assertCount(0, $mock::getBranches()); // works fine
self::assertCount(0, Export::getBranches()); // does not work, returns number of branches in Database
I am expecting that the Export class now uses the mocked getBranches Method. But this is not happening. Do you have any ideas what is missing? or what I am misunderstanding?