22
33use Behat \Gherkin \Node \PyStringNode ;
44use Behat \Gherkin \Node \TableNode ;
5- use Behat \Step \Given ;
65use donatj \MockWebServer \MockWebServer ;
76use donatj \MockWebServer \RequestInfo ;
87use donatj \MockWebServer \Response as MockWebServerResponse ;
@@ -23,17 +22,17 @@ public function __construct(?array $parameters = []) {
2322
2423 /**
2524 * @inheritDoc
25+ * @psalm-suppress MissingOverrideAttribute
2626 */
27- #[\Override]
2827 public function setCurrentUser (string $ user ): void {
2928 parent ::setCurrentUser ($ user );
3029 Assert::assertEquals ($ this ->currentUser , $ user );
3130 }
3231
3332 /**
3433 * @inheritDoc
34+ * @psalm-suppress MissingOverrideAttribute
3535 */
36- #[\Override]
3736 public function assureUserExists (string $ user ): void {
3837 parent ::assureUserExists ($ user );
3938 $ lastRequest = $ this ->getLastREquest ();
@@ -58,16 +57,17 @@ private function getLastRequest(): RequestInfo {
5857 * When whe run the test suit of this repository at GitHub Actions, is
5958 * necessary to consider that we haven't Nextcloud installed and mock
6059 * the real path of files.
60+ * @psalm-suppress MissingOverrideAttribute
6161 */
62- #[\Override]
6362 public static function findParentDirContainingFile (string $ filename ): string {
6463 return __DIR__ ;
6564 }
6665
6766 /**
6867 * @inheritDoc
68+ * @param TableNode|PyStringNode|array|null $body
69+ * @psalm-suppress MissingOverrideAttribute
6970 */
70- #[\Override]
7171 public function sendRequest (string $ verb , string $ url , $ body = null , array $ headers = [], array $ options = []): void {
7272 parent ::sendRequest ($ verb , $ url , $ body , $ headers , $ options );
7373 $ lastRequest = $ this ->getLastRequest ();
@@ -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 {
@@ -122,7 +131,9 @@ private function hasNestedPayload(array $payload): bool {
122131 return false ;
123132 }
124133
125- #[Given('set the response to: ' )]
134+ /**
135+ * @Given set the response to:
136+ */
126137 public function setTheResponseTo (PyStringNode $ response ): void {
127138 // Mock response to be equal to body of request
128139 $ this ->mockServer ->setDefaultResponse (new MockWebServerResponse (
@@ -132,8 +143,8 @@ public function setTheResponseTo(PyStringNode $response): void {
132143
133144 /**
134145 * @inheritDoc
146+ * @psalm-suppress MissingOverrideAttribute
135147 */
136- #[\Override]
137148 public function theResponseShouldBeAJsonArrayWithTheFollowingMandatoryValues (TableNode $ table ): void {
138149 $ lastRequest = $ this ->getLastRequest ();
139150 $ parsedInput = $ this ->getParsedInputFromRequest ($ lastRequest );
0 commit comments