$data = "{ 'your_json_answer_from_api } ";
$apiMock = $this->createMock(ApiService::class);
$apiMock = $apiMock->expects(self::once())->method('rest')->willReturn($data);
$shop->setApi($api);
// Your test/asserts
(function () use ($apiMock) {$this->api = $apiMock;})->call($shop);
class Foo {}
class Foo2 {
function __construct(Foo $foo) {
// ..
}
}
$foo = new Foo();
$foo2 = new Foo2($foo);