Skip to content

Commit

Permalink
Merge pull request #64 from msiebeneicher/issue-63
Browse files Browse the repository at this point in the history
Ensure that json_decode always return an assoc array (Fix #63)
  • Loading branch information
msiebeneicher authored Dec 15, 2016
2 parents ea77a0f + 39adac7 commit 8bdf77d
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Component/Http/HttpGuzzlResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,6 @@ public function getBody()
*/
public function json()
{
return json_decode($this->getBody());
return json_decode($this->getBody(), true);
}
}
25 changes: 25 additions & 0 deletions test/unit/Component/Http/HttpGuzzleResponseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,29 @@ public function testJsonSuccess()

$this->assertEquals([1,2,3], $_oHttpGuzzleResponse->json());
}

public function testJsonReturnAssocArray()
{
$dummyBody = [
'histogram' => [
'75thPercentile' => 539159,
'95thPercentile' => 539159,
'98thPercentile' => 539159,
'99thPercentile' => 539159,
'median' => 539159,
'count' => 15
],
'taskStatHistory' => []
];
$this->oResponseInterface
->getBody()
->shouldBeCalledTimes(1)
->willReturn(json_encode($dummyBody));

$_oHttpGuzzleResponse = new HttpGuzzlResponse($this->oResponseInterface->reveal());

$result = $_oHttpGuzzleResponse->json();
$this->assertInternalType('array', $result);
$this->assertEquals($dummyBody, $result);
}
}

0 comments on commit 8bdf77d

Please sign in to comment.