Thank you for your reply.
In general, you are right. But in my case, it is a bit different. So, I try to explain the real-world scenario, maybe you/someone could even give me a suggestion about the architecture.
Note: I changed the methods' name and functionality to make it more generic.
In my application, I need to implement a third-party API. This API only provides insert() and delete() func, but on my side, I need to prepare move method for customers as well. To do so, whenever the customer call the move method:
- API::delete() is called
- If the answer is OK, API::inser() will be called as well
so class body is something like this:
class service
{
public function __contruct(apiClient $client) {...}
public function insert($request) {
...
$this->client->performRequest($req);
...
}
public function delete($request) {
...
$this->client->performRequest($req);
...
}
public function move($request)
{
...
$response = $this->delete($request);
if($response == 'OK') {
$this->insert($request)
}
...
}
}
I would like to write a test for the move(). Obviously, I mocked the apiClient, in normal cases, as you said I create a mock for the apiClient and then I instantiate my class this way: $service = new Service($mockClient), but, here if I mocked apiClient the expected method and andReturn method would have two different values! one for delete and one for insert. Therefor, I decided to use partialMock() for my Service class, so I could mock the not needed methods and with passthru() I could test the move(). Here I need to define the constructor!
If you have any suggestion or totally different idea for implementation I am happy to hear and appreciate