Skip to content

Commit

Permalink
Merge pull request #61 from gam6itko/get_json_parsed_body
Browse files Browse the repository at this point in the history
FakeHttp add method `getJsonParsedBody`
  • Loading branch information
butschster committed Sep 20, 2023
2 parents 763ce92 + 5ec21de commit c217343
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/Http/TestResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -219,4 +219,12 @@ public function getCookies(): array
{
return $this->cookies;
}

public function getJsonParsedBody(): array
{
return \json_decode(
(string)$this->response->getBody(),
true
);
}
}
14 changes: 14 additions & 0 deletions tests/src/Http/FakeHttpTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,18 @@ public function testGetWithDefaultHeaders(): void
$response = $http->get('/get/headers');
$response->assertBodySame('{"baz":["bar"],"foo":["bar"]}');
}

public function testGetJsonParsedBody(): void
{
$http = $this->fakeHttp();
$arr = [
'foo' => 'bar',
'list' => [1, 2, 3, 4]
];
$response = $http->get('/get/query-params', $arr);
self::assertSame(
$arr,
$response->getJsonParsedBody()
);
}
}

0 comments on commit c217343

Please sign in to comment.