22
22
use Codeception \Util \JsonArray ;
23
23
use Codeception \Util \JsonType ;
24
24
use Codeception \Util \Soap as XmlUtils ;
25
- use Codeception \Util \XmlBuilder ;
26
25
use Codeception \Util \XmlStructure ;
27
- use DOMDocument ;
28
- use DOMNode ;
29
26
use Exception ;
30
27
use JsonException ;
31
28
use JsonSchema \Constraints \Constraint as JsonConstraint ;
@@ -124,13 +121,17 @@ class REST extends Module implements DependsOnModule, PartedModule, API, Conflic
124
121
125
122
protected int $ DEFAULT_SHORTEN_VALUE = 150 ;
126
123
127
- public HttpKernelBrowser |AbstractBrowser |null $ client ;
124
+ /**
125
+ * @var HttpKernelBrowser|AbstractBrowser
126
+ */
127
+ public $ client ;
128
128
129
129
public bool $ isFunctional = false ;
130
130
131
131
protected ?InnerBrowser $ connectionModule = null ;
132
132
133
- public array |string |ArrayAccess |JsonSerializable $ params = [];
133
+ /** @var array */
134
+ public $ params = [];
134
135
135
136
public ?string $ response = null ;
136
137
@@ -149,7 +150,7 @@ protected function resetVariables(): void
149
150
150
151
public function _conflicts (): string
151
152
{
152
- return API ::class;
153
+ return \ Codeception \ Lib \ Interfaces \ API ::class;
153
154
}
154
155
155
156
public function _depends (): array
@@ -201,7 +202,7 @@ protected function getRunningClient(): AbstractBrowser
201
202
}
202
203
203
204
/**
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.
205
206
*
206
207
* ```php
207
208
* <?php
@@ -218,7 +219,7 @@ public function haveHttpHeader(string $name, string $value): void
218
219
}
219
220
220
221
/**
221
- * Deletes an HTTP header (that was originally added by [haveHttpHeader()](#haveHttpHeader)),
222
+ * Deletes a HTTP header (that was originally added by [haveHttpHeader()](#haveHttpHeader)),
222
223
* so that subsequent requests will not send it anymore.
223
224
*
224
225
* Example:
@@ -244,6 +245,7 @@ public function deleteHeader(string $name): void
244
245
* Checks over the given HTTP header and (optionally)
245
246
* its value, asserting that are there
246
247
*
248
+ * @param $value
247
249
* @part json
248
250
* @part xml
249
251
*/
@@ -264,6 +266,7 @@ public function seeHttpHeader(string $name, $value = null): void
264
266
* Checks over the given HTTP header and (optionally)
265
267
* its value, asserting that are not there
266
268
*
269
+ * @param $value
267
270
* @part json
268
271
* @part xml
269
272
*/
@@ -283,7 +286,7 @@ public function dontSeeHttpHeader(string $name, $value = null): void
283
286
/**
284
287
* Checks that http response header is received only once.
285
288
* 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.
287
290
*
288
291
* ``` php
289
292
* <?php
@@ -303,7 +306,7 @@ public function seeHttpHeaderOnce(string $name): void
303
306
* Returns the value of the specified header name
304
307
*
305
308
* @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
307
310
* @part json
308
311
* @part xml
309
312
*/
@@ -383,7 +386,7 @@ public function amNTLMAuthenticated(string $username, string $password): void
383
386
}
384
387
385
388
/**
386
- * Allows sending REST request using AWS Authorization
389
+ * Allows to send REST request using AWS Authorization
387
390
*
388
391
* Only works with PhpBrowser
389
392
* Example Config:
@@ -457,6 +460,7 @@ public function amAWSAuthenticated(array $additionalAWSConfig = []): void
457
460
* ]]);
458
461
* ```
459
462
*
463
+ * @param array|string|JsonSerializable $params
460
464
* @param array $files A list of filenames or "mocks" of $_FILES (each entry being an array with the following
461
465
* keys: name, type, error, size, tmp_name (pointing to the real file path). Each key works
462
466
* as the "name" attribute of a file input field.
@@ -466,10 +470,7 @@ public function amAWSAuthenticated(array $additionalAWSConfig = []): void
466
470
* @part json
467
471
* @part xml
468
472
*/
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 = [])
473
474
{
474
475
return $ this ->execute ('POST ' , $ url , $ params , $ files );
475
476
}
@@ -480,7 +481,7 @@ public function sendPost(
480
481
* @part json
481
482
* @part xml
482
483
*/
483
- public function sendHead (string $ url , array $ params = []): ? string
484
+ public function sendHead (string $ url , array $ params = [])
484
485
{
485
486
return $ this ->execute ('HEAD ' , $ url , $ params );
486
487
}
@@ -510,7 +511,7 @@ public function sendOptions(string $url, array $params = []): void
510
511
* @part json
511
512
* @part xml
512
513
*/
513
- public function sendGet (string $ url , array $ params = []): ? string
514
+ public function sendGet (string $ url , array $ params = [])
514
515
{
515
516
return $ this ->execute ('GET ' , $ url , $ params );
516
517
}
@@ -523,14 +524,11 @@ public function sendGet(string $url, array $params = []): ?string
523
524
* $response = $I->sendPut('/message/1', ['subject' => 'Read this!']);
524
525
* ```
525
526
*
527
+ * @param array|string|JsonSerializable $params
526
528
* @part json
527
529
* @part xml
528
530
*/
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 = [])
534
532
{
535
533
return $ this ->execute ('PUT ' , $ url , $ params , $ files );
536
534
}
@@ -543,14 +541,11 @@ public function sendPut(
543
541
* $response = $I->sendPatch('/message/1', ['subject' => 'Read this!']);
544
542
* ```
545
543
*
544
+ * @param array|string|JsonSerializable $params
546
545
* @part json
547
546
* @part xml
548
547
*/
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 = [])
554
549
{
555
550
return $ this ->execute ('PATCH ' , $ url , $ params , $ files );
556
551
}
@@ -566,26 +561,19 @@ public function sendPatch(
566
561
* @part json
567
562
* @part xml
568
563
*/
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 = [])
574
565
{
575
566
return $ this ->execute ('DELETE ' , $ url , $ params , $ files );
576
567
}
577
568
578
569
/**
579
570
* Sends a HTTP request.
580
571
*
572
+ * @param array|string|JsonSerializable $params
581
573
* @part json
582
574
* @part xml
583
575
*/
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 = [])
589
577
{
590
578
return $ this ->execute (strtoupper ($ method ), $ url , $ params , $ files );
591
579
}
@@ -652,13 +640,13 @@ public function sendUnlink(string $url, array $linkEntries): void
652
640
}
653
641
654
642
/**
643
+ * @param $method
644
+ * @param $url
645
+ * @param array|string|object $parameters
646
+ * @param array $files
655
647
* @throws ModuleException|ExternalUrlException|JsonException
656
648
*/
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 = [])
662
650
{
663
651
// allow full url to be requested
664
652
if (!$ url ) {
@@ -704,9 +692,6 @@ protected function execute(
704
692
705
693
$ this ->response = $ this ->connectionModule ->_request ($ method , $ url , $ parameters , $ files );
706
694
} else {
707
- /**
708
- * @var string $parameters
709
- */
710
695
$ requestData = $ parameters ;
711
696
if ($ this ->isBinaryData ($ requestData )) {
712
697
$ requestData = $ this ->binaryToDebugString ($ requestData );
@@ -754,10 +739,7 @@ protected function binaryToDebugString(string $data): string
754
739
return '[binary-data length: ' . strlen ($ data ) . ' md5: ' . md5 ($ data ) . '] ' ;
755
740
}
756
741
757
- protected function encodeApplicationJson (
758
- string $ method ,
759
- array |string |ArrayAccess |JsonSerializable $ parameters ,
760
- ): array |string
742
+ protected function encodeApplicationJson (string $ method , $ parameters )
761
743
{
762
744
if (
763
745
array_key_exists ('Content-Type ' , $ this ->connectionModule ->headers )
@@ -919,15 +901,15 @@ public function dontSeeResponseContains(string $text): void
919
901
*
920
902
* ``` php
921
903
* <?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') );
924
906
*
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] ') );
927
909
*
928
910
* ```
929
911
*
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.
931
913
*
932
914
* @part json
933
915
*/
@@ -1331,13 +1313,13 @@ public function dontSeeResponseContainsJson(array $json = []): void
1331
1313
*
1332
1314
* ```php
1333
1315
* <?php
1334
- * // {" user_id" : 1, " email" => " [email protected] " }
1316
+ * // {' user_id' : 1, ' email' => ' [email protected] ' }
1335
1317
* $I->seeResponseMatchesJsonType([
1336
1318
* 'user_id' => 'string:>0:<1000', // multiple filters can be used
1337
1319
* 'email' => 'string:regex(~\@~)' // we just check that @ char is included
1338
1320
* ]);
1339
1321
*
1340
- * // {" user_id"'": "1" }
1322
+ * // {' user_id': '1' }
1341
1323
* $I->seeResponseMatchesJsonType([
1342
1324
* 'user_id' => 'string:>0', // works with strings as well
1343
1325
* ]);
@@ -1531,9 +1513,10 @@ public function dontSeeXmlResponseMatchesXpath(string $xPath): void
1531
1513
* Finds and returns text contents of element.
1532
1514
* Element is matched by either CSS or XPath
1533
1515
*
1516
+ * @param mixed $cssOrXPath
1534
1517
* @part xml
1535
1518
*/
1536
- public function grabTextContentFromXmlElement (string $ cssOrXPath ): string
1519
+ public function grabTextContentFromXmlElement ($ cssOrXPath ): string
1537
1520
{
1538
1521
$ el = (new XmlStructure ($ this ->connectionModule ->_getResponseContent ()))->matchElement ($ cssOrXPath );
1539
1522
return $ el ->textContent ;
@@ -1559,9 +1542,12 @@ public function grabAttributeFromXmlElement(string $cssOrXPath, string $attribut
1559
1542
* Checks XML response equals provided XML.
1560
1543
* Comparison is done by canonicalizing both xml`s.
1561
1544
*
1545
+ * Parameters can be passed either as DOMDocument, DOMNode, XML string, or array (if no attributes).
1546
+ *
1547
+ * @param mixed $xml
1562
1548
* @part xml
1563
1549
*/
1564
- public function seeXmlResponseEquals (DOMDocument | string $ xml ): void
1550
+ public function seeXmlResponseEquals ($ xml ): void
1565
1551
{
1566
1552
Assert::assertXmlStringEqualsXmlString ($ this ->connectionModule ->_getResponseContent (), $ xml );
1567
1553
}
@@ -1571,10 +1557,12 @@ public function seeXmlResponseEquals(DOMDocument|string $xml): void
1571
1557
* Checks XML response does not equal to provided XML.
1572
1558
* Comparison is done by canonicalizing both xml`s.
1573
1559
*
1560
+ * Parameter can be passed either as XmlBuilder, DOMDocument, DOMNode, XML string, or array (if no attributes).
1561
+ *
1574
1562
* @param mixed $xml
1575
1563
* @part xml
1576
1564
*/
1577
- public function dontSeeXmlResponseEquals (DOMDocument | string $ xml ): void
1565
+ public function dontSeeXmlResponseEquals ($ xml ): void
1578
1566
{
1579
1567
Assert::assertXmlStringNotEqualsXmlString (
1580
1568
$ this ->connectionModule ->_getResponseContent (),
@@ -1594,9 +1582,10 @@ public function dontSeeXmlResponseEquals(DOMDocument|string $xml): void
1594
1582
* $I->seeXmlResponseIncludes("<result>1</result>");
1595
1583
* ```
1596
1584
*
1585
+ * @param mixed $xml
1597
1586
* @part xml
1598
1587
*/
1599
- public function seeXmlResponseIncludes (DOMNode | XmlBuilder | array | string $ xml ): void
1588
+ public function seeXmlResponseIncludes ($ xml ): void
1600
1589
{
1601
1590
$ this ->assertStringContainsString (
1602
1591
XmlUtils::toXml ($ xml )->C14N (),
@@ -1610,9 +1599,10 @@ public function seeXmlResponseIncludes(DOMNode|XmlBuilder|array|string $xml): vo
1610
1599
* Comparison is done by canonicalizing both xml`s.
1611
1600
* Parameter can be passed either as XmlBuilder, DOMDocument, DOMNode, XML string, or array (if no attributes).
1612
1601
*
1602
+ * @param mixed $xml
1613
1603
* @part xml
1614
1604
*/
1615
- public function dontSeeXmlResponseIncludes (DOMNode | XmlBuilder | array | string $ xml ): void
1605
+ public function dontSeeXmlResponseIncludes ($ xml ): void
1616
1606
{
1617
1607
$ this ->assertStringNotContainsString (
1618
1608
XmlUtils::toXml ($ xml )->C14N (),
0 commit comments