コード例 #1
0
 public function testWithResponse()
 {
     $requestContent = "I request this";
     $responseContent = "I respond with this";
     $statusCode = 555;
     $this->request->shouldReceive("getUri->__toString")->andReturn("");
     $this->request->shouldReceive("getBody->getContents")->andReturn($requestContent);
     $this->request->shouldReceive("getHeaders")->andReturn([]);
     $this->response->shouldReceive("getBody->getContents")->andReturn($responseContent);
     $this->response->shouldReceive("getStatusCode")->andReturn($statusCode);
     $this->response->shouldReceive("getHeaders")->andReturn([]);
     $transferStats = $this->createTransferStats($this->response, null);
     $processor = new ApiRequestProcessor();
     $processor->recordTransferStats($transferStats);
     $record = ["extra" => []];
     $record = $processor($record);
     $this->assertArrayHasKey("extra", $record);
     $extra = $record["extra"];
     $this->assertArrayHasKey("requestBody", $extra);
     $this->assertArrayHasKey("responseHeaders", $extra);
     $this->assertArrayHasKey("responseBody", $extra);
     $this->assertArrayHasKey("statusCode", $extra);
     $this->assertEquals($requestContent, $extra["requestBody"]);
     $this->assertEquals("", $extra["responseHeaders"]);
     $this->assertEquals($responseContent, $extra["responseBody"]);
     $this->assertEquals($statusCode, $extra["statusCode"]);
 }
コード例 #2
0
 private function remoteAppDoesNotRespond()
 {
     $this->response->shouldReceive('getBody')->andReturn($this->faker->word);
     $this->badResponseException->shouldReceive('getResponse')->andReturn($this->response);
     $this->client->shouldReceive('request')->andThrow($this->badResponseException);
 }