2222use Codeception \Util \JsonArray ;
2323use Codeception \Util \JsonType ;
2424use Codeception \Util \Soap as XmlUtils ;
25- use Codeception \Util \XmlBuilder ;
2625use Codeception \Util \XmlStructure ;
27- use DOMDocument ;
28- use DOMNode ;
2926use Exception ;
3027use JsonException ;
3128use JsonSchema \Constraints \Constraint as JsonConstraint ;
@@ -124,13 +121,17 @@ class REST extends Module implements DependsOnModule, PartedModule, API, Conflic
124121
125122 protected int $ DEFAULT_SHORTEN_VALUE = 150 ;
126123
127- public HttpKernelBrowser |AbstractBrowser |null $ client ;
124+ /**
125+ * @var HttpKernelBrowser|AbstractBrowser
126+ */
127+ public $ client ;
128128
129129 public bool $ isFunctional = false ;
130130
131131 protected ?InnerBrowser $ connectionModule = null ;
132132
133- public array |string |ArrayAccess |JsonSerializable $ params = [];
133+ /** @var array */
134+ public $ params = [];
134135
135136 public ?string $ response = null ;
136137
@@ -149,7 +150,7 @@ protected function resetVariables(): void
149150
150151 public function _conflicts (): string
151152 {
152- return API ::class;
153+ return \ Codeception \ Lib \ Interfaces \ API ::class;
153154 }
154155
155156 public function _depends (): array
@@ -201,7 +202,7 @@ protected function getRunningClient(): AbstractBrowser
201202 }
202203
203204 /**
204- * Sets na HTTP header to be used for all subsequent requests. Use [`deleteHeader`](#deleteHeader) to unset it.
205+ * Sets a HTTP header to be used for all subsequent requests. Use [`deleteHeader`](#deleteHeader) to unset it.
205206 *
206207 * ```php
207208 * <?php
@@ -218,7 +219,7 @@ public function haveHttpHeader(string $name, string $value): void
218219 }
219220
220221 /**
221- * Deletes an HTTP header (that was originally added by [haveHttpHeader()](#haveHttpHeader)),
222+ * Deletes a HTTP header (that was originally added by [haveHttpHeader()](#haveHttpHeader)),
222223 * so that subsequent requests will not send it anymore.
223224 *
224225 * Example:
@@ -244,6 +245,7 @@ public function deleteHeader(string $name): void
244245 * Checks over the given HTTP header and (optionally)
245246 * its value, asserting that are there
246247 *
248+ * @param $value
247249 * @part json
248250 * @part xml
249251 */
@@ -264,6 +266,7 @@ public function seeHttpHeader(string $name, $value = null): void
264266 * Checks over the given HTTP header and (optionally)
265267 * its value, asserting that are not there
266268 *
269+ * @param $value
267270 * @part json
268271 * @part xml
269272 */
@@ -283,7 +286,7 @@ public function dontSeeHttpHeader(string $name, $value = null): void
283286 /**
284287 * Checks that http response header is received only once.
285288 * HTTP RFC2616 allows multiple response headers with the same name.
286- * You can check that you didn't accidentally send the same header twice.
289+ * You can check that you didn't accidentally sent the same header twice.
287290 *
288291 * ``` php
289292 * <?php
@@ -303,7 +306,7 @@ public function seeHttpHeaderOnce(string $name): void
303306 * Returns the value of the specified header name
304307 *
305308 * @param bool $first Whether to return the first value or all header values
306- * @return string|array|null The first header value if $first is true, an array of values otherwise
309+ * @return string|array The first header value if $first is true, an array of values otherwise
307310 * @part json
308311 * @part xml
309312 */
@@ -383,7 +386,7 @@ public function amNTLMAuthenticated(string $username, string $password): void
383386 }
384387
385388 /**
386- * Allows sending REST request using AWS Authorization
389+ * Allows to send REST request using AWS Authorization
387390 *
388391 * Only works with PhpBrowser
389392 * Example Config:
@@ -457,6 +460,7 @@ public function amAWSAuthenticated(array $additionalAWSConfig = []): void
457460 * ]]);
458461 * ```
459462 *
463+ * @param array|string|JsonSerializable $params
460464 * @param array $files A list of filenames or "mocks" of $_FILES (each entry being an array with the following
461465 * keys: name, type, error, size, tmp_name (pointing to the real file path). Each key works
462466 * as the "name" attribute of a file input field.
@@ -466,10 +470,7 @@ public function amAWSAuthenticated(array $additionalAWSConfig = []): void
466470 * @part json
467471 * @part xml
468472 */
469- public function sendPost (
470- string $ url ,
471- array |string |ArrayAccess |JsonSerializable $ params = [],
472- array $ files = []): ?string
473+ public function sendPost (string $ url , $ params = [], array $ files = [])
473474 {
474475 return $ this ->execute ('POST ' , $ url , $ params , $ files );
475476 }
@@ -480,7 +481,7 @@ public function sendPost(
480481 * @part json
481482 * @part xml
482483 */
483- public function sendHead (string $ url , array $ params = []): ? string
484+ public function sendHead (string $ url , array $ params = [])
484485 {
485486 return $ this ->execute ('HEAD ' , $ url , $ params );
486487 }
@@ -510,7 +511,7 @@ public function sendOptions(string $url, array $params = []): void
510511 * @part json
511512 * @part xml
512513 */
513- public function sendGet (string $ url , array $ params = []): ? string
514+ public function sendGet (string $ url , array $ params = [])
514515 {
515516 return $ this ->execute ('GET ' , $ url , $ params );
516517 }
@@ -523,14 +524,11 @@ public function sendGet(string $url, array $params = []): ?string
523524 * $response = $I->sendPut('/message/1', ['subject' => 'Read this!']);
524525 * ```
525526 *
527+ * @param array|string|JsonSerializable $params
526528 * @part json
527529 * @part xml
528530 */
529- public function sendPut (
530- string $ url ,
531- array |string |ArrayAccess |JsonSerializable $ params = [],
532- array $ files = []
533- ): ?string
531+ public function sendPut (string $ url , $ params = [], array $ files = [])
534532 {
535533 return $ this ->execute ('PUT ' , $ url , $ params , $ files );
536534 }
@@ -543,14 +541,11 @@ public function sendPut(
543541 * $response = $I->sendPatch('/message/1', ['subject' => 'Read this!']);
544542 * ```
545543 *
544+ * @param array|string|JsonSerializable $params
546545 * @part json
547546 * @part xml
548547 */
549- public function sendPatch (
550- string $ url ,
551- array |string |ArrayAccess |JsonSerializable $ params = [],
552- array $ files = []
553- ): ?string
548+ public function sendPatch (string $ url , $ params = [], array $ files = [])
554549 {
555550 return $ this ->execute ('PATCH ' , $ url , $ params , $ files );
556551 }
@@ -566,26 +561,19 @@ public function sendPatch(
566561 * @part json
567562 * @part xml
568563 */
569- public function sendDelete (
570- string $ url ,
571- array |string |ArrayAccess |JsonSerializable $ params = [],
572- array $ files = []
573- ): ?string
564+ public function sendDelete (string $ url , array $ params = [], array $ files = [])
574565 {
575566 return $ this ->execute ('DELETE ' , $ url , $ params , $ files );
576567 }
577568
578569 /**
579570 * Sends a HTTP request.
580571 *
572+ * @param array|string|JsonSerializable $params
581573 * @part json
582574 * @part xml
583575 */
584- public function send (
585- string $ method ,
586- string $ url ,
587- array |string |ArrayAccess |JsonSerializable $ params = [],
588- array $ files = []): ?string
576+ public function send (string $ method , string $ url , $ params = [], array $ files = [])
589577 {
590578 return $ this ->execute (strtoupper ($ method ), $ url , $ params , $ files );
591579 }
@@ -652,13 +640,13 @@ public function sendUnlink(string $url, array $linkEntries): void
652640 }
653641
654642 /**
643+ * @param $method
644+ * @param $url
645+ * @param array|string|object $parameters
646+ * @param array $files
655647 * @throws ModuleException|ExternalUrlException|JsonException
656648 */
657- protected function execute (
658- string $ method ,
659- string $ url ,
660- array |string |ArrayAccess |JsonSerializable $ parameters = [],
661- array $ files = []): ?string
649+ protected function execute ($ method , $ url , $ parameters = [], $ files = [])
662650 {
663651 // allow full url to be requested
664652 if (!$ url ) {
@@ -704,9 +692,6 @@ protected function execute(
704692
705693 $ this ->response = $ this ->connectionModule ->_request ($ method , $ url , $ parameters , $ files );
706694 } else {
707- /**
708- * @var string $parameters
709- */
710695 $ requestData = $ parameters ;
711696 if ($ this ->isBinaryData ($ requestData )) {
712697 $ requestData = $ this ->binaryToDebugString ($ requestData );
@@ -754,10 +739,7 @@ protected function binaryToDebugString(string $data): string
754739 return '[binary-data length: ' . strlen ($ data ) . ' md5: ' . md5 ($ data ) . '] ' ;
755740 }
756741
757- protected function encodeApplicationJson (
758- string $ method ,
759- array |string |ArrayAccess |JsonSerializable $ parameters ,
760- ): array |string
742+ protected function encodeApplicationJson (string $ method , $ parameters )
761743 {
762744 if (
763745 array_key_exists ('Content-Type ' , $ this ->connectionModule ->headers )
@@ -919,15 +901,15 @@ public function dontSeeResponseContains(string $text): void
919901 *
920902 * ``` php
921903 * <?php
922- * // response: {" name": " john", " email": " [email protected] " } 923- * $I->seeResponseContainsJson([ 'name' => 'john'] );
904+ * // response: {name: john, email: [email protected] } 905+ * $I->seeResponseContainsJson(array( 'name' => 'john') );
924906 *
925- * // response {" user": " john", " profile" : {" email": " [email protected] " }} 926- * $I->seeResponseContainsJson([ 'email' => '[email protected] '] ); 907+ * // response {user: john, profile: { email: [email protected] }} 908+ * $I->seeResponseContainsJson(array( 'email' => '[email protected] ') ); 927909 *
928910 * ```
929911 *
930- * This method recursively checks if one array can be found inside another.
912+ * This method recursively checks if one array can be found inside of another.
931913 *
932914 * @part json
933915 */
@@ -1331,13 +1313,13 @@ public function dontSeeResponseContainsJson(array $json = []): void
13311313 *
13321314 * ```php
13331315 * <?php
1334- * // {" user_id" : 1, " email" => " [email protected] " } 1316+ * // {' user_id' : 1, ' email' => ' [email protected] ' } 13351317 * $I->seeResponseMatchesJsonType([
13361318 * 'user_id' => 'string:>0:<1000', // multiple filters can be used
13371319 * 'email' => 'string:regex(~\@~)' // we just check that @ char is included
13381320 * ]);
13391321 *
1340- * // {" user_id"'": "1" }
1322+ * // {' user_id': '1' }
13411323 * $I->seeResponseMatchesJsonType([
13421324 * 'user_id' => 'string:>0', // works with strings as well
13431325 * ]);
@@ -1531,9 +1513,10 @@ public function dontSeeXmlResponseMatchesXpath(string $xPath): void
15311513 * Finds and returns text contents of element.
15321514 * Element is matched by either CSS or XPath
15331515 *
1516+ * @param mixed $cssOrXPath
15341517 * @part xml
15351518 */
1536- public function grabTextContentFromXmlElement (string $ cssOrXPath ): string
1519+ public function grabTextContentFromXmlElement ($ cssOrXPath ): string
15371520 {
15381521 $ el = (new XmlStructure ($ this ->connectionModule ->_getResponseContent ()))->matchElement ($ cssOrXPath );
15391522 return $ el ->textContent ;
@@ -1559,9 +1542,12 @@ public function grabAttributeFromXmlElement(string $cssOrXPath, string $attribut
15591542 * Checks XML response equals provided XML.
15601543 * Comparison is done by canonicalizing both xml`s.
15611544 *
1545+ * Parameters can be passed either as DOMDocument, DOMNode, XML string, or array (if no attributes).
1546+ *
1547+ * @param mixed $xml
15621548 * @part xml
15631549 */
1564- public function seeXmlResponseEquals (DOMDocument | string $ xml ): void
1550+ public function seeXmlResponseEquals ($ xml ): void
15651551 {
15661552 Assert::assertXmlStringEqualsXmlString ($ this ->connectionModule ->_getResponseContent (), $ xml );
15671553 }
@@ -1571,10 +1557,12 @@ public function seeXmlResponseEquals(DOMDocument|string $xml): void
15711557 * Checks XML response does not equal to provided XML.
15721558 * Comparison is done by canonicalizing both xml`s.
15731559 *
1560+ * Parameter can be passed either as XmlBuilder, DOMDocument, DOMNode, XML string, or array (if no attributes).
1561+ *
15741562 * @param mixed $xml
15751563 * @part xml
15761564 */
1577- public function dontSeeXmlResponseEquals (DOMDocument | string $ xml ): void
1565+ public function dontSeeXmlResponseEquals ($ xml ): void
15781566 {
15791567 Assert::assertXmlStringNotEqualsXmlString (
15801568 $ this ->connectionModule ->_getResponseContent (),
@@ -1594,9 +1582,10 @@ public function dontSeeXmlResponseEquals(DOMDocument|string $xml): void
15941582 * $I->seeXmlResponseIncludes("<result>1</result>");
15951583 * ```
15961584 *
1585+ * @param mixed $xml
15971586 * @part xml
15981587 */
1599- public function seeXmlResponseIncludes (DOMNode | XmlBuilder | array | string $ xml ): void
1588+ public function seeXmlResponseIncludes ($ xml ): void
16001589 {
16011590 $ this ->assertStringContainsString (
16021591 XmlUtils::toXml ($ xml )->C14N (),
@@ -1610,9 +1599,10 @@ public function seeXmlResponseIncludes(DOMNode|XmlBuilder|array|string $xml): vo
16101599 * Comparison is done by canonicalizing both xml`s.
16111600 * Parameter can be passed either as XmlBuilder, DOMDocument, DOMNode, XML string, or array (if no attributes).
16121601 *
1602+ * @param mixed $xml
16131603 * @part xml
16141604 */
1615- public function dontSeeXmlResponseIncludes (DOMNode | XmlBuilder | array | string $ xml ): void
1605+ public function dontSeeXmlResponseIncludes ($ xml ): void
16161606 {
16171607 $ this ->assertStringNotContainsString (
16181608 XmlUtils::toXml ($ xml )->C14N (),
0 commit comments