P粉8850351142023-09-03 17:16:49
Okay, I found the solution, but anyway, I'm interested to know if anyone has this problem too
My solution to this problem is:
public function testRealExternalMethod() { // Create a mock of the dependency that will be used by the class $mockDependency = $this->createMock(Dependency::class); // in this case we need to use a partial mock because we have an internal method $mockMyClass = Mockery::mock( MyClass::class, [$mockDependency, $parameter1] ) ->makePartial(); $responseInternalMethod = ['needed data']; $mockMyClass->shouldReceive('internalMethod') ->andReturn($responseInternalMethod); $result = $mockMyClass->realExternalMethod($parameter2, $parameter3); }The solution for these cases is to directly create a mock instance of my class and pass all parameters required by the constructor as dependencies or data. Then continue the testing loop using the mock class as the real class.