The goal of Mocks and Stub is to replace based on dependency functionality, for example. when you have something like
class Foo { public function __construct($apiConnector) { $this->apiConnector = $apiConnector } }
where $apiConnector is the dependency used to invoke the API, then you mute or mock this dependency with your own implementation. Since this dependency is called through it via the Foo interface, it blocks a method that runs the protected method in the dependency.
If, however, there is no dependency, but the API call is made from testclass, then you need to write your own class that extends your test class and implements its own API call function, for example.
class FooMock extends Foo { protected function queryAPI() { return $fixture; } }
Then you check this class instead of the actual class.
If your class actually connects to WebService, see the Stubbing and Mocking WebServices chapter.
source share