diff --git a/src/AnalyticsResponse.php b/src/AnalyticsResponse.php index c4de83e..264f1dc 100644 --- a/src/AnalyticsResponse.php +++ b/src/AnalyticsResponse.php @@ -36,6 +36,13 @@ class AnalyticsResponse implements AnalyticsResponseInterface */ protected $responseBody; + /** + * Reason phrase. + * + * @var string + */ + protected $reasonPhrase; + /** * Gets the relevant data from the Guzzle clients. * @@ -47,9 +54,11 @@ public function __construct(RequestInterface $request, $response) if ($response instanceof ResponseInterface) { $this->httpStatusCode = $response->getStatusCode(); $this->responseBody = $response->getBody()->getContents(); + $this->reasonPhrase = $response->getReasonPhrase(); } elseif ($response instanceof PromiseInterface) { $this->httpStatusCode = null; $this->responseBody = null; + $this->reasonPhrase = null; } else { throw new \InvalidArgumentException( 'Second constructor argument "response" must be instance of ResponseInterface or PromiseInterface' @@ -71,6 +80,17 @@ public function getHttpStatusCode() return $this->httpStatusCode; } + /** + * Gets the HTTP reason phrase. + * + * @api + * @return string + */ + public function getReasonPhrase() + { + return $this->reasonPhrase; + } + /** * Gets the request URI used to get the response. * diff --git a/src/AnalyticsResponseInterface.php b/src/AnalyticsResponseInterface.php index 7b5a310..574e7de 100644 --- a/src/AnalyticsResponseInterface.php +++ b/src/AnalyticsResponseInterface.php @@ -17,6 +17,14 @@ interface AnalyticsResponseInterface */ public function getHttpStatusCode(); + /** + * Gets the HTTP reason phrase. + * + * @api + * @return string + */ + public function getReasonPhrase(); + /** * Gets the request URI used to get the response. * diff --git a/tests/TheIconic/Tracking/GoogleAnalytics/AnalyticsResponseTest.php b/tests/TheIconic/Tracking/GoogleAnalytics/AnalyticsResponseTest.php index b3081f2..a6ff22e 100644 --- a/tests/TheIconic/Tracking/GoogleAnalytics/AnalyticsResponseTest.php +++ b/tests/TheIconic/Tracking/GoogleAnalytics/AnalyticsResponseTest.php @@ -59,6 +59,15 @@ public function setUp() ->method('getUri') ->will($this->returnValue(new Uri('http://test-collector/hello'))); + $this->mockRequest = $this->getMockBuilder('GuzzleHttp\Psr7\Request') + ->setMethods(['getUri']) + ->disableOriginalConstructor() + ->getMock(); + + $this->mockRequest->expects($this->atLeast(1)) + ->method('getReasonPhrase') + ->will($this->returnValue("ReasonPhrase")); + $this->analyticsResponse = new AnalyticsResponse($this->mockRequest, $mockResponse); @@ -107,6 +116,12 @@ public function testStatusCode() $this->assertEquals(null, $this->analyticsResponseAsync->getHttpStatusCode()); } + public function testGetReasonPhrase() + { + $this->assertEquals('ReasonPhrase', $this->analyticsResponse->getReasonPhrase()); + $this->assertEquals('ReasonPhrase', $this->analyticsResponseAsync->getReasonPhrase()); + } + public function testGetUrl() { $this->assertEquals('http://test-collector/hello', $this->analyticsResponse->getRequestUrl());