Answer the question
In order to leave comments, you need to log in
How to override class method when testing laravel phpunit?
There is a ServiceApi.php class - a guzzle client with default options is created in its constructor:
it also has a method:
$this->client = new Client($options);
public function fetch()
{
return $this->client->get('http://......')->getBody()->getContents();
}
public function fetchFromApi()
{
return (new ServiceApi())->fetch();
}
Answer the question
In order to leave comments, you need to log in
you can, in conjunction with Laravel, you can use https://laravel.com/docs/8.x/http-client#testing
or mock your class (like this for me)
$this->mock(RestApi::class, function (MockInterface $mock) use ($user) {
$mock->shouldReceive('login')
->with($user->phone, $user->pass)
->andReturn([
'result' => ApiStatus::OK,
]);
});
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question