Skip to content

Commit 5789db0

Browse files
author
Justin Hayes
authored
Merge pull request #8 from SoapBox/bugfix/generate-payload-from-guzzle
[Bugfix] Fix payload generation for guzzle requests
2 parents d1e7f46 + 3272703 commit 5789db0

File tree

2 files changed

+28
-2
lines changed

2 files changed

+28
-2
lines changed

src/Requests/Payload.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ protected function generateFromPsr7Request(Psr7Request $request) : string
4949
'method' => $this->request->getMethod(),
5050
'timestamp' => $timestamp,
5151
'uri' => (string) $this->request->getUri(),
52-
'content' => $this->request->getBody()
52+
'content' => $this->request->getBody()->getContents()
5353
], JSON_UNESCAPED_SLASHES);
5454
}
5555

tests/Requests/PayloadTest.php

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,33 @@ public function it_translates_a_guzzle_request_to_a_json_encoded_string()
3131
'method' => $method,
3232
'timestamp' => $now,
3333
'uri' => $uri,
34-
'content' => $request->getBody()
34+
'content' => $request->getBody()->getContents()
35+
], JSON_UNESCAPED_SLASHES);
36+
37+
$this->assertEquals($expected, (string) new Payload($request));
38+
}
39+
40+
/**
41+
* @test
42+
*/
43+
public function it_translates_a_guzzle_request_with_content_to_a_json_encoded_string()
44+
{
45+
$now = (string) Carbon::now();
46+
47+
$method = 'GET';
48+
$uri = 'https://localhost';
49+
$id = Uuid::uuid4();
50+
51+
$request = (new GuzzleRequest('GET', 'https://localhost', [], 'content'))
52+
->withHeader('X-SIGNED-ID', $id)
53+
->withHeader('X-SIGNED-TIMESTAMP', $now);
54+
55+
$expected = json_encode([
56+
'id' => $id,
57+
'method' => $method,
58+
'timestamp' => $now,
59+
'uri' => $uri,
60+
'content' => 'content'
3561
], JSON_UNESCAPED_SLASHES);
3662

3763
$this->assertEquals($expected, (string) new Payload($request));

0 commit comments

Comments
 (0)