-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Revert "Add missing types to method signatures"
This reverts commit 9baf902.
- Loading branch information
1 parent
fbc0f9c
commit bb545d4
Showing
7 changed files
with
92 additions
and
81 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,10 +22,7 @@ | |
use Codeception\Util\JsonArray; | ||
use Codeception\Util\JsonType; | ||
use Codeception\Util\Soap as XmlUtils; | ||
use Codeception\Util\XmlBuilder; | ||
use Codeception\Util\XmlStructure; | ||
use DOMDocument; | ||
use DOMNode; | ||
use Exception; | ||
use JsonException; | ||
use JsonSchema\Constraints\Constraint as JsonConstraint; | ||
|
@@ -124,13 +121,17 @@ class REST extends Module implements DependsOnModule, PartedModule, API, Conflic | |
|
||
protected int $DEFAULT_SHORTEN_VALUE = 150; | ||
|
||
public HttpKernelBrowser|AbstractBrowser|null $client; | ||
/** | ||
* @var HttpKernelBrowser|AbstractBrowser | ||
*/ | ||
public $client; | ||
|
||
public bool $isFunctional = false; | ||
|
||
protected ?InnerBrowser $connectionModule = null; | ||
|
||
public array|string|ArrayAccess|JsonSerializable $params = []; | ||
/** @var array */ | ||
public $params = []; | ||
|
||
public ?string $response = null; | ||
|
||
|
@@ -149,7 +150,7 @@ protected function resetVariables(): void | |
|
||
public function _conflicts(): string | ||
{ | ||
return API::class; | ||
return \Codeception\Lib\Interfaces\API::class; | ||
} | ||
|
||
public function _depends(): array | ||
|
@@ -201,7 +202,7 @@ protected function getRunningClient(): AbstractBrowser | |
} | ||
|
||
/** | ||
* Sets na HTTP header to be used for all subsequent requests. Use [`deleteHeader`](#deleteHeader) to unset it. | ||
* Sets a HTTP header to be used for all subsequent requests. Use [`deleteHeader`](#deleteHeader) to unset it. | ||
* | ||
* ```php | ||
* <?php | ||
|
@@ -218,7 +219,7 @@ public function haveHttpHeader(string $name, string $value): void | |
} | ||
|
||
/** | ||
* Deletes an HTTP header (that was originally added by [haveHttpHeader()](#haveHttpHeader)), | ||
* Deletes a HTTP header (that was originally added by [haveHttpHeader()](#haveHttpHeader)), | ||
* so that subsequent requests will not send it anymore. | ||
* | ||
* Example: | ||
|
@@ -244,6 +245,7 @@ public function deleteHeader(string $name): void | |
* Checks over the given HTTP header and (optionally) | ||
* its value, asserting that are there | ||
* | ||
* @param $value | ||
* @part json | ||
* @part xml | ||
*/ | ||
|
@@ -264,6 +266,7 @@ public function seeHttpHeader(string $name, $value = null): void | |
* Checks over the given HTTP header and (optionally) | ||
* its value, asserting that are not there | ||
* | ||
* @param $value | ||
* @part json | ||
* @part xml | ||
*/ | ||
|
@@ -283,7 +286,7 @@ public function dontSeeHttpHeader(string $name, $value = null): void | |
/** | ||
* Checks that http response header is received only once. | ||
* HTTP RFC2616 allows multiple response headers with the same name. | ||
* You can check that you didn't accidentally send the same header twice. | ||
* You can check that you didn't accidentally sent the same header twice. | ||
* | ||
* ``` php | ||
* <?php | ||
|
@@ -303,7 +306,7 @@ public function seeHttpHeaderOnce(string $name): void | |
* Returns the value of the specified header name | ||
* | ||
* @param bool $first Whether to return the first value or all header values | ||
* @return string|array|null The first header value if $first is true, an array of values otherwise | ||
* @return string|array The first header value if $first is true, an array of values otherwise | ||
* @part json | ||
* @part xml | ||
*/ | ||
|
@@ -383,7 +386,7 @@ public function amNTLMAuthenticated(string $username, string $password): void | |
} | ||
|
||
/** | ||
* Allows sending REST request using AWS Authorization | ||
* Allows to send REST request using AWS Authorization | ||
* | ||
* Only works with PhpBrowser | ||
* Example Config: | ||
|
@@ -457,6 +460,7 @@ public function amAWSAuthenticated(array $additionalAWSConfig = []): void | |
* ]]); | ||
* ``` | ||
* | ||
* @param array|string|JsonSerializable $params | ||
* @param array $files A list of filenames or "mocks" of $_FILES (each entry being an array with the following | ||
* keys: name, type, error, size, tmp_name (pointing to the real file path). Each key works | ||
* as the "name" attribute of a file input field. | ||
|
@@ -466,10 +470,7 @@ public function amAWSAuthenticated(array $additionalAWSConfig = []): void | |
* @part json | ||
* @part xml | ||
*/ | ||
public function sendPost( | ||
string $url, | ||
array|string|ArrayAccess|JsonSerializable $params = [], | ||
array $files = []): ?string | ||
public function sendPost(string $url, $params = [], array $files = []) | ||
{ | ||
return $this->execute('POST', $url, $params, $files); | ||
} | ||
|
@@ -480,7 +481,7 @@ public function sendPost( | |
* @part json | ||
* @part xml | ||
*/ | ||
public function sendHead(string $url, array $params = []): ?string | ||
public function sendHead(string $url, array $params = []) | ||
{ | ||
return $this->execute('HEAD', $url, $params); | ||
} | ||
|
@@ -510,7 +511,7 @@ public function sendOptions(string $url, array $params = []): void | |
* @part json | ||
* @part xml | ||
*/ | ||
public function sendGet(string $url, array $params = []): ?string | ||
public function sendGet(string $url, array $params = []) | ||
{ | ||
return $this->execute('GET', $url, $params); | ||
} | ||
|
@@ -523,14 +524,11 @@ public function sendGet(string $url, array $params = []): ?string | |
* $response = $I->sendPut('/message/1', ['subject' => 'Read this!']); | ||
* ``` | ||
* | ||
* @param array|string|JsonSerializable $params | ||
* @part json | ||
* @part xml | ||
*/ | ||
public function sendPut( | ||
string $url, | ||
array|string|ArrayAccess|JsonSerializable $params = [], | ||
array $files = [] | ||
): ?string | ||
public function sendPut(string $url, $params = [], array $files = []) | ||
{ | ||
return $this->execute('PUT', $url, $params, $files); | ||
} | ||
|
@@ -543,14 +541,11 @@ public function sendPut( | |
* $response = $I->sendPatch('/message/1', ['subject' => 'Read this!']); | ||
* ``` | ||
* | ||
* @param array|string|JsonSerializable $params | ||
* @part json | ||
* @part xml | ||
*/ | ||
public function sendPatch( | ||
string $url, | ||
array|string|ArrayAccess|JsonSerializable $params = [], | ||
array $files = [] | ||
): ?string | ||
public function sendPatch(string $url, $params = [], array $files = []) | ||
{ | ||
return $this->execute('PATCH', $url, $params, $files); | ||
} | ||
|
@@ -566,26 +561,19 @@ public function sendPatch( | |
* @part json | ||
* @part xml | ||
*/ | ||
public function sendDelete( | ||
string $url, | ||
array|string|ArrayAccess|JsonSerializable $params = [], | ||
array $files = [] | ||
): ?string | ||
public function sendDelete(string $url, array $params = [], array $files = []) | ||
{ | ||
return $this->execute('DELETE', $url, $params, $files); | ||
} | ||
|
||
/** | ||
* Sends a HTTP request. | ||
* | ||
* @param array|string|JsonSerializable $params | ||
* @part json | ||
* @part xml | ||
*/ | ||
public function send( | ||
string $method, | ||
string $url, | ||
array|string|ArrayAccess|JsonSerializable $params = [], | ||
array $files = []): ?string | ||
public function send(string $method, string $url, $params = [], array $files = []) | ||
{ | ||
return $this->execute(strtoupper($method), $url, $params, $files); | ||
} | ||
|
@@ -652,13 +640,13 @@ public function sendUnlink(string $url, array $linkEntries): void | |
} | ||
|
||
/** | ||
* @param $method | ||
* @param $url | ||
* @param array|string|object $parameters | ||
* @param array $files | ||
* @throws ModuleException|ExternalUrlException|JsonException | ||
*/ | ||
protected function execute( | ||
string $method, | ||
string $url, | ||
array|string|ArrayAccess|JsonSerializable $parameters = [], | ||
array $files = []): ?string | ||
protected function execute($method, $url, $parameters = [], $files = []) | ||
{ | ||
// allow full url to be requested | ||
if (!$url) { | ||
|
@@ -704,9 +692,6 @@ protected function execute( | |
|
||
$this->response = $this->connectionModule->_request($method, $url, $parameters, $files); | ||
} else { | ||
/** | ||
* @var string $parameters | ||
*/ | ||
$requestData = $parameters; | ||
if ($this->isBinaryData($requestData)) { | ||
$requestData = $this->binaryToDebugString($requestData); | ||
|
@@ -754,10 +739,7 @@ protected function binaryToDebugString(string $data): string | |
return '[binary-data length:' . strlen($data) . ' md5:' . md5($data) . ']'; | ||
} | ||
|
||
protected function encodeApplicationJson( | ||
string $method, | ||
array|string|ArrayAccess|JsonSerializable $parameters, | ||
): array|string | ||
protected function encodeApplicationJson(string $method, $parameters) | ||
{ | ||
if ( | ||
array_key_exists('Content-Type', $this->connectionModule->headers) | ||
|
@@ -919,15 +901,15 @@ public function dontSeeResponseContains(string $text): void | |
* | ||
* ``` php | ||
* <?php | ||
* // response: {"name": "john", "email": "[email protected]"} | ||
* $I->seeResponseContainsJson(['name' => 'john']); | ||
* // response: {name: john, email: [email protected]} | ||
* $I->seeResponseContainsJson(array('name' => 'john')); | ||
* | ||
* // response {"user": "john", "profile": {"email": "[email protected]"}} | ||
* $I->seeResponseContainsJson(['email' => '[email protected]']); | ||
* // response {user: john, profile: { email: [email protected] }} | ||
* $I->seeResponseContainsJson(array('email' => '[email protected]')); | ||
* | ||
* ``` | ||
* | ||
* This method recursively checks if one array can be found inside another. | ||
* This method recursively checks if one array can be found inside of another. | ||
* | ||
* @part json | ||
*/ | ||
|
@@ -1331,13 +1313,13 @@ public function dontSeeResponseContainsJson(array $json = []): void | |
* | ||
* ```php | ||
* <?php | ||
* // {"user_id": 1, "email" => "[email protected]"} | ||
* // {'user_id': 1, 'email' => '[email protected]'} | ||
* $I->seeResponseMatchesJsonType([ | ||
* 'user_id' => 'string:>0:<1000', // multiple filters can be used | ||
* 'email' => 'string:regex(~\@~)' // we just check that @ char is included | ||
* ]); | ||
* | ||
* // {"user_id"'": "1"} | ||
* // {'user_id': '1'} | ||
* $I->seeResponseMatchesJsonType([ | ||
* 'user_id' => 'string:>0', // works with strings as well | ||
* ]); | ||
|
@@ -1531,9 +1513,10 @@ public function dontSeeXmlResponseMatchesXpath(string $xPath): void | |
* Finds and returns text contents of element. | ||
* Element is matched by either CSS or XPath | ||
* | ||
* @param mixed $cssOrXPath | ||
* @part xml | ||
*/ | ||
public function grabTextContentFromXmlElement(string $cssOrXPath): string | ||
public function grabTextContentFromXmlElement($cssOrXPath): string | ||
{ | ||
$el = (new XmlStructure($this->connectionModule->_getResponseContent()))->matchElement($cssOrXPath); | ||
return $el->textContent; | ||
|
@@ -1559,9 +1542,12 @@ public function grabAttributeFromXmlElement(string $cssOrXPath, string $attribut | |
* Checks XML response equals provided XML. | ||
* Comparison is done by canonicalizing both xml`s. | ||
* | ||
* Parameters can be passed either as DOMDocument, DOMNode, XML string, or array (if no attributes). | ||
* | ||
* @param mixed $xml | ||
* @part xml | ||
*/ | ||
public function seeXmlResponseEquals(DOMDocument|string $xml): void | ||
public function seeXmlResponseEquals($xml): void | ||
{ | ||
Assert::assertXmlStringEqualsXmlString($this->connectionModule->_getResponseContent(), $xml); | ||
} | ||
|
@@ -1571,10 +1557,12 @@ public function seeXmlResponseEquals(DOMDocument|string $xml): void | |
* Checks XML response does not equal to provided XML. | ||
* Comparison is done by canonicalizing both xml`s. | ||
* | ||
* Parameter can be passed either as XmlBuilder, DOMDocument, DOMNode, XML string, or array (if no attributes). | ||
* | ||
* @param mixed $xml | ||
* @part xml | ||
*/ | ||
public function dontSeeXmlResponseEquals(DOMDocument|string $xml): void | ||
public function dontSeeXmlResponseEquals($xml): void | ||
{ | ||
Assert::assertXmlStringNotEqualsXmlString( | ||
$this->connectionModule->_getResponseContent(), | ||
|
@@ -1594,9 +1582,10 @@ public function dontSeeXmlResponseEquals(DOMDocument|string $xml): void | |
* $I->seeXmlResponseIncludes("<result>1</result>"); | ||
* ``` | ||
* | ||
* @param mixed $xml | ||
* @part xml | ||
*/ | ||
public function seeXmlResponseIncludes(DOMNode|XmlBuilder|array|string $xml): void | ||
public function seeXmlResponseIncludes($xml): void | ||
{ | ||
$this->assertStringContainsString( | ||
XmlUtils::toXml($xml)->C14N(), | ||
|
@@ -1610,9 +1599,10 @@ public function seeXmlResponseIncludes(DOMNode|XmlBuilder|array|string $xml): vo | |
* Comparison is done by canonicalizing both xml`s. | ||
* Parameter can be passed either as XmlBuilder, DOMDocument, DOMNode, XML string, or array (if no attributes). | ||
* | ||
* @param mixed $xml | ||
* @part xml | ||
*/ | ||
public function dontSeeXmlResponseIncludes(DOMNode|XmlBuilder|array|string $xml): void | ||
public function dontSeeXmlResponseIncludes($xml): void | ||
{ | ||
$this->assertStringNotContainsString( | ||
XmlUtils::toXml($xml)->C14N(), | ||
|
Oops, something went wrong.