Skip to content

Commit f773a4f

Browse files
committed
test: cover raw json body requests
Signed-off-by: Vitor Mattos <vitor@php.rio>
1 parent 32dedd1 commit f773a4f

2 files changed

Lines changed: 34 additions & 0 deletions

File tree

features/bootstrap/FeatureContext.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,15 @@ public function sendRequest(string $verb, string $url, $body = null, array $head
9696
if (array_key_exists('json', $this->requestOptions)) {
9797
Assert::assertEquals($this->requestOptions['json'], $parsedInput);
9898
}
99+
100+
// Raw body payload
101+
if (array_key_exists('body', $this->requestOptions)) {
102+
Assert::assertEquals($this->requestOptions['body'], $lastRequest->getInput());
103+
Assert::assertStringContainsString(
104+
'application/json',
105+
(string)($lastRequest->getHeaders()['Content-Type'] ?? $lastRequest->getHeaders()['CONTENT_TYPE'] ?? '')
106+
);
107+
}
99108
}
100109

101110
private function getParsedInputFromRequest(RequestInfo $requestInfo): array {

features/test.feature

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,31 @@ Feature: Test this extension
4242
| key | value |
4343
| status | true |
4444

45+
Scenario: Test POST with raw json body via PyStringNode
46+
When set the response to:
47+
"""
48+
{
49+
"status": {
50+
"nested": true
51+
}
52+
}
53+
"""
54+
And sending "POST" to "/"
55+
"""
56+
{
57+
"status": {
58+
"nested": true
59+
},
60+
"events": [
61+
"created",
62+
"updated"
63+
]
64+
}
65+
"""
66+
Then the response should be a JSON array with the following mandatory values
67+
| key | value |
68+
| (jq).status.nested | true |
69+
4570
Scenario: Test response of POST is json
4671
When set the response to:
4772
"""

0 commit comments

Comments
 (0)