client = $this->getMockBuilder(HttpClientInterface::class) ->disableOriginalConstructor() ->getMock(); $this->mobytService = new MobytService($this->client); } private function getContentFromFixture(string $filename): string { $filepath = dirname(__FILE__) . '/fixtures/' . $filename; return file_get_contents($filepath); } /** * @see MobytService::getUserStatus() */ public function testGetUserStatus(): void { // Mock the response that will be returned by the connection request $connectResponse = $this->getMockBuilder(ResponseInterface::class) ->disableOriginalConstructor() ->getMock(); $connectResponse->method('getContent')->willReturn('userId;sessionKey'); // Mock the response that will be returned by the user_status request $responseContent = $this->getContentFromFixture('user_status.json'); $response = $this->getMockBuilder(ResponseInterface::class) ->disableOriginalConstructor() ->getMock(); $response->method('getContent')->willReturn($responseContent); $this->client ->method('request') ->withConsecutive( ["GET", "login?username=user&password=pwd"], ["GET", "status?getMoney=true&typeAliases=true", ['headers' => [ 'user_key' => 'userId', 'Session_key' => 'sessionKey' ]]] ) ->willReturnOnConsecutiveCalls( $connectResponse, $response ); $data = $this->mobytService->getUserStatus(1, 'user', 'pwd'); $this->assertEquals( $data['money'], 33.0 ); } }