Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ability to get reason phrase #104

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions src/AnalyticsResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,13 @@ class AnalyticsResponse implements AnalyticsResponseInterface
*/
protected $responseBody;

/**
* Reason phrase.
*
* @var string
*/
protected $reasonPhrase;

/**
* Gets the relevant data from the Guzzle clients.
*
Expand All @@ -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'
Expand All @@ -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.
*
Expand Down
8 changes: 8 additions & 0 deletions src/AnalyticsResponseInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down
15 changes: 15 additions & 0 deletions tests/TheIconic/Tracking/GoogleAnalytics/AnalyticsResponseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);


Expand Down Expand Up @@ -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());
Expand Down