Skip to content

Commit

Permalink
Revert "Add missing types to method signatures"
Browse files Browse the repository at this point in the history
This reverts commit 9baf902.
  • Loading branch information
Naktibalda committed Feb 9, 2023
1 parent fbc0f9c commit bb545d4
Show file tree
Hide file tree
Showing 7 changed files with 92 additions and 81 deletions.
8 changes: 7 additions & 1 deletion src/Codeception/Constraint/JsonContains.php
Expand Up @@ -16,8 +16,14 @@

class JsonContains extends Constraint
{
public function __construct(protected array $expected)
/**
* @var array
*/
protected $expected;

public function __construct(array $expected)
{
$this->expected = $expected;
}

/**
Expand Down
17 changes: 13 additions & 4 deletions src/Codeception/Constraint/JsonType.php
Expand Up @@ -13,17 +13,26 @@

class JsonType extends Constraint
{
public function __construct(
protected array $jsonType,
private bool $match = true)
/**
* @var array
*/
protected $jsonType;
/**
* @var bool
*/
private $match;

public function __construct(array $jsonType, bool $match = true)
{
$this->jsonType = $jsonType;
$this->match = $match;
}

/**
* Evaluates the constraint for parameter $other. Returns true if the
* constraint is met, false otherwise.
*
* @param array|JsonArray $jsonArray Value or object to evaluate.
* @param mixed $jsonArray Value or object to evaluate.
*/
protected function matches($jsonArray): bool
{
Expand Down
112 changes: 51 additions & 61 deletions src/Codeception/Module/REST.php
Expand Up @@ -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;
Expand Down Expand Up @@ -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;

Expand All @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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:
Expand All @@ -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
*/
Expand All @@ -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
*/
Expand All @@ -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
Expand All @@ -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
*/
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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.
Expand All @@ -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);
}
Expand All @@ -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);
}
Expand Down Expand Up @@ -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);
}
Expand All @@ -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);
}
Expand All @@ -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);
}
Expand All @@ -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);
}
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -919,15 +901,15 @@ public function dontSeeResponseContains(string $text): void
*
* ``` php
* <?php
* // response: {"name": "john", "email": "john@gmail.com"}
* $I->seeResponseContainsJson(['name' => 'john']);
* // response: {name: john, email: john@gmail.com}
* $I->seeResponseContainsJson(array('name' => 'john'));
*
* // response {"user": "john", "profile": {"email": "john@gmail.com"}}
* $I->seeResponseContainsJson(['email' => 'john@gmail.com']);
* // response {user: john, profile: { email: john@gmail.com }}
* $I->seeResponseContainsJson(array('email' => 'john@gmail.com'));
*
* ```
*
* 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
*/
Expand Down Expand Up @@ -1331,13 +1313,13 @@ public function dontSeeResponseContainsJson(array $json = []): void
*
* ```php
* <?php
* // {"user_id": 1, "email" => "davert@codeception.com"}
* // {'user_id': 1, 'email' => 'davert@codeception.com'}
* $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
* ]);
Expand Down Expand Up @@ -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;
Expand All @@ -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);
}
Expand All @@ -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(),
Expand All @@ -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(),
Expand All @@ -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(),
Expand Down

0 comments on commit bb545d4

Please sign in to comment.