92
92
* ## Conflicts
93
93
*
94
94
* Conflicts with SOAP module
95
+ *
95
96
*/
96
97
class REST extends Module implements DependsOnModule, PartedModule, API , ConflictsWithModule
97
98
{
@@ -231,8 +232,8 @@ public function haveHttpHeader(string $name, string $value): void
231
232
* ```
232
233
*
233
234
* @param string $name the name of the header to delete.
234
- * @part json
235
- * @part xml
235
+ * @part json
236
+ * @part xml
236
237
*/
237
238
public function deleteHeader (string $ name ): void
238
239
{
@@ -301,10 +302,10 @@ public function seeHttpHeaderOnce(string $name): void
301
302
/**
302
303
* Returns the value of the specified header name
303
304
*
304
- * @param bool $first Whether to return the first value or all header values
305
+ * @param bool $first Whether to return the first value or all header values
305
306
* @return string|array|null The first header value if $first is true, an array of values otherwise
306
- * @part json
307
- * @part xml
307
+ * @part json
308
+ * @part xml
308
309
*/
309
310
public function grabHttpHeader (string $ name , bool $ first = true ): string |array |null
310
311
{
@@ -365,8 +366,8 @@ public function amBearerAuthenticated(string $accessToken): void
365
366
* ```
366
367
*
367
368
* @throws ModuleException
368
- * @part json
369
- * @part xml
369
+ * @part json
370
+ * @part xml
370
371
*/
371
372
public function amNTLMAuthenticated (string $ username , string $ password ): void
372
373
{
@@ -401,7 +402,6 @@ public function amNTLMAuthenticated(string $username, string $password): void
401
402
* <?php
402
403
* $I->amAWSAuthenticated();
403
404
* ```
404
- *
405
405
* @throws ConfigurationException
406
406
*/
407
407
public function amAWSAuthenticated (array $ additionalAWSConfig = []): void
@@ -461,16 +461,16 @@ public function amAWSAuthenticated(array $additionalAWSConfig = []): void
461
461
* keys: name, type, error, size, tmp_name (pointing to the real file path). Each key works
462
462
* as the "name" attribute of a file input field.
463
463
*
464
- * @see https://php.net/manual/en/features.file-upload.post-method.php
465
- * @see codecept_data_dir()
464
+ * @see https://php.net/manual/en/features.file-upload.post-method.php
465
+ * @see codecept_data_dir()
466
466
* @part json
467
467
* @part xml
468
468
*/
469
469
public function sendPost (
470
470
string $ url ,
471
471
array |string |ArrayAccess |JsonSerializable $ params = [],
472
- array $ files = []
473
- ): ? string {
472
+ array $ files = []): ? string
473
+ {
474
474
return $ this ->execute ('POST ' , $ url , $ params , $ files );
475
475
}
476
476
@@ -530,7 +530,8 @@ public function sendPut(
530
530
string $ url ,
531
531
array |string |ArrayAccess |JsonSerializable $ params = [],
532
532
array $ files = []
533
- ): ?string {
533
+ ): ?string
534
+ {
534
535
return $ this ->execute ('PUT ' , $ url , $ params , $ files );
535
536
}
536
537
@@ -549,7 +550,8 @@ public function sendPatch(
549
550
string $ url ,
550
551
array |string |ArrayAccess |JsonSerializable $ params = [],
551
552
array $ files = []
552
- ): ?string {
553
+ ): ?string
554
+ {
553
555
return $ this ->execute ('PATCH ' , $ url , $ params , $ files );
554
556
}
555
557
@@ -568,7 +570,8 @@ public function sendDelete(
568
570
string $ url ,
569
571
array |string |ArrayAccess |JsonSerializable $ params = [],
570
572
array $ files = []
571
- ): ?string {
573
+ ): ?string
574
+ {
572
575
return $ this ->execute ('DELETE ' , $ url , $ params , $ files );
573
576
}
574
577
@@ -582,8 +585,8 @@ public function send(
582
585
string $ method ,
583
586
string $ url ,
584
587
array |string |ArrayAccess |JsonSerializable $ params = [],
585
- array $ files = []
586
- ): ? string {
588
+ array $ files = []): ? string
589
+ {
587
590
return $ this ->execute (strtoupper ($ method ), $ url , $ params , $ files );
588
591
}
589
592
@@ -624,8 +627,8 @@ private function setHeaderLink(array $linkEntries): void
624
627
* @link https://tools.ietf.org/html/rfc2068#section-19.6.2.4
625
628
*
626
629
627
- * @part json
628
- * @part xml
630
+ * @part json
631
+ * @part xml
629
632
*/
630
633
public function sendLink (string $ url , array $ linkEntries ): void
631
634
{
@@ -636,11 +639,11 @@ public function sendLink(string $url, array $linkEntries): void
636
639
/**
637
640
* Sends UNLINK request to given uri.
638
641
*
639
- * @param array $linkEntries (entry is array with keys "uri" and "link-param")
640
- * @link https://tools.ietf.org/html/rfc2068#section-19.6.2.4
642
+ * @param array $linkEntries (entry is array with keys "uri" and "link-param")
643
+ * @link https://tools.ietf.org/html/rfc2068#section-19.6.2.4
641
644
642
- * @part json
643
- * @part xml
645
+ * @part json
646
+ * @part xml
644
647
*/
645
648
public function sendUnlink (string $ url , array $ linkEntries ): void
646
649
{
@@ -655,8 +658,8 @@ protected function execute(
655
658
string $ method ,
656
659
string $ url ,
657
660
array |string |ArrayAccess |JsonSerializable $ parameters = [],
658
- array $ files = []
659
- ): ? string {
661
+ array $ files = []): ? string
662
+ {
660
663
// allow full url to be requested
661
664
if (!$ url ) {
662
665
$ url = $ this ->config ['url ' ];
@@ -693,8 +696,7 @@ protected function execute(
693
696
$ this ->debugSection ("Request " , sprintf ('%s %s ' , $ method , $ url ));
694
697
$ files = [];
695
698
} else {
696
- $ this ->debugSection (
697
- "Request " ,
699
+ $ this ->debugSection ("Request " ,
698
700
sprintf ('%s %s ' , $ method , $ url ) . json_encode ($ parameters , JSON_PRESERVE_ZERO_FRACTION | JSON_THROW_ON_ERROR )
699
701
);
700
702
$ files = $ this ->formatFilesArray ($ files );
@@ -744,7 +746,7 @@ protected function isBinaryData(string $data): bool
744
746
/**
745
747
* Format a binary string for debug printing
746
748
*
747
- * @param string $data the binary data string
749
+ * @param string $data the binary data string
748
750
* @return string the debug string
749
751
*/
750
752
protected function binaryToDebugString (string $ data ): string
@@ -755,11 +757,13 @@ protected function binaryToDebugString(string $data): string
755
757
protected function encodeApplicationJson (
756
758
string $ method ,
757
759
array |string |ArrayAccess |JsonSerializable $ parameters ,
758
- ): array |string {
760
+ ): array |string
761
+ {
759
762
if (
760
763
array_key_exists ('Content-Type ' , $ this ->connectionModule ->headers )
761
764
&& ($ this ->connectionModule ->headers ['Content-Type ' ] === 'application/json '
762
- || preg_match ('#^application/.+\+json$# ' , $ this ->connectionModule ->headers ['Content-Type ' ]))
765
+ || preg_match ('#^application/.+\+json$# ' , $ this ->connectionModule ->headers ['Content-Type ' ])
766
+ )
763
767
) {
764
768
if ($ parameters instanceof JsonSerializable) {
765
769
return json_encode ($ parameters , JSON_PRESERVE_ZERO_FRACTION | JSON_THROW_ON_ERROR );
@@ -821,7 +825,6 @@ private function formatFilesArray(array $files): array
821
825
} elseif (is_object ($ value )) {
822
826
/**
823
827
* do nothing, probably the user knows what he is doing
824
- *
825
828
* @issue https://github.com/Codeception/Codeception/issues/3298
826
829
*/
827
830
} else {
@@ -858,6 +861,7 @@ private function checkFileBeforeUpload(string $file): void
858
861
859
862
/**
860
863
* Extends the function Module::validateConfig for shorten messages
864
+ *
861
865
*/
862
866
protected function validateConfig (): void
863
867
{
@@ -991,7 +995,7 @@ public function seeResponseIsValidOnJsonSchemaString(string $schema): void
991
995
* Supply schema as relative file path in your project directory or an absolute path
992
996
*
993
997
* @part json
994
- * @see codecept_absolute_path()
998
+ * @see codecept_absolute_path()
995
999
*/
996
1000
public function seeResponseIsValidOnJsonSchema (string $ schemaFilename ): void
997
1001
{
@@ -1006,7 +1010,7 @@ public function seeResponseIsValidOnJsonSchema(string $schemaFilename): void
1006
1010
/**
1007
1011
* Converts string to json and asserts that no error occurred while decoding.
1008
1012
*
1009
- * @param string $jsonString the json encoded string
1013
+ * @param string $jsonString the json encoded string
1010
1014
* @param string $errorFormat optional string for custom sprintf format
1011
1015
*/
1012
1016
protected function decodeAndValidateJson (string $ jsonString , string $ errorFormat = "Invalid json: %s. System message: %s. " )
@@ -1059,7 +1063,7 @@ public function grabResponse(): string
1059
1063
*
1060
1064
* @return array Array of matching items
1061
1065
* @throws Exception
1062
- * @part json
1066
+ * @part json
1063
1067
*/
1064
1068
public function grabDataFromResponseByJsonPath (string $ jsonPath ): array
1065
1069
{
@@ -1102,7 +1106,6 @@ public function grabDataFromResponseByJsonPath(string $jsonPath): array
1102
1106
* // at least one item in store has price
1103
1107
* $I->seeResponseJsonMatchesXpath('/store//price');
1104
1108
* ```
1105
- *
1106
1109
* @part json
1107
1110
*/
1108
1111
public function seeResponseJsonMatchesXpath (string $ xPath ): void
@@ -1149,7 +1152,6 @@ public function seeResponseJsonMatchesXpath(string $xPath): void
1149
1152
* // count the number of books written by given author is 5
1150
1153
* $I->seeResponseJsonMatchesXpath("//author[text() = 'Nigel Rees']", 1.0);
1151
1154
* ```
1152
- *
1153
1155
* @part json
1154
1156
*/
1155
1157
public function seeResponseJsonXpathEvaluatesTo (string $ xPath , $ expected ): void
@@ -1161,7 +1163,7 @@ public function seeResponseJsonXpathEvaluatesTo(string $xPath, $expected): void
1161
1163
"Received JSON did not evualated XPath ` {$ xPath }` as expected. \nJson Response: \n" . $ response
1162
1164
);
1163
1165
}
1164
-
1166
+
1165
1167
/**
1166
1168
* Opposite to seeResponseJsonXpathEvaluatesTo
1167
1169
*
@@ -1345,7 +1347,7 @@ public function dontSeeResponseContainsJson(array $json = []): void
1345
1347
* See [JsonType reference](https://codeception.com/docs/reference/JsonType).
1346
1348
*
1347
1349
* @part json
1348
- * @see JsonType
1350
+ * @see JsonType
1349
1351
*/
1350
1352
public function seeResponseMatchesJsonType (array $ jsonType , string $ jsonPath = null ): void
1351
1353
{
@@ -1360,9 +1362,9 @@ public function seeResponseMatchesJsonType(array $jsonType, string $jsonPath = n
1360
1362
/**
1361
1363
* Opposite to `seeResponseMatchesJsonType`.
1362
1364
*
1363
- * @part json
1365
+ * @part json
1364
1366
* @param array $jsonType JsonType structure
1365
- * @see seeResponseMatchesJsonType
1367
+ * @see seeResponseMatchesJsonType
1366
1368
*/
1367
1369
public function dontSeeResponseMatchesJsonType (array $ jsonType , string $ jsonPath = null ): void
1368
1370
{
@@ -1502,7 +1504,6 @@ public function seeResponseIsXml(): void
1502
1504
* <?php
1503
1505
* $I->seeXmlResponseMatchesXpath('//root/user[@id=1]');
1504
1506
* ```
1505
- *
1506
1507
* @part xml
1507
1508
*/
1508
1509
public function seeXmlResponseMatchesXpath (string $ xPath ): void
@@ -1518,7 +1519,6 @@ public function seeXmlResponseMatchesXpath(string $xPath): void
1518
1519
* <?php
1519
1520
* $I->dontSeeXmlResponseMatchesXpath('//root/user[@id=1]');
1520
1521
* ```
1521
- *
1522
1522
* @part xml
1523
1523
*/
1524
1524
public function dontSeeXmlResponseMatchesXpath (string $ xPath ): void
@@ -1572,7 +1572,7 @@ public function seeXmlResponseEquals(DOMDocument|string $xml): void
1572
1572
* Comparison is done by canonicalizing both xml`s.
1573
1573
*
1574
1574
* @param mixed $xml
1575
- * @part xml
1575
+ * @part xml
1576
1576
*/
1577
1577
public function dontSeeXmlResponseEquals (DOMDocument |string $ xml ): void
1578
1578
{
@@ -1650,8 +1650,8 @@ public function dontSeeXmlResponseIncludes(DOMNode|XmlBuilder|array|string $xml)
1650
1650
*
1651
1651
* @param string $hash the hashed data response expected
1652
1652
* @param string $algo the hash algorithm to use. Default sha1.
1653
- * @part json
1654
- * @part xml
1653
+ * @part json
1654
+ * @part xml
1655
1655
*/
1656
1656
public function seeBinaryResponseEquals (string $ hash , string $ algo = 'sha1 ' ): void
1657
1657
{
@@ -1670,8 +1670,8 @@ public function seeBinaryResponseEquals(string $hash, string $algo = 'sha1'): vo
1670
1670
*
1671
1671
* @param string $hash the hashed data response expected
1672
1672
* @param string $algo the hash algorithm to use. Default md5.
1673
- * @part json
1674
- * @part xml
1673
+ * @part json
1674
+ * @part xml
1675
1675
*/
1676
1676
public function dontSeeBinaryResponseEquals (string $ hash , string $ algo = 'sha1 ' ): void
1677
1677
{
0 commit comments