diff --git a/.coveralls.yml b/.coveralls.yml new file mode 100644 index 0000000..5918acb --- /dev/null +++ b/.coveralls.yml @@ -0,0 +1,3 @@ +service_name: travis-ci +coverage_clover: tests/_output/coverage.xml +json_path: tests/_output/coveralls.json \ No newline at end of file diff --git a/.travis.yml b/.travis.yml index 5c9e132..858cdfc 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,31 +1,13 @@ language: php - sudo: false - php: - - 7.1 - - 7.0 - - + - 7.2 before_script: - - pecl channel-update pecl.php.net - - pecl install yaml-2.0.0 < /dev/null - - echo "extension = yaml.so" >> ~/.phpenv/versions/$(phpenv version-name)/etc/php.ini - composer install -n - -addons: - apt: - packages: - - libyaml-dev -addons: - code_climate: - repo_token: b0a53bb7d832d3d4fc6cc499e3709d2206238cb0ba4da93b4e97d1150f17d453 script: - - phpunit --coverage-clover build/logs/clover.xml - + - vendor/bin/codecept run unit --coverage --coverage-xml after_script: - - if [ $TRAVIS_PHP_VERSION >= '7.0' ]; then php vendor/bin/coveralls; fi - + - if [ $TRAVIS_PHP_VERSION = '7.2' ]; then php vendor/bin/php-coveralls; fi after_success: - - travis_retry php vendor/bin/coveralls -v + - travis_retry php vendor/bin/php-coveralls -v - vendor/bin/test-reporter \ No newline at end of file diff --git a/codeception.yml b/codeception.yml new file mode 100644 index 0000000..f0446cc --- /dev/null +++ b/codeception.yml @@ -0,0 +1,10 @@ +paths: + tests: tests + output: tests/_output + data: tests/_data + support: tests/_support + envs: tests/_envs +actor_suffix: Tester +extensions: + enabled: + - Codeception\Extension\RunFailed diff --git a/composer.json b/composer.json index 996ece2..a151f63 100644 --- a/composer.json +++ b/composer.json @@ -1,7 +1,13 @@ { "name": "selami/entity", - "description": "A library to assert variable types, to normalize and to set default values for a model definition.", + "description": "A library to assert variable types and values for a model defined using JSON Schema standard (draft-07 and draft-06).", "type": "library", + "require": { + "php": "^7.2", + "ext-json": "*", + "opis/json-schema": "^1.0", + "ramsey/uuid": "^3.8" + }, "license": "MIT", "authors": [ { @@ -9,34 +15,22 @@ "email": "mehmet@mkorkmaz.com" } ], - "minimum-stability": "dev", - "require": { - "php": "~7.0||~7.1", - "crisu83/shortid": "~1.0", - "ezyang/htmlpurifier": "~4.8", - "seld/jsonlint": "^1.5", - "symfony/yaml": "^3.2" - }, - "require-dev": { - "phpunit/phpunit": "^6.0", - "phpunit/phpcov": "^4.0", - "satooshi/php-coveralls": "^1.0", - "codeclimate/php-test-reporter": "dev-master" - }, - "suggest":{ - "ext-yaml": "Needed to support native yaml parser. Default parser is Symfony Yaml Parser" - }, + "minimum-stability": "stable", "autoload": { "psr-4": { - "Selami\\Entity\\": "src/" - }, - "files":[ - "src/functions.php" - ] - }, - "autoload-dev": { - "psr-4": { - "Selami\\Test\\Abstracts\\": "tests/extend/" + "Selami\\Entity\\" : "./src/" } + }, + "require-dev": { + "squizlabs/php_codesniffer": "^3.3", + "codeception/codeception": "^2.5", + "php-coveralls/php-coveralls": "^2.1", + "object-calisthenics/phpcs-calisthenics-rules": "^3.3" + }, + "scripts": { + "unit-tests": "vendor/bin/codecept run unit --coverage", + "phpcs": "vendor/bin/phpcs --standard=PSR2 src tests", + "phpcbf": "vendor/bin/phpcbf --standard=PSR2 src tests", + "phpcs-object-calisthenics": "vendor/bin/phpcs src -sp --standard=vendor/object-calisthenics/phpcs-calisthenics-rules/src/ObjectCalisthenics/ruleset.xml" } } diff --git a/phpunit.xml b/phpunit.xml deleted file mode 100644 index 3ea939d..0000000 --- a/phpunit.xml +++ /dev/null @@ -1,37 +0,0 @@ - - - - - - - - - - tests - - - - - - benchmark - - - - - ./src - - - - - - diff --git a/src/DataType/Boolean.php b/src/DataType/Boolean.php deleted file mode 100644 index dbeb9ea..0000000 --- a/src/DataType/Boolean.php +++ /dev/null @@ -1,27 +0,0 @@ - false - ]; - /** - * {@inheritdoc} - */ - public function assert() - { - if (!is_bool($this->datum)) { - $this->errorMessageTemplate = self::DATA_TYPE_ERROR; - $this->throwException(); - } - return true; - } -} diff --git a/src/DataType/DataTypeFilterTrait.php b/src/DataType/DataTypeFilterTrait.php deleted file mode 100644 index be10f42..0000000 --- a/src/DataType/DataTypeFilterTrait.php +++ /dev/null @@ -1,100 +0,0 @@ -key = $key; - $this->datum = $datum; - $this->checkValidOptions($options); - $this->options = array_merge(self::$defaults, $options); - } - - /** - * {@inheritdoc} - */ - public function assert() - { - $filter = array_shift($this->filterFlags); - $options =['flags' => $this->filterFlags[0]??null]; - if (!filter_var($this->datum, $filter, $options)) { - $this->errorMessageTemplate = self::DATA_TYPE_ERROR; - $this->throwException(); - } - return true; - } - - /** - * {@inheritdoc} - */ - public function normalize() - { - try { - $this->assert(); - return $this->sanitize(); - } catch (InvalidArgumentException $e) { - return $this->options['default']; - } - } - - protected function sanitize() - { - if ($this->sanitizeFlags !== null) { - return filter_var($this->datum, $this->sanitizeFlags); - } - return $this->datum; - } - - protected function checkValidOptions(array $options) - { - $validOptions = array_keys($this::$defaults); - foreach (array_keys($options) as $optionKey) { - if (!in_array($optionKey, $validOptions, true)) { - throw new InvalidArgumentException(sprintf($this->invalidOptionsErrorMessage, $optionKey)); - } - } - } - - protected function throwException() - { - if (getType($this->datum) === 'array') { - $this->datum = '{NoOtConvertibleToStringValue}'; - } - $message = sprintf( - $this->errorMessageTemplate, - $this->datum, - $this->key - ); - throw new InvalidArgumentException($message); - } -} diff --git a/src/DataType/DataTypeRegexTrait.php b/src/DataType/DataTypeRegexTrait.php deleted file mode 100644 index 1b8d53d..0000000 --- a/src/DataType/DataTypeRegexTrait.php +++ /dev/null @@ -1,26 +0,0 @@ -regex, - $this->datum - ) - ) { - $error = error_get_last(); - $this->errorMessageTemplate = ($error !== null) ? $error['message'] : self::DATA_FORMAT_ERROR; - $this->throwException(); - } - return true; - } -} diff --git a/src/DataType/Date.php b/src/DataType/Date.php deleted file mode 100644 index fb34a3c..0000000 --- a/src/DataType/Date.php +++ /dev/null @@ -1,97 +0,0 @@ - 'Y-m-d H:i:s', - 'default' => 'now', - 'min' => null, - 'max' => null - ]; - - protected static $validDateOptions = [ - 'now', - 'tomorrow', - 'next week', - 'next month', - 'next year', - 'yesterday', - 'previous week', - 'previous month', - 'previous year', - ]; - - /** - * {@inheritdoc} - */ - public function assert() - { - $this->isString(); - $this->checkFormat(); - $this->checkMin(); - $this->checkMax(); - return true; - } - private function isString() - { - if (!is_string($this->datum)) { - $this->errorMessageTemplate = self::DATA_TYPE_ERROR; - $this->throwException(); - } - } - - private function checkFormat() - { - if (in_array($this->datum, self::$validDateOptions, true)) { - return true; - } - $dateTime = DateTime::createFromFormat($this->options['format'], $this->datum); - if (false === $dateTime || $this->datum !== $dateTime->format($this->options['format'])) { - $this->errorMessageTemplate = self::DATA_FORMAT_ERROR; - $this->throwException(); - } - } - - private function checkMin() - { - if (($this->options['min'] !== null) && $this->datum < $this->options['min']) { - $this->errorMessageTemplate = self::DATA_MIN_ERROR . ' ' . $this->options['min']; - $this->throwException(); - } - } - - private function checkMax() - { - if (($this->options['max'] !== null) && ($this->datum > $this->options['max'])) { - $this->errorMessageTemplate = self::DATA_MAX_ERROR . ' ' . $this->options['max']; - $this->throwException(); - } - } - - /** - * {@inheritdoc} - */ - public function normalize() - { - try { - $this->assert(); - $date = new DateTime($this->datum); - } catch (InvalidArgumentException $e) { - $date = new DateTime($this->options['default']); - } - return $date->format($this->options['format']); - } -} diff --git a/src/DataType/Double.php b/src/DataType/Double.php deleted file mode 100644 index 0905602..0000000 --- a/src/DataType/Double.php +++ /dev/null @@ -1,29 +0,0 @@ - 0.0 - ]; - - - /** - * {@inheritdoc} - */ - public function assert() - { - if (!is_float($this->datum)) { - $this->errorMessageTemplate = self::DATA_TYPE_ERROR; - $this->throwException(); - } - return true; - } -} diff --git a/src/DataType/Email.php b/src/DataType/Email.php deleted file mode 100644 index 138291e..0000000 --- a/src/DataType/Email.php +++ /dev/null @@ -1,17 +0,0 @@ - '' - ]; -} diff --git a/src/DataType/Enum.php b/src/DataType/Enum.php deleted file mode 100644 index 63888df..0000000 --- a/src/DataType/Enum.php +++ /dev/null @@ -1,54 +0,0 @@ - false, - 'values' => null - ]; - - - /** - * Enum constructor. - * @param string $key - * @param mixed $datum - * @param array $options - * @throws InvalidArgumentException; - * - */ - public function __construct(string $key, $datum, array $options = []) - { - $this->key = $key; - $this->datum = $datum; - $this->checkValidOptions($options); - $this->options = array_merge(self::$defaults, $options); - if ($this->options['values'] === null - || !is_array($this->options['values']) - || count($this->options['values']) < 2 - ) { - throw new InvalidArgumentException('$options[values] must be an array has at least two elements'); - } - } - - /** - * {@inheritdoc} - */ - public function assert() - { - if (!in_array($this->datum, $this->options['values'], true)) { - $this->errorMessageTemplate = self::DATA_TYPE_ERROR; - $this->throwException(); - } - return true; - } -} diff --git a/src/DataType/FilePath.php b/src/DataType/FilePath.php deleted file mode 100644 index 5bc9482..0000000 --- a/src/DataType/FilePath.php +++ /dev/null @@ -1,17 +0,0 @@ - null - ]; -} diff --git a/src/DataType/Html.php b/src/DataType/Html.php deleted file mode 100644 index d0bfb15..0000000 --- a/src/DataType/Html.php +++ /dev/null @@ -1,35 +0,0 @@ - null - ]; - - /** - * {@inheritdoc} - */ - public function assert() - { - $this->isString(); - return true; - } - - private function isString() - { - if (!is_string($this->datum)) { - $this->errorMessageTemplate = self::DATA_TYPE_ERROR; - $this->throwException(); - } - return true; - } -} diff --git a/src/DataType/Integer.php b/src/DataType/Integer.php deleted file mode 100644 index 6eeab86..0000000 --- a/src/DataType/Integer.php +++ /dev/null @@ -1,30 +0,0 @@ - 0 - ]; - - - /** - * {@inheritdoc} - */ - public function assert() - { - if (!is_int($this->datum)) { - $this->errorMessageTemplate = self::DATA_TYPE_ERROR; - $this->throwException(); - } - return true; - } -} diff --git a/src/DataType/Ipv4.php b/src/DataType/Ipv4.php deleted file mode 100644 index 75c8ab6..0000000 --- a/src/DataType/Ipv4.php +++ /dev/null @@ -1,16 +0,0 @@ - null - ]; -} diff --git a/src/DataType/Ipv6.php b/src/DataType/Ipv6.php deleted file mode 100644 index 024aac0..0000000 --- a/src/DataType/Ipv6.php +++ /dev/null @@ -1,18 +0,0 @@ - null - ]; -} diff --git a/src/DataType/MacAddress.php b/src/DataType/MacAddress.php deleted file mode 100644 index 8441607..0000000 --- a/src/DataType/MacAddress.php +++ /dev/null @@ -1,16 +0,0 @@ - null - ]; -} diff --git a/src/DataType/PhoneNumber.php b/src/DataType/PhoneNumber.php deleted file mode 100644 index 0b8b47a..0000000 --- a/src/DataType/PhoneNumber.php +++ /dev/null @@ -1,16 +0,0 @@ - null - ]; -} diff --git a/src/DataType/Regex.php b/src/DataType/Regex.php deleted file mode 100644 index e3bce49..0000000 --- a/src/DataType/Regex.php +++ /dev/null @@ -1,42 +0,0 @@ - null, - 'regex' => null, - 'sanitize_flag' => null - ]; - - /** - * Regex constructor. - * @param string $key - * @param mixed $datum - * @param array $options - * @throws InvalidArgumentException - */ - public function __construct(string $key, $datum, array $options = []) - { - if (!isset($options['regex']) || empty($options['regex'])) { - throw new InvalidArgumentException('$options[regex] can\'t be empty and must be a valid regex'); - } - $this->key = $key; - $this->datum = $datum; - $this->regex = $options['regex']; - $this->sanitizeFlags = $options['sanitize_flag'] ?? null; - $this->checkValidOptions($options); - $this->options = array_merge(self::$defaults, $options); - } -} diff --git a/src/DataType/Slug.php b/src/DataType/Slug.php deleted file mode 100644 index a48c8f9..0000000 --- a/src/DataType/Slug.php +++ /dev/null @@ -1,17 +0,0 @@ - null - ]; -} diff --git a/src/DataType/Text.php b/src/DataType/Text.php deleted file mode 100644 index f6682a4..0000000 --- a/src/DataType/Text.php +++ /dev/null @@ -1,96 +0,0 @@ - '', - 'min' => 0, - 'max' => null, - 'pad' => 'left', - 'left_pad' => ' ', - 'right_pad' => ' ' - ]; - - protected static $padOptions = [ - 'left' => STR_PAD_LEFT, - 'right' => STR_PAD_RIGHT - ]; - - /** - * {@inheritdoc} - */ - public function assert() - { - $this->isString(); - $this->checkLength(); - return true; - } - - private function isString() - { - if (!is_string($this->datum)) { - $this->errorMessageTemplate = self::DATA_TYPE_ERROR; - $this->throwException(); - } - return true; - } - - private function checkLength() - { - if ($this->options['max'] !== null) { - return $this->checkLengthBetween(); - } - if (mb_strlen($this->datum) < (int) $this->options['min']) { - $this->errorMessageTemplate = self::DATA_LENGTH . 'MIN:' . $this->options['min']; - $this->throwException(); - } - } - - private function checkLengthBetween() - { - $stringLength = mb_strlen($this->datum); - if ($stringLength < (int) $this->options['min'] || $stringLength > (int) $this->options['max']) { - $this->errorMessageTemplate = self::DATA_LENGTH - . 'MIN:' . $this->options['min'] - . 'MAX:' . $this->options['max']; - $this->throwException(); - } - } - - /** - * {@inheritdoc} - */ - public function normalize() - { - if (null === $this->datum) { - return $this->options['default']; - } - if ($this->options['max'] !== null) { - $length = (int) $this->options['max']; - return filter_var( - mb_substr($this->datum, 0, $length), - FILTER_SANITIZE_STRING, - FILTER_FLAG_NO_ENCODE_QUOTES - ); - } - if (strlen($this->datum) < (int) $this->options['min']) { - $padType = self::$padOptions[$this->options['pad']] ?: STR_PAD_RIGHT; - $padding = $this->options[$this->options['pad'].'_pad']; - return filter_var( - str_pad($this->datum, (int) $this->options['min'], $padding, $padType), - FILTER_SANITIZE_STRING, - FILTER_FLAG_NO_ENCODE_QUOTES - ); - } - return filter_var($this->datum, FILTER_SANITIZE_STRING, FILTER_FLAG_NO_ENCODE_QUOTES); - } -} diff --git a/src/DataType/Url.php b/src/DataType/Url.php deleted file mode 100644 index 57b6ad2..0000000 --- a/src/DataType/Url.php +++ /dev/null @@ -1,18 +0,0 @@ - null - ]; -} diff --git a/src/DataType/Uuid.php b/src/DataType/Uuid.php deleted file mode 100644 index 069cacd..0000000 --- a/src/DataType/Uuid.php +++ /dev/null @@ -1,16 +0,0 @@ - '00000000-0000-0000-0000-000000000000' - ]; -} diff --git a/src/Entity.php b/src/Entity.php new file mode 100644 index 0000000..c3ddfc1 --- /dev/null +++ b/src/Entity.php @@ -0,0 +1,109 @@ +model = $model; + $this->data = $data; + if ($data === null) { + $this->data = new stdClass(); + } + $this->checkAndSetId(); + } + + private function checkAndSetId() : void + { + if (!isset($this->data->id)) { + $this->data->id = Uuid::uuid4()->toString(); + } + } + + public function __get($name) + { + return $this->data->{$name}; + } + + public function __set($name, $value) : void + { + $this->data->{$name} = $value; + } + + public function __isset($name) : bool + { + return property_exists($this->data, $name); + } + + public function __unset($name) + { + unset($this->data->{$name}); + } + + public function validate() : bool + { + $validation = (new Validator())->schemaValidation($this->data, $this->model->getSchema()); + if (!$validation->isValid()) { + $errors = $validation->getErrors(); + $message = 'Data validation failed.' . PHP_EOL; + foreach ($errors as $error) { + $message .= sprintf( + 'ERROR: %s. %s', + $error->keyword(), + json_encode($error->keywordArgs(), JSON_PRETTY_PRINT) + ) . PHP_EOL; + } + throw new InvalidArgumentException( + $message + ); + } + return true; + } + + public function equals($rightHandedObject) : bool + { + return (string) $this === (string) $rightHandedObject; + } + + public function jsonSerialize() : string + { + return (string) json_encode($this->data); + } + + public function __toString() + { + return $this->jsonSerialize(); + } + + public static function createFromJsonFile($filePath) : Entity + { + if (!file_exists($filePath)) { + throw new UnexpectedValueException(sprintf('Model definition file (%s) does not exist!', $filePath)); + } + $json = file_get_contents($filePath); + return self::createFromJson($json); + } + + public static function createFromJson($json) : Entity + { + return new static(new Model($json)); + } +} diff --git a/src/Exception/FileNotFoundException.php b/src/Exception/FileNotFoundException.php deleted file mode 100644 index e43baa5..0000000 --- a/src/Exception/FileNotFoundException.php +++ /dev/null @@ -1,12 +0,0 @@ -schema = Schema::fromJsonString($jsonSchema); + } + + public function getSchema() : Schema + { + return $this->schema; + } + + public static function fromJsonFile(string $filePath) : Model + { + if (!file_exists($filePath)) { + throw new UnexpectedValueException(sprintf('Model definition file (%s) does not exist!', $filePath)); + } + return new static(file_get_contents($filePath)); + } +} diff --git a/src/Parser/ConfigIni.php b/src/Parser/ConfigIni.php deleted file mode 100644 index 70694b1..0000000 --- a/src/Parser/ConfigIni.php +++ /dev/null @@ -1,53 +0,0 @@ -setConfig($schemaConfig); - } - } - - /** - * {@inheritDoc} - */ - public function parse() - { - $this->isConfigEmpty($this->schemaConfig); - $schema = @parse_ini_string($this->schemaConfig, true); - if ($schema === false) { - $message = error_get_last(); - throw new InvalidArgumentException($message['message']); - } - return ['schema' => $schema]; - } - - /** - * {@inheritDoc} - */ - public function checkFormat() - { - $schema = @parse_ini_string($this->schemaConfig, true); - return $schema !== false; - } -} diff --git a/src/Parser/Json.php b/src/Parser/Json.php deleted file mode 100644 index c62e874..0000000 --- a/src/Parser/Json.php +++ /dev/null @@ -1,56 +0,0 @@ -setConfig($schemaConfig); - } - } - - /** - * {@inheritDoc} - */ - public function parse() - { - $this->isConfigEmpty($this->schemaConfig); - $schema = json_decode($this->schemaConfig, true); - if (json_last_error() !== JSON_ERROR_NONE) { - $parser = new JsonParser(); - $linting = $parser->lint($this->schemaConfig); - throw new InvalidArgumentException($linting->getMessage()); - } - return $schema; - } - - /** - * {@inheritDoc} - */ - public function checkFormat() - { - $parser = new JsonParser(); - $linting = $parser->lint($this->schemaConfig); - return $linting === null; - } -} diff --git a/src/Parser/ParserFactory.php b/src/Parser/ParserFactory.php deleted file mode 100644 index 7b5ae1a..0000000 --- a/src/Parser/ParserFactory.php +++ /dev/null @@ -1,33 +0,0 @@ - ConfigIni::class, - 'json' => Json::class, - 'yaml' => Yaml::class, - 'xml' => Xml::class, - 'php' => PhpArray::class - ]; - public static function createParser(string $parserType) - { - if (!array_key_exists($parserType, self::$validParsers)) { - $message = sprintf( - 'Invalid parser type: %s. Valid types are case sensitive and possible values are: %s', - $parserType, - implode(', ', array_keys(self::$validParsers)) - ); - throw new InvalidArgumentException($message); - } - return new self::$validParsers[$parserType](); - } -} diff --git a/src/Parser/ParserTrait.php b/src/Parser/ParserTrait.php deleted file mode 100644 index 3855658..0000000 --- a/src/Parser/ParserTrait.php +++ /dev/null @@ -1,55 +0,0 @@ -isConfigEmpty($configString); - $this->schemaConfig = $configString; - } - - /** - * Set the file contains config string - * @param string $configFile - * @return mixed - * @throws FileNotFoundException - * @throws InvalidArgumentException - */ - public function getConfigFromFile(string $configFile) - { - if (!file_exists($configFile)) { - $message = sprintf( - 'File %s could be found', - $configFile - ); - throw new FileNotFoundException($message); - } - $configString = file_get_contents($configFile); - $this->setConfig($configString); - } - - /** - * Checks if schemaConfig is empty - * @param string $configString - * @throws InvalidArgumentException - */ - protected function isConfigEmpty(string $configString) - { - if (empty($configString)) { - throw new InvalidArgumentException('Schema config can\'t be empty'); - } - } -} diff --git a/src/Parser/PhpArray.php b/src/Parser/PhpArray.php deleted file mode 100644 index bd5c06f..0000000 --- a/src/Parser/PhpArray.php +++ /dev/null @@ -1,69 +0,0 @@ -configFile = $configFileName; - } - } - - /** - * {@inheritDoc} - */ - public function parse() - { - try { - $schema = include $this->configFile; - } catch (\Exception $e) { - throw new InvalidArgumentException($e->getMessage()); - } catch (\Error $e) { - throw new InvalidArgumentException($e->getMessage()); - } - if (!is_array($schema)) { - throw new InvalidArgumentException('Config file does not return an array.'); - } - return $schema; - } - - /** - * {@inheritDoc} - */ - public function checkFormat() - { - try { - $schema = include $this->configFile; - if (!is_array($schema)) { - return false; - } - return true; - } catch (\Exception $e) { - // will return false - } catch (\Error $e) { - // will return false - } - return false; - } -} diff --git a/src/Parser/Xml.php b/src/Parser/Xml.php deleted file mode 100644 index 1856f96..0000000 --- a/src/Parser/Xml.php +++ /dev/null @@ -1,78 +0,0 @@ -setConfig($schemaConfig); - } - } - - /** - * {@inheritDoc} - */ - public function parse() - { - $this->isConfigEmpty($this->schemaConfig); - try { - $schemaData = new SimpleXMLElement($this->schemaConfig); - } catch (\Exception $e) { - throw new InvalidArgumentException($e->getMessage()); - } - $schema = $this->getSchema($schemaData); - return ['schema' => $schema]; - } - - /** - * {@inheritDoc} - */ - public function checkFormat() - { - try { - new SimpleXMLElement($this->schemaConfig); - } catch (\Exception $e) { - return false; - } - return true; - } - - private function getSchema($schemaData) - { - return $this->arrayWalkRecursively((array) $schemaData); - } - - private function arrayWalkRecursively(array $schemaData) - { - foreach ($schemaData as $key => $value) { - $newValue = null; - if ($value instanceof SimpleXMLElement) { - $newValue = (array) $value; - $newValue = $this->arrayWalkRecursively($newValue); - } - $schemaData[$key] = $newValue===null ? $value: $newValue; - } - return $schemaData; - } -} diff --git a/src/Parser/Yaml.php b/src/Parser/Yaml.php deleted file mode 100644 index da22f6b..0000000 --- a/src/Parser/Yaml.php +++ /dev/null @@ -1,117 +0,0 @@ -setYamlParser($yamlParser); - if ($schemaConfig !== null) { - $this->setConfig($schemaConfig); - } - } - - /** - * {@inheritDoc} - */ - public function parse() - { - $this->isConfigEmpty($this->schemaConfig); - $schema = $this->yamlParse(); - return $schema; - } - - /** - * {@inheritDoc} - */ - public function checkFormat() - { - try { - SymfonyYaml\Yaml::parse($this->schemaConfig); - return true; - } catch (SymfonyParseException $e) { - return false; - } - } - - /** - * @param string $selectedParser - * @throws UnexpectedValueException - */ - private function setYamlParser(string $selectedParser = 'ext') - { - if (!in_array($selectedParser, self::$yamlParsers, true)) { - throw new UnexpectedValueException('Invalid parser. Possible values are: ' - . implode(', ', self::$yamlParsers)); - } - $yamlParser = 'symfony'; - if (($selectedParser === 'ext') && extension_loaded('yaml')) { - $yamlParser = 'ext'; - } - $this->yamlParser = $yamlParser; - } - - /** - * @return array - * @throws InvalidArgumentException - */ - private function yamlParse() - { - if ($this->yamlParser === 'ext') { - return $this->extParse(); - } - return $this->symfonyParse(); - } - - /** - * @return array - * @throws InvalidArgumentException - */ - private function extParse() - { - try { - return yaml_parse($this->schemaConfig); - } catch (\Exception $e) { - throw new InvalidArgumentException($e->getMessage()); - } - } - - /** - * @return array - * @throws InvalidArgumentException - */ - private function symfonyParse() - { - try { - return (array) SymfonyYaml\Yaml::parse($this->schemaConfig, 0); - } catch (SymfonyParseException $e) { - throw new InvalidArgumentException($e->getMessage()); - } - } -} diff --git a/src/Validator.php b/src/Validator.php deleted file mode 100644 index bd27ff9..0000000 --- a/src/Validator.php +++ /dev/null @@ -1,166 +0,0 @@ - DataType\Boolean::class, - 'Date' => DataType\Date::class, - 'Double' => DataType\Double::class, - 'Email' => DataType\Email::class, - 'Enum' => DataType\Enum::class, - 'FilePath' => DataType\FilePath::class, - 'Html' => DataType\Html::class, - 'Integer' => DataType\Integer::class, - 'Ipv4' => DataType\Ipv4::class, - 'Ipv6' => DataType\Ipv6::class, - 'MacAddress' => DataType\MacAddress::class, - 'PhoneNumber' => DataType\PhoneNumber::class, - 'Regex' => DataType\Regex::class, - 'Slug' => DataType\Slug::class, - 'Text' => DataType\Text::class, - 'Url' => DataType\Url::class, - 'Uuid' => DataType\Uuid::class - ]; - - static protected $validTypes = [ - 'Boolean' => 'boolean', - 'Date' => 'string', - 'Double' => 'float', - 'Email' => 'string', - 'Enum' => 'string', - 'FilePath' => 'string', - 'Html' => 'string', - 'Integer' => 'integer', - 'Ipv4' => 'string', - 'Ipv6' => 'string', - 'MacAddress' => 'string', - 'PhoneNumber' => 'string', - 'Regex' => 'string', - 'Slug' => 'string', - 'Text' => 'string', - 'Url' => 'string', - 'Uuid' => 'string' - ]; - - public function __construct() - { - } - - /** - * @param string $itemKey - * @param mixed $item - * @param array $properties - * @return bool|string - * @throws InvalidArgumentException - */ - public function assertDocItem(string $itemKey, $item, array $properties) - { - $this->checkType($itemKey, $properties); - $dataType = self::$constraints[upperCamelCase($properties['type'])]; - unset($properties['type']); - $constraint = new $dataType($itemKey, $item, $properties); - return $constraint->assert(); - } - - /** - * @param string $itemKey - * @param array $properties - * @return bool - * @throws InvalidArgumentException - */ - private function checkType(string $itemKey, array $properties) - { - if (!array_key_exists('type', $properties)) { - throw new InvalidArgumentException(sprintf('%s must have "type" property.', $itemKey)); - } - if (!array_key_exists(upperCamelCase($properties['type']), self::$constraints)) { - throw new InvalidArgumentException(sprintf('%s is not valid DataType.', $properties['type'])); - } - return true; - } - - /** - * Validate given documents - * - * @param array $schema - * @param array $myDoc - * @param array $myKey - * @return array - * @throws InvalidArgumentException - */ - public function assertDoc(array $schema, array $myDoc, array $myKey = null) - { - $myKeys = array_keys($myDoc); - foreach ($myKeys as $key) { - $myDoc[$key] = $this->assertItem($schema, $myDoc, $key, $myKey); - } - return $myDoc; - } - - /** - * @param array $schema - * @param array $myDoc - * @param string $key - * @param array $myKey - * @return array|bool|string - * @throws InvalidArgumentException; - */ - private function assertItem(array $schema, array $myDoc, string $key, array $myKey = null) - { - $vKey = is_array($myKey) ? $myKey + [$key] : [$key]; - $this->doesSchemaHasKey($schema, $key, $vKey); - $tmp = $this->isMulti($schema, $myDoc[$key], $key, $vKey); - if ($tmp !== false && is_array($tmp)) { - return $tmp; - } - $myDocKeyType = getType($myDoc[$key]); - $this->checkValueType($myDocKeyType, $schema[$key], $vKey); - $this->assertDocItem($key, $myDoc[$key], $schema[$key]); - return $myDoc[$key]; - } - - private function isMulti(array $schema, $myDoc, $key, array $vKey) - { - if (array_key_exists('_many', $schema[$key])) { - $newDoc = []; - foreach ($myDoc as $mKey => $item) { - $tmpvKey = $vKey + [$mKey]; - $newDoc[] = $this->assertDoc($schema[$key]['_many'], $item, $tmpvKey); - } - return $newDoc; - } - return false; - } - - private function doesSchemaHasKey(array $schema, $key, $vKey) - { - // Does doc has an array key that does not exist in model definition. - if (!array_key_exists($key, $schema)) { - $message = sprintf('Error for key "%s" that does not exist in the model', implode('.', $vKey)); - throw new InvalidArgumentException($message); - } - } - - // Is the value of the array[key] have same variable type - //that stated in the definition of the model array. - private function checkValueType($myDocKeyType, $schemaKey, $vKey) - { - if (array_key_exists('type', $schemaKey) - && $myDocKeyType !== self::$validTypes[upperCamelCase($schemaKey['type'])] - ) { - $message = sprintf( - 'Error for key "%s": %s value given but it must have been %s', - implode('.', $vKey), - $myDocKeyType, - self::$validTypes[upperCamelCase($schemaKey['type'])] - ); - throw new InvalidArgumentException($message); - } - } -} diff --git a/src/functions.php b/src/functions.php deleted file mode 100644 index 9f1fa83..0000000 --- a/src/functions.php +++ /dev/null @@ -1,36 +0,0 @@ - Possible values for the returned string are: - * "double" (for historical reasons "double" is returned in case of a float, and not simply "float") - * - * @param mixed $value - * @return string - */ -function getDataType($value) -{ - return [ - 'boolean' => 'boolean', - 'string' => 'string', - 'integer' => 'integer', - 'long' => 'integer', - 'double' => 'float', - 'float' => 'float', - 'array' => 'array', - 'null' => 'null' - ][strtolower(gettype($value))]; -} - -/** - * @param string $str - * @return string - */ -function upperCamelCase(string $str) -{ - return str_replace(' ', '', ucwords(str_replace('_', ' ', $str))); -} diff --git a/tests/DataType/BooleanTest.php b/tests/DataType/BooleanTest.php deleted file mode 100644 index 8746808..0000000 --- a/tests/DataType/BooleanTest.php +++ /dev/null @@ -1,44 +0,0 @@ -className = '\\Selami\\Entity\\DataType\\Boolean'; - $this->validValue = true; - $this->key = 'is_active'; - $this->options = []; - } - - public function trueProvider() - { - return [ - [true], - [false] - ]; - } - - public function exceptionProvider() - { - return [ - ['2323'], - ['13'], - ['03.0'] - ]; - } - - public function defaultsProvider() - { - return [ - [true, true], - [false, false], - [1, false, ['default' => false]] - ]; - } -} diff --git a/tests/DataType/DateTest.php b/tests/DataType/DateTest.php deleted file mode 100644 index eb0293c..0000000 --- a/tests/DataType/DateTest.php +++ /dev/null @@ -1,57 +0,0 @@ -className = '\\Selami\\Entity\\DataType\\Date'; - $this->validValue = '1979-03-18'; - $this->key = 'created_at'; - $this->options = []; - } - - public function trueProvider() - { - return [ - ['1979-03-18', ['format' => 'Y-m-d']], - ['1996-02-29', ['format' => 'Y-m-d']], // leap year: year is evenly divisible by 4 - ['2000-02-29', ['format' => 'Y-m-d']], // leap year: year is evenly divisible by 4, 100 but also 400 - ['1979-03-18 13:30:00', ['format' => 'Y-m-d H:i:s']], - ['13:30:00', ['format' => 'H:i:s']], - ]; - } - - public function exceptionProvider() - { - return [ - ['1979-13-18', ['format' => 'Y-m-d']], - [2016, ['format' => 'Y-m-d']], - ['2016', ['format' => 'Y-m-d']], - ['1979-03-18', ['format' => 'Y-m-d', 'min' => '1980-01-01']], - ['1979-03-18', ['format' => 'Y-m-d', 'max' => '1880-01-01']], - ['1979-03-18', ['format' => 'Y-m-d H:i:s']], - ['1979-03-18 24:00:00', ['format' => 'Y-m-d H:i:s']], - ['1979-03-18 23:60:00', ['format' => 'Y-m-d H:i:s']], - ['1979-03-18 23:59:60', ['format' => 'Y-m-d H:i:s']], - ['1979-03-32', ['format' => 'Y-m-d']], - ['1979-4-30', ['format' => 'Y-m-d']], - ['2000-02', ['format' => 'Y-m-d']], - ['1900-02-29', ['format' => 'Y-m-d']] // not leap year: year is evenly divisible by 4 and 100 - ]; - } - - public function defaultsProvider() - { - return [ - ['now', date('Y-m-d'), ['format' => 'Y-m-d']], - ['1979-03-30', '1979-03-30', ['format' => 'Y-m-d', 'default' => 'now']], - ['2000-02-19', '2000-02-19', ['format' => 'Y-m-d', 'default' => 'now']], - ['1900-02-29', '1979-03-18', ['format' => 'Y-m-d', 'default' => '1979-03-18']] - ]; - } -} diff --git a/tests/DataType/DoubleTest.php b/tests/DataType/DoubleTest.php deleted file mode 100644 index 84f43dc..0000000 --- a/tests/DataType/DoubleTest.php +++ /dev/null @@ -1,45 +0,0 @@ -className = '\\Selami\\Entity\\DataType\\Double'; - $this->validValue = 0.1; - $this->key = 'ratio'; - $this->options = []; - } - - public function trueProvider() - { - return [ - [0.1], - [PHP_INT_MIN/11], - [PHP_INT_MAX/11] - ]; - } - - public function exceptionProvider() - { - return [ - ['2323'], - [1], - [PHP_INT_MAX] - ]; - } - - public function defaultsProvider() - { - return [ - [0.1, 0.1], - [PHP_INT_MAX/11, PHP_INT_MAX/11], - [9, 0.5, ['default' => 0.5]] - ]; - } -} diff --git a/tests/DataType/EmailTest.php b/tests/DataType/EmailTest.php deleted file mode 100644 index 61ea3c0..0000000 --- a/tests/DataType/EmailTest.php +++ /dev/null @@ -1,50 +0,0 @@ -className = '\\Selami\\Entity\\DataType\\Email'; - $this->validValue = 'mehmet@mkorkmaz.com'; - $this->key = 'email'; - $this->options = []; - } - - public function trueProvider() - { - return [ - ['m@k.co'], - ['mehmet.korkmaz@reformo.net'], - ['mehmet+korkmaz@reformo.net'] - ]; - } - - public function exceptionProvider() - { - return [ - ['mehmet@korkmaz@reformo.net'], // no two @ char - ['mehmet @mkorkmaz.com'], // no whitespace - ['m@k.co,m@k.com'], // no comma char - ['m@k.co;m@k.com'], // no colon char - ['.m@k.co'], // no period at the first char - ['m\k@k.co'], // backslash is invalid - ['m+k.co'], // there must be at least one @ char - ['email123456789012345678901234567890123456789012345678901234567890@k.co'] // max 64 char before @ - ]; - } - - public function defaultsProvider() - { - return [ - ['mehmet,@mkorkmaz.com', 'mehmet@mkorkmaz.com', ['default' => 'mehmet@mkorkmaz.com']], - ['m@k.co;m@k.com', null, ['default' => null]], - ['m@k.com', 'm@k.com', ['default' => null]] - ]; - } -} diff --git a/tests/DataType/EnumTest.php b/tests/DataType/EnumTest.php deleted file mode 100644 index e58dd62..0000000 --- a/tests/DataType/EnumTest.php +++ /dev/null @@ -1,49 +0,0 @@ -className = '\\Selami\\Entity\\DataType\\Enum'; - $this->validValue = 'F'; - $this->key = 'gender'; - $this->options = ['values' => ['M','F','NaN']]; - } - - public function trueProvider() - { - return [ - ['M', ['values' => ['M','F','NaN']]], - ['F', ['values' => ['M','F','NaN']]], - [1, ['values' => [1,2,3]]], - ]; - } - - public function exceptionProvider() - { - return [ - ['E', ['values' => ['M','F','NaN']]], - [null, ['values' => ['M','F','NaN']]], - ['F', ['values' => ['M']]], - ['1', ['values' => [1,2,3]]], - [1, ['values' => ['1','2','3']]], - ]; - } - - public function defaultsProvider() - { - return [ - ['M', 'M', ['values' => ['M','F','NaN']]], - ['F', 'F', ['values' => ['M','F','NaN']]], - [1, 'NaN', ['values' => ['M','F','NaN'], 'default' => 'NaN']], - ['1', 3, ['values' => [1,2,3], 'default' => 3]], - [1.1, 1.1, ['values' => [1.1,2.0,3.0], 'default' => 3.0]], - ]; - } -} diff --git a/tests/DataType/FilePathTest.php b/tests/DataType/FilePathTest.php deleted file mode 100644 index 4e2c8d2..0000000 --- a/tests/DataType/FilePathTest.php +++ /dev/null @@ -1,46 +0,0 @@ -className = '\\Selami\\Entity\\DataType\\FilePath'; - $this->validValue = 'path/file.jpg'; - $this->key = 'path'; - $this->options = []; - } - - public function trueProvider() - { - return [ - ['path/to/file.jpg'], - ['path-2'], - ['/etc'], - ['path-2/file.jpg'], - ['path-2/path-3'], - ['path-2/path-3/pa_th'] - ]; - } - - public function exceptionProvider() - { - return [ - ['file/to/path:'], - ['file/t o/path'] - ]; - } - - public function defaultsProvider() - { - return [ - ['-slug', '-slug'], - ['slug/slug:', 'NaN', ['default' => 'NaN']] - ]; - } -} diff --git a/tests/DataType/HtmlTest.php b/tests/DataType/HtmlTest.php deleted file mode 100644 index 2f3f192..0000000 --- a/tests/DataType/HtmlTest.php +++ /dev/null @@ -1,54 +0,0 @@ -className = '\\Selami\\Entity\\DataType\\Html'; - $this->validValue = 'PHP is a popular general-purpose scripting language ' - . 'that is especially suited to web development.'; - $this->key = 'description'; - $this->options = []; - } - - public function trueProvider() - { - return [ - ['Selami Entity3'], - ['Selami Entity'] - ]; - } - - public function exceptionProvider() - { - return [ - [0.1], - [['random_text']] - ]; - } - - public function defaultsProvider() - { - return [ - ['Selami Entity', 'Selami Entity'], - ['Selami', 'Selami'], - ['Selami Entity', 'Selami Entity'], - [ - null, - 'PHP is a popular general-purpose scripting language', - ['default' => 'PHP is a popular general-purpose scripting language'] - ], - [ - 'Selami', - 'Selami', - ['default' => 'PHP is a popular general-purpose scripting language'] - ] - ]; - } -} diff --git a/tests/DataType/IntegerTest.php b/tests/DataType/IntegerTest.php deleted file mode 100644 index 037364c..0000000 --- a/tests/DataType/IntegerTest.php +++ /dev/null @@ -1,45 +0,0 @@ -className = '\\Selami\\Entity\\DataType\\Integer'; - $this->validValue = 1; - $this->key = 'is_active'; - $this->options = []; - } - - public function trueProvider() - { - return [ - [1], - [PHP_INT_MIN], - [PHP_INT_MAX] - ]; - } - - public function exceptionProvider() - { - return [ - ['2323'], - [0.1], - [PHP_INT_MAX+1] - ]; - } - - public function defaultsProvider() - { - return [ - [PHP_INT_MAX, PHP_INT_MAX], - [9, 9], - ['9', 0, ['default' => 0]] - ]; - } -} diff --git a/tests/DataType/Ipv4Test.php b/tests/DataType/Ipv4Test.php deleted file mode 100644 index 6780a52..0000000 --- a/tests/DataType/Ipv4Test.php +++ /dev/null @@ -1,45 +0,0 @@ -className = '\\Selami\\Entity\\DataType\\Ipv4'; - $this->validValue = '127.0.0.1'; - $this->key = 'ip'; - $this->options = []; - } - - public function trueProvider() - { - return [ - ['127.0.0.1'], - ['8.8.8.8'], - ['192.168.0.1'] - ]; - } - - public function exceptionProvider() - { - return [ - ['::1'], - ['8.8.8'], - ['127.0.0.0.1'] - ]; - } - - public function defaultsProvider() - { - return [ - ['192.168.0.1', '192.168.0.1'], - ['8.8.8.8', '8.8.8.8'], - ['8.8.8', null] - ]; - } -} diff --git a/tests/DataType/Ipv6Test.php b/tests/DataType/Ipv6Test.php deleted file mode 100644 index 770d2d0..0000000 --- a/tests/DataType/Ipv6Test.php +++ /dev/null @@ -1,44 +0,0 @@ -className = '\\Selami\\Entity\\DataType\\Ipv6'; - $this->validValue = '127.0.0.1'; - $this->key = 'ip'; - $this->options = []; - } - - public function trueProvider() - { - return [ - ['::1'], - ['2002:0:0:0:0:0:808:808'] - ]; - } - - public function exceptionProvider() - { - return [ - ['127.0.0.1'], - ['8.8.8'], - ['2002:0:0:0:0:0:808:808:0'] - ]; - } - - public function defaultsProvider() - { - return [ - ['::1', '::1'], - ['2002:0:0:0:0:0:808:808', '2002:0:0:0:0:0:808:808'], - ['2002:0:0:0:0:0:808', null] - ]; - } -} diff --git a/tests/DataType/MacAddressTest.php b/tests/DataType/MacAddressTest.php deleted file mode 100644 index 0bccdb4..0000000 --- a/tests/DataType/MacAddressTest.php +++ /dev/null @@ -1,43 +0,0 @@ -className = '\\Selami\\Entity\\DataType\\MacAddress'; - $this->validValue = '22af99d09203'; - $this->key = 'mac_address'; - $this->options = []; - } - - public function trueProvider() - { - return [ - ['28:cf:e9:4a:11:e9'], - ['08:cf:e9:4a:11:e9'] - ]; - } - - public function exceptionProvider() - { - return [ - ['::1'], - ['8:cf:e9:4a:11:e9'], - ['127.0.0.0.1'] - ]; - } - - public function defaultsProvider() - { - return [ - ['28:cf:e9:4a:11:e9', '28:cf:e9:4a:11:e9'], - ['2:cf:e9:4a:11:e9', null] - ]; - } -} diff --git a/tests/DataType/PhoneNumberTest.php b/tests/DataType/PhoneNumberTest.php deleted file mode 100644 index b987804..0000000 --- a/tests/DataType/PhoneNumberTest.php +++ /dev/null @@ -1,44 +0,0 @@ -className = '\\Selami\\Entity\\DataType\\PhoneNumber'; - $this->validValue = '+905555555555'; - $this->key = 'phone_number'; - $this->options = []; - } - - public function trueProvider() - { - return [ - ['+905555555555'], - ['905555555555'], - ['+18004873217'], - ]; - } - - public function exceptionProvider() - { - return [ - ['+90555555555a'], - ['+90555555555555555555'], - ]; - } - - public function defaultsProvider() - { - return [ - ['+90555555555a', null], - ['+905555555555', '+905555555555'], - ['+90555555555a', 'NaN', ['default' => 'NaN']] - ]; - } -} diff --git a/tests/DataType/RegexTest.php b/tests/DataType/RegexTest.php deleted file mode 100644 index eadb785..0000000 --- a/tests/DataType/RegexTest.php +++ /dev/null @@ -1,54 +0,0 @@ -className = '\\Selami\\Entity\\DataType\\Regex'; - $this->validValue = 'valid_regex_text'; - $this->key = 'field'; - $this->options = ['regex' => '#^v#']; - } - - /** - * @test - * @expectedException InvalidArgumentException - */ - public function shouldThrowExceptionForEmptyRegexOption() - { - new $this->className($this->key, $this->validValue, []); - } - - public function trueProvider() - { - return [ - [ - 'https://www.youtube.com/watch?v=1VVj1zqbWpU', - ['regex' => '#(?<=v=)[a-zA-Z0-9-]+(?=&)|(?<=v\/)[^&\n]+|(?<=v=)[^&\n]+|(?<=youtu.be/)[^&\n]+#'] - ] - ]; - } - - public function exceptionProvider() - { - return [ - ['not_found_text', ['regex' => '#^t#']], - ['not_found_text', ['regex' => '#^#t#']] - ]; - } - - public function defaultsProvider() - { - return [ - ['-slug', '-slug', ['regex' => '#^\-#']], - ['slug/slug:', 'NaN', ['default' => 'NaN', 'regex' => '#^t#']] - ]; - } -} diff --git a/tests/DataType/SlugTest.php b/tests/DataType/SlugTest.php deleted file mode 100644 index 388cb1b..0000000 --- a/tests/DataType/SlugTest.php +++ /dev/null @@ -1,48 +0,0 @@ -className = '\\Selami\\Entity\\DataType\\Slug'; - $this->validValue = 'slug-slug'; - $this->key = 'slug'; - $this->options = []; - } - - public function trueProvider() - { - return [ - ['slug'], - ['slug-2'], - ['slug-2-sub'], - ['12-slug-2'] - ]; - } - - public function exceptionProvider() - { - return [ - ['-slug'], - ['-slug-'], - ['slug/slug'], - ['www.github.com'], - ['http:/www.github.com'], - ['Selami Entity'] - ]; - } - - public function defaultsProvider() - { - return [ - ['-slug', null], - ['slug/slug', 'NaN', ['default' => 'NaN']] - ]; - } -} diff --git a/tests/DataType/TextTest.php b/tests/DataType/TextTest.php deleted file mode 100644 index 2dbde1f..0000000 --- a/tests/DataType/TextTest.php +++ /dev/null @@ -1,57 +0,0 @@ -className = '\\Selami\\Entity\\DataType\\Text'; - $this->validValue = 'PHP is a popular general-purpose scripting language ' - . 'that is especially suited to web development.'; - $this->key = 'description'; - $this->options = []; - } - - public function trueProvider() - { - return [ - ['Selami Entity'], - ['Selami Entity', ['max'=> 200]] - ]; - } - - public function exceptionProvider() - { - return [ - ['2323', ['min' => 5]], - [0.1], - ['Selami Entity', ['max'=> 10]] - ]; - } - - public function defaultsProvider() - { - return [ - ['Selami Entity', 'Selami Entity'], - ['Selami', 'Selami'], - ['Selami Entity', 'Selami Entity', ['max' => 200]], - [ - null, - 'PHP is a popular general-purpose scripting language', - ['min' => 10, 'default' => 'PHP is a popular general-purpose scripting language'] - ], - [ - 'Selami', - 'Selami ', - ['min' => 10, 'default' => 'PHP is a popular general-purpose scripting language', 'pad' => 'right'] - ], - ['Selami Entity', 'Selami Ent', ['max' => 10]], - ["", "alert('XSS');"] - ]; - } -} diff --git a/tests/DataType/UrlTest.php b/tests/DataType/UrlTest.php deleted file mode 100644 index f7ab7d3..0000000 --- a/tests/DataType/UrlTest.php +++ /dev/null @@ -1,51 +0,0 @@ -className = '\\Selami\\Entity\\DataType\\Url'; - $this->validValue = 'http://github.com'; - $this->key = 'www'; - $this->options = []; - } - - public function trueProvider() - { - return [ - ['http://github.com'], - ['http://www.github.com'], - ['https://github.com'], - ['https://github.com/selamiphp'], - ['https://github.com/selamiphp/entity'], - ['https://github.com/selamiphp/entity/search?utf8=%E2%9C%93&q=php'], - ['https://username@github.com/selamiphp/entity'], - ['https://username:password@github.com/selamiphp/entity'], - ['ssh://username:password@github.com/selamiphp/entity'], - ['mailto:noreply@github.com'], - ]; - } - - public function exceptionProvider() - { - return [ - ['www.github.com'], - ['http:/www.github.com'], - ['Selami Entity'] - ]; - } - - public function defaultsProvider() - { - return [ - ['www.github.com', null], - ['www.github.com', 'NaN', ['default' => 'NaN']] - ]; - } -} diff --git a/tests/DataType/UuidTest.php b/tests/DataType/UuidTest.php deleted file mode 100644 index c9309d7..0000000 --- a/tests/DataType/UuidTest.php +++ /dev/null @@ -1,45 +0,0 @@ -className = '\\Selami\\Entity\\DataType\\Uuid'; - $this->validValue = 'TextTest.php'; - $this->key = 'description'; - $this->options = []; - } - - public function trueProvider() - { - return [ - ['9507c888-2186-443d-8e4a-9bee412be869'], - ['7b2dcd95-13a2-46e9-ac31-7b2772d63404'] - ]; - } - - public function exceptionProvider() - { - return [ - ['7b2dcd95-13a2-46e9-ac31-7b2772d6340'], - ['b2dcd95-13a2-46e9-ac31-7b2772d63404'], - ['7g2dcd95-13a2-46e9-ac31-7b2772d63404'], - ['random-text'] - ]; - } - - public function defaultsProvider() - { - return [ - ['9507c888-2186-443d-8e4a-9bee412be869', '9507c888-2186-443d-8e4a-9bee412be869'], - ['00000000-0000-0000-0000-000000000000', '00000000-0000-0000-0000-000000000000'], - ['b2dcd95-13a2-46e9-ac31-7b2772d63404', '00000000-0000-0000-0000-000000000000'] - ]; - } -} diff --git a/tests/FunctionsTest.php b/tests/FunctionsTest.php deleted file mode 100644 index f08f2d3..0000000 --- a/tests/FunctionsTest.php +++ /dev/null @@ -1,45 +0,0 @@ -assertEquals($expected, $type); - } - - public function typeProvider() - { - return [ - [true, 'boolean'], - ['string', 'string'], - [1, 'integer'], - [PHP_INT_MAX, 'integer'], - [7E-10, 'float'], - [1.1, 'float'], - [['item'], 'array'], - [null, 'null'] - ]; - } - - /** - * @test - */ - public function upperCamelCaseShouldReturnRightString() - { - - $this->assertEquals('FilePath', Entity\upperCamelCase('file_path')); - } -} diff --git a/tests/Parser/ConfigIniParserClassTest.php b/tests/Parser/ConfigIniParserClassTest.php deleted file mode 100644 index cde49f3..0000000 --- a/tests/Parser/ConfigIniParserClassTest.php +++ /dev/null @@ -1,114 +0,0 @@ -getConfigFromFile(dirname(__DIR__) . '/resources/config_data/config.ini'); - $this->assertInstanceOf(ParserInterface::class, $parser); - $schema = $parser->parse(); - $this->assertArrayHasKey('schema', $schema); - $this->assertArrayHasKey('id', $schema ['schema']); - $this->assertArrayHasKey('age', $schema ['schema']); - $this->assertArrayHasKey('is_active', $schema ['schema']); - $this->assertArrayHasKey('type', $schema ['schema']['id']); - $this->assertEquals('int', $schema ['schema']['id']['type']); - $this->assertEquals(3, $schema ['schema']['id']['length']); - $this->assertEquals(0, $schema ['schema']['id']['min']); - $this->assertEquals(999, $schema ['schema']['id']['max']); - } - - /** - * @test - * @expectedException InvalidArgumentException - */ - public function shouldThrowInvalidArgumentExceptionForInvalidConfigIni() - { - $parser = new ConfigIni($this->invalidSchema); - $parser->parse(); - } - - /** - * @test - * @expectedException Selami\Entity\Exception\FileNotFoundException - */ - public function shouldThrowFileNotFoundExceptionForInvalidConfigIni() - { - $parser = new ConfigIni(); - $parser->getConfigFromFile('/tmp/not_existed_config_file'); - } - - - /** - * @test - */ - public function shouldReturnTrueForCheckFormatMethod() - { - $parser = new ConfigIni($this->validSchema); - $isFormatOk = $parser->checkFormat(); - $this->assertTrue($isFormatOk); - } - /** - * @test - */ - public function shouldReturnFalseForCheckFormatMethod() - { - $parser = new ConfigIni($this->invalidSchema); - $isFormatOk = $parser->checkFormat(); - $this->assertFalse($isFormatOk); - } -} diff --git a/tests/Parser/JsonParserClassTest.php b/tests/Parser/JsonParserClassTest.php deleted file mode 100644 index 9d41635..0000000 --- a/tests/Parser/JsonParserClassTest.php +++ /dev/null @@ -1,97 +0,0 @@ -getConfigFromFile(dirname(__DIR__) . '/resources/config_data/config.json'); - $this->assertInstanceOf(ParserInterface::class, $parser); - $schema = $parser->parse(); - $this->assertArrayHasKey('schema', $schema); - $this->assertArrayHasKey('id', $schema ['schema']); - $this->assertArrayHasKey('age', $schema ['schema']); - $this->assertArrayHasKey('is_active', $schema ['schema']); - $this->assertArrayHasKey('type', $schema ['schema']['id']); - $this->assertEquals('int', $schema ['schema']['id']['type']); - $this->assertEquals(3, $schema ['schema']['id']['length']); - $this->assertEquals(0, $schema ['schema']['id']['min']); - $this->assertEquals(999, $schema ['schema']['id']['max']); - } - - /** - * @test - * @expectedException InvalidArgumentException - */ - public function shouldThrowInvalidArgumentExceptionForInvalidJson() - { - $parser = new Json($this->invalidSchema); - $parser->parse(); - } - - /** - * @test - * @expectedException Selami\Entity\Exception\FileNotFoundException - */ - public function shouldThrowFileNotFoundExceptionForInvalidJson() - { - $parser = new Json(); - $parser->getConfigFromFile('/tmp/not_existed_config_file'); - } - - - /** - * @test - */ - public function shouldReturnTrueForCheckFormatMethod() - { - $parser = new Json($this->validSchema); - $isFormatOk = $parser->checkFormat(); - $this->assertTrue($isFormatOk); - } - /** - * @test - */ - public function shouldReturnFalseForCheckFormatMethod() - { - $parser = new Json($this->invalidSchema, false); - $isFormatOk = $parser->checkFormat(); - $this->assertFalse($isFormatOk); - } -} diff --git a/tests/Parser/ParserFactoryTest.php b/tests/Parser/ParserFactoryTest.php deleted file mode 100644 index a5c1f0a..0000000 --- a/tests/Parser/ParserFactoryTest.php +++ /dev/null @@ -1,44 +0,0 @@ -assertInstanceOf($expected, $parser); - } - - public function parserTypeProvider() - { - return [ - ['ini', ConfigIni::class], - ['ini', ParserInterface::class] - ]; - } - - /** - * @test - * @expectedException InvalidArgumentException - */ - public function shouldThrowInvalidArgumentExceptionForInvalidConfigIni() - { - ParserFactory::createParser('html'); - } - -} diff --git a/tests/Parser/ParserTraitTest.php b/tests/Parser/ParserTraitTest.php deleted file mode 100644 index 1f190d5..0000000 --- a/tests/Parser/ParserTraitTest.php +++ /dev/null @@ -1,108 +0,0 @@ -getObjectForTrait(ParserTrait::class); - - $this->assertAttributeEmpty('schemaConfig', $parseTrait); - - return $parseTrait; - } - - /** - * @test - * @cover ParserTrait::setConfig - * @depends shouldInitiallyEmpty - * @param ParseTrait $parseTrait - */ - public function shouldSetConfigSuccessfully($parseTrait) - { - $parseTrait->setConfig('random_text'); - $this->assertAttributeEquals( - 'random_text', - 'schemaConfig', - $parseTrait - ); - } - - /** - * @test - * @cover ParserTrait::setConfig - * @depends shouldInitiallyEmpty - * @param ParseTrait $parseTrait - * @expectedException InvalidArgumentException - */ - public function shouldFailSettingEmptyConfig($parseTrait) - { - $parseTrait->setConfig(''); - $this->assertAttributeEquals( - 'random_text', - 'schemaConfig', - $parseTrait - ); - } - - /** - * @test - * @cover ParserTrait::getConfigFromFile - * @depends shouldInitiallyEmpty - * @param ParseTrait $parseTrait - */ - public function shouldGetConfigFromFileSuccessfully($parseTrait) - { - $parseTrait->getConfigFromFile(dirname(__DIR__) . '/resources/config_data/config_for_trait.txt'); - $this->assertAttributeEquals( - 'random_text_from_file', - 'schemaConfig', - $parseTrait - ); - } - - /** - * @test - * @cover ParserTrait::getConfigFromFile - * @depends shouldInitiallyEmpty - * @param ParseTrait $parseTrait - * @expectedException InvalidArgumentException - */ - public function shouldFailGettingConfigFromFile($parseTrait) - { - $parseTrait->getConfigFromFile(dirname(__DIR__) . '/resources/config_data/empty_config_for_trait.txt'); - $this->assertAttributeEquals( - 'random_text_from_file', - 'schemaConfig', - $parseTrait - ); - } - - /** - * @test - * @cover ParserTrait::getConfigFromFile - * @depends shouldInitiallyEmpty - * @param ParseTrait $parseTrait - * @expectedException Selami\Entity\Exception\FileNotFoundException - */ - public function shouldNotFoundNonExistedConfigFromFile($parseTrait) - { - $parseTrait->getConfigFromFile(dirname(__DIR__) . '/tmp/imaginary_trait_config_file.txt'); - $this->assertAttributeEquals( - 'random_text_from_file', - 'schemaConfig', - $parseTrait - ); - } -} diff --git a/tests/Parser/PhpArrayParserClassTest.php b/tests/Parser/PhpArrayParserClassTest.php deleted file mode 100644 index a20b3fc..0000000 --- a/tests/Parser/PhpArrayParserClassTest.php +++ /dev/null @@ -1,216 +0,0 @@ -validSchema = dirname(__DIR__) . '/resources/config_data/config.php'; - $this->invalidSchema = [ - dirname(__DIR__) . '/resources/config_data/config_invalid.php', - dirname(__DIR__) . '/resources/config_data/config_invalid_parse.php', - dirname(__DIR__) . '/resources/config_data/config_invalid_type.php', - dirname(__DIR__) . '/resources/config_data/config_invalid_division_by_zero.php', - dirname(__DIR__) . '/resources/config_data/config_invalid_arithmetic.php', - dirname(__DIR__) . '/resources/config_data/config_invalid_assertion.php', - dirname(__DIR__) . '/resources/config_data/config_invalid_not_array.php' - ]; - } - - /** - * @test - */ - public function shouldReturnArrayCorrectly() - { - $parser = new PhpArray($this->validSchema); - $this->assertInstanceOf(ParserInterface::class, $parser); - $schema = $parser->parse(); - $this->assertArrayHasKey('schema', $schema); - $this->assertArrayHasKey('id', $schema ['schema']); - $this->assertArrayHasKey('age', $schema ['schema']); - $this->assertArrayHasKey('is_active', $schema ['schema']); - $this->assertArrayHasKey('type', $schema ['schema']['id']); - $this->assertEquals('int', $schema ['schema']['id']['type']); - $this->assertEquals(3, $schema ['schema']['id']['length']); - $this->assertEquals(0, $schema ['schema']['id']['min']); - $this->assertEquals(999, $schema ['schema']['id']['max']); - } - - /** - * @test - * @expectedException InvalidArgumentException - */ - public function shouldThrowInvalidArgumentExceptionForInvalidArray() - { - $parser = new PhpArray($this->invalidSchema[0]); - $parser->parse(); - } - - /** - * @test - * @expectedException InvalidArgumentException - */ - public function shouldThrowInvalidArgumentExceptionForPhpParseError() - { - $parser = new PhpArray($this->invalidSchema[1]); - $parser->parse(); - } - - /** - * @test - * @expectedException InvalidArgumentException - */ - public function shouldThrowInvalidArgumentExceptionForPhpTypeError() - { - - $parser = new PhpArray($this->invalidSchema[2]); - $parser->parse(); - } - - /** - * @test - * @expectedException InvalidArgumentException - */ - public function shouldThrowInvalidArgumentExceptionForPhpDivisionByZeroError() - { - $parser = new PhpArray($this->invalidSchema[3]); - $parser->parse(); - } - - /** - * @test - * @expectedException InvalidArgumentException - */ - public function shouldThrowInvalidArgumentExceptionForPhpArithmeticError() - { - - $parser = new PhpArray($this->invalidSchema[4]); - $parser->parse(); - } - - /** - * @test - * @expectedException InvalidArgumentException - */ - public function shouldThrowInvalidArgumentExceptionForPhpAssertionError() - { - - $parser = new PhpArray($this->invalidSchema[5]); - $parser->parse(); - } - - /** - * @test - * @expectedException InvalidArgumentException - * - */ - public function shouldThrowInvalidArgumentExceptionForInvalidReturnArray() - { - $parser = new PhpArray($this->invalidSchema[6]); - $parser->parse(); - } - - /** - * @test - * @expectedException Selami\Entity\Exception\FileNotFoundException - */ - public function shouldThrowFileNotFoundExceptionForInvalidArray() - { - $parser = new PhpArray(); - $parser->getConfigFromFile($this->imaginaryFile); - } - - - /** - * @test - */ - public function shouldReturnTrueForCheckFormatMethod() - { - $parser = new PhpArray($this->validSchema); - $isFormatOk = $parser->checkFormat(); - $this->assertTrue($isFormatOk); - } - - /** - * @test - */ - public function shouldReturnFalseForCheckFormatMethodForInvalidArray() - { - $parser = new PhpArray($this->invalidSchema[0]); - $isFormatOk = $parser->checkFormat(); - $this->assertFalse($isFormatOk); - } - - /** - * @test - */ - public function shouldReturnFalseForCheckFormatMethodForPhpParseError() - { - $parser = new PhpArray($this->invalidSchema[1]); - $isFormatOk = $parser->checkFormat(); - $this->assertFalse($isFormatOk); - } - - /** - * @test - */ - public function shouldReturnFalseForCheckFormatMethodForPhpTypeError() - { - $parser = new PhpArray($this->invalidSchema[2]); - $isFormatOk = $parser->checkFormat(); - $this->assertFalse($isFormatOk); - } - - /** - * @test - */ - public function shouldReturnFalseForCheckFormatMethodForPhpDivisionByZeroError() - { - $parser = new PhpArray($this->invalidSchema[3]); - $isFormatOk = $parser->checkFormat(); - $this->assertFalse($isFormatOk); - } - - /** - * @test - */ - public function shouldReturnFalseForCheckFormatMethodForPhpArithmeticError() - { - $parser = new PhpArray($this->invalidSchema[4]); - $isFormatOk = $parser->checkFormat(); - $this->assertFalse($isFormatOk); - } - - /** - * @test - */ - public function shouldReturnFalseForCheckFormatMethodforPhpAssertionError() - { - $parser = new PhpArray($this->invalidSchema[5]); - $isFormatOk = $parser->checkFormat(); - $this->assertFalse($isFormatOk); - } - - /** - * @test - */ - public function shouldReturnFalseForCheckFormatMethodForInvalidReturnArray() - { - $parser = new PhpArray($this->invalidSchema[6]); - $isFormatOk = $parser->checkFormat(); - $this->assertFalse($isFormatOk); - } -} diff --git a/tests/Parser/XmlParserClassTest.php b/tests/Parser/XmlParserClassTest.php deleted file mode 100644 index c1f352f..0000000 --- a/tests/Parser/XmlParserClassTest.php +++ /dev/null @@ -1,121 +0,0 @@ - - - - int - 3 - 0 - 999 - - - int - 3 - 0 - 120 - - - enum - 1 - - 0 - 1 - - - -'; - - protected $invalidSchema = ' - - - int - 3 - 0 - 999 - - - int - 3 - 0 - 120 - - - enum - 1 - - 0 - 1 - - -'; - - - /** - * @test - */ - public function shouldReturnArrayCorrectly() - { - $parser = new Xml(); - $parser->getConfigFromFile(dirname(__DIR__) . '/resources/config_data/config.xml'); - $this->assertInstanceOf(ParserInterface::class, $parser); - $schema = $parser->parse(); - $this->assertArrayHasKey('schema', $schema); - $this->assertArrayHasKey('id', $schema ['schema']); - $this->assertArrayHasKey('age', $schema ['schema']); - $this->assertArrayHasKey('is_active', $schema ['schema']); - $this->assertArrayHasKey('type', $schema ['schema']['id']); - $this->assertEquals('int', $schema ['schema']['id']['type']); - $this->assertEquals(3, $schema ['schema']['id']['length']); - $this->assertEquals(0, $schema ['schema']['id']['min']); - $this->assertEquals(999, $schema ['schema']['id']['max']); - } - - - /** - * @test - * @expectedException InvalidArgumentException - */ - public function shouldThrowInvalidArgumentExceptionForInvalidXml() - { - $parser = new Xml($this->invalidSchema); - $parser->parse(); - } - - /** - * @test - * @expectedException Selami\Entity\Exception\FileNotFoundException - */ - public function shouldThrowFileNotFoundExceptionForInvalidXml() - { - $parser = new Xml(); - $parser->getConfigFromFile('/tmp/not_existed_config_file'); - } - - /** - * @test - */ - public function shouldReturnTrueForCheckFormatMethod() - { - $parser = new Xml($this->validSchema); - $isFormatOk = $parser->checkFormat(); - $this->assertTrue($isFormatOk); - } - /** - * @test - */ - public function shouldReturnFalseForCheckFormatMethod() - { - $parser = new Xml($this->invalidSchema); - $isFormatOk = $parser->checkFormat(); - $this->assertFalse($isFormatOk); - } -} diff --git a/tests/Parser/YamlParserClassTest.php b/tests/Parser/YamlParserClassTest.php deleted file mode 100644 index 6e118e1..0000000 --- a/tests/Parser/YamlParserClassTest.php +++ /dev/null @@ -1,161 +0,0 @@ -getConfigFromFile(dirname(__DIR__) . '/resources/config_data/config.yaml'); - $this->assertInstanceOf(ParserInterface::class, $parser); - $schema = $parser->parse(); - $this->assertArrayHasKey('schema', $schema); - $this->assertArrayHasKey('id', $schema ['schema']); - $this->assertArrayHasKey('age', $schema ['schema']); - $this->assertArrayHasKey('is_active', $schema ['schema']); - $this->assertArrayHasKey('type', $schema ['schema']['id']); - $this->assertEquals('int', $schema ['schema']['id']['type']); - $this->assertEquals(3, $schema ['schema']['id']['length']); - $this->assertEquals(0, $schema ['schema']['id']['min']); - $this->assertEquals(999, $schema ['schema']['id']['max']); - } - - - /** - * @test - * @expectedException InvalidArgumentException - */ - public function shouldThrowInvalidArgumentExceptionForInvalidYamlExt() - { - $parser = new Yaml('ext', $this->invalidSchema); - $parser->parse(); - } - - /** - * @test - * @expectedException Selami\Entity\Exception\FileNotFoundException - */ - public function shouldThrowFileNotFoundExceptionForInvalidYamlExt() - { - $parser = new Yaml('ext'); - $parser->getConfigFromFile('/tmp/not_existed_config_file'); - } - - /** - * @test - */ - public function shouldReturnTrueForCheckFormatMethodExt() - { - $parser = new Yaml('ext', $this->validSchema); - $isFormatOk = $parser->checkFormat(); - $this->assertTrue($isFormatOk); - } - /** - * @test - */ - public function shouldReturnFalseForCheckFormatMethodExt() - { - $parser = new Yaml('ext', $this->invalidSchema); - $isFormatOk = $parser->checkFormat(); - $this->assertFalse($isFormatOk); - } - - - - /** - * @test - */ - public function shouldReturnArrayCorrectlySymfony() - { - $parser = new Yaml('symfony'); - $parser->getConfigFromFile(dirname(__DIR__) . '/resources/config_data/config.yaml'); - $this->assertInstanceOf(ParserInterface::class, $parser); - $schema = $parser->parse(); - $this->assertArrayHasKey('schema', $schema); - $this->assertArrayHasKey('id', $schema ['schema']); - $this->assertArrayHasKey('age', $schema ['schema']); - $this->assertArrayHasKey('is_active', $schema ['schema']); - $this->assertArrayHasKey('type', $schema ['schema']['id']); - $this->assertEquals('int', $schema ['schema']['id']['type']); - $this->assertEquals(3, $schema ['schema']['id']['length']); - $this->assertEquals(0, $schema ['schema']['id']['min']); - $this->assertEquals(999, $schema ['schema']['id']['max']); - } - - /** - * @test - * @expectedException InvalidArgumentException - */ - public function shouldThrowInvalidArgumentExceptionForInvalidYamlSymfony() - { - $parser = new Yaml('symfony', $this->invalidSchema); - $parser->parse(); - } - - /** - * @test - * @expectedException Selami\Entity\Exception\FileNotFoundException - */ - public function shouldThrowFileNotFoundExceptionForInvalidYamlSymfony() - { - $parser = new Yaml('symfony'); - $parser->getConfigFromFile('/tmp/not_existed_config_file.yaml'); - } -} diff --git a/tests/ValidatorClassTest.php b/tests/ValidatorClassTest.php deleted file mode 100644 index 6dcb92d..0000000 --- a/tests/ValidatorClassTest.php +++ /dev/null @@ -1,257 +0,0 @@ - [ - 'type' => 'integer' - ], - 'email' => [ - 'type' => 'email' - ], - 'is_active' => [ - 'type' => 'enum', - 'values' => ['0', '1'] - ] - ]; - public $validSchema2 = [ - 'id' => [ - 'type' => 'integer' - ], - 'email' => [ - 'type' => 'email' - ], - 'is_active' => [ - 'type' => 'enum', - 'values' => ['0', '1'] - ], - 'children' => [ - '_many' => [ - 'name' => ['type' => 'text'], - 'education' => [ - '_many' => [ - 'school' => ['type' => 'text'], - 'city' => ['type' => 'text'], - 'year' => ['type' => 'integer'] - ] - ] - ] - ] - ]; - - public $validData1 = [ - 'id' => 1, - 'email' => 'selami@github.com', - 'is_active' => '1' - ]; - - public $validData2 = [ - 'id' => 1, - 'email' => 'selami@github.com', - 'is_active' => '1', - 'children' => [ - [ - 'name' => 'Jon', - 'education' => [ - [ - 'school' => 'Yıldırım Beyazıt', - 'city' => 'Bursa', - 'year' => 1996 - ] - ] - ], - [ - 'name' => 'Jane', - 'education' => [ - [ - 'school' => 'Ankara University', - 'city' => 'Ankara', - 'year' => 2003 - - ] - ] - ] - ] - ]; - - - /** - * @test - * @expectedException InvalidArgumentException - */ - public function shouldThrowInvalidArgumentExceptionForCheckTypeMissingProperty() - { - $properties = [ - '_type' => 'integer' - ]; - $method = new ReflectionMethod(Validator::class, 'checkType'); - $method->setAccessible(true); - $method->invoke(new Validator(), 'key', $properties); - } - - /** - * @test - * @expectedException InvalidArgumentException - */ - public function shouldThrowInvalidArgumentExceptionForCheckTypeInvalidDataType() - { - $properties = [ - 'type' => 'nteger' - ]; - $method = new ReflectionMethod(Validator::class, 'checkType'); - $method->setAccessible(true); - $method->invoke(new Validator(), 'key', $properties); - } - - /** - * @test - */ - public function shouldTReturnTrueForCheckType() - { - $properties = [ - 'type' => 'integer' - ]; - $method = new ReflectionMethod(Validator::class, 'checkType'); - $method->setAccessible(true); - $this->assertTrue($method->invoke(new Validator(), 'key', $properties)); - } - - /** - * @test - */ - public function shouldAssertTrueForAssertDocItem() - { - $constraint = new Validator(); - $assert = $constraint->assertDocItem('key', 'selami@github.com', ['type' => 'email']); - $this->assertTrue($assert); - } - - /** - * @test - * @expectedException InvalidArgumentException - */ - public function shouldReturnErrorForAssertDocItem() - { - $constraint = new Validator(); - $assert = $constraint->assertDocItem('key', 'selami@t@github.com', ['type' => 'email']); - $this->assertContains('INVALID_MAIL_ADDRESS_FORMAT', $assert); - } - - /** - * @test - */ - public function shouldAssertTrueForAssertDoc() - { - $constraint = new Validator(); - $assert = $constraint->assertDoc($this->validSchema1, $this->validData1); - $this->assertArrayHasKey('id', $assert); - $this->assertArrayHasKey('email', $assert); - $this->assertArrayHasKey('is_active', $assert); - $this->assertSame(1, $assert['id']); - $this->assertSame('selami@github.com', $assert['email']); - $this->assertSame('1', $assert['is_active']); - } - - /** - * @test - */ - public function shouldAssertTrueForNestedAssertDoc() - { - $constraint = new Validator(); - $assert = $constraint->assertDoc($this->validSchema2, $this->validData2); - - $this->assertArrayHasKey('id', $assert); - $this->assertArrayHasKey('email', $assert); - $this->assertArrayHasKey('is_active', $assert); - $this->assertSame(1, $assert['id']); - $this->assertSame('selami@github.com', $assert['email']); - $this->assertSame('1', $assert['is_active']); - $this->assertArrayHasKey(0, $assert['children']); - $this->assertArrayHasKey('name', $assert['children'][0]); - $this->assertSame('Jon', $assert['children'][0]['name']); - - $this->assertArrayHasKey(1, $assert['children']); - $this->assertArrayHasKey('name', $assert['children'][1]); - $this->assertSame('Jane', $assert['children'][1]['name']); - - $this->assertArrayHasKey('education', $assert['children'][0]); - $this->assertArrayHasKey('school', $assert['children'][0]['education'][0]); - $this->assertArrayHasKey('city', $assert['children'][0]['education'][0]); - $this->assertArrayHasKey('year', $assert['children'][0]['education'][0]); - $this->assertSame('Yıldırım Beyazıt', $assert['children'][0]['education'][0]['school']); - $this->assertSame('Bursa', $assert['children'][0]['education'][0]['city']); - $this->assertSame(1996, $assert['children'][0]['education'][0]['year']); - } - - - /** - * @test - * @dataProvider invalidDataProvider - * @param array $invalidData - * @expectedException InvalidArgumentException - */ - public function shouldThrowExceptionForAssertDoc($invalidData) - { - $constraint = new Validator(); - $constraint->assertDoc($this->validSchema1, $invalidData); - } - - public function invalidDataProvider() - { - return [ - [ - ['id' => 2, 'non_existing_field' => 'some_text'], - ['id' => 2, 'email' => 'selami@github.com', 'is_active' => 1] - ] - ]; - } - - /** - * @test - * @dataProvider invalidSchemaProvider - * @param array $invalidSchema - * @expectedException InvalidArgumentException - */ - public function shouldThrowExceptionForAssertDocForInvalidSchema($invalidSchema) - { - $constraint = new Validator(); - $constraint->assertDoc($invalidSchema, $this->validData1); - } - - public function invalidSchemaProvider() - { - return [ - [ - 'id' => [ - 'type' => 'integer' - ], - 'email' => [ - 'type' => 'email' - ], - 'is_active' => [ - 'type' => 'non_existed_data_type', - 'values' => ['0', '1'] - ] - ], - [ - 'id' => [ - 'type' => 'integer' - ], - 'email' => [ - 'type' => 'email' - ], - 'is_active' => [ - 'values' => ['0', '1'] - ] - ] - ]; - } -} diff --git a/tests/resources/config_data/empty_config_for_trait.txt b/tests/_data/.gitkeep similarity index 100% rename from tests/resources/config_data/empty_config_for_trait.txt rename to tests/_data/.gitkeep diff --git a/tests/_output/.gitkeep b/tests/_output/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/tests/_output/coverage.serialized b/tests/_output/coverage.serialized new file mode 100644 index 0000000..7805e7d --- /dev/null +++ b/tests/_output/coverage.serialized @@ -0,0 +1,287 @@ +setData(array ( + '/Volumes/MK/Projects/selamiphp/entity/src/Entity.php' => + array ( + 26 => + array ( + 0 => 'EntityTest::shouldReturnEntityObjectSuccessfully', + 1 => 'EntityTest::shouldCompareTwoEntityObjectSuccessfully', + 2 => 'EntityTest::shouldFailForRequiredInput', + ), + 27 => + array ( + 0 => 'EntityTest::shouldReturnEntityObjectSuccessfully', + 1 => 'EntityTest::shouldCompareTwoEntityObjectSuccessfully', + 2 => 'EntityTest::shouldFailForRequiredInput', + ), + 28 => + array ( + 0 => 'EntityTest::shouldReturnEntityObjectSuccessfully', + 1 => 'EntityTest::shouldCompareTwoEntityObjectSuccessfully', + 2 => 'EntityTest::shouldFailForRequiredInput', + ), + 29 => + array ( + 0 => 'EntityTest::shouldReturnEntityObjectSuccessfully', + 1 => 'EntityTest::shouldCompareTwoEntityObjectSuccessfully', + 2 => 'EntityTest::shouldFailForRequiredInput', + ), + 31 => + array ( + 0 => 'EntityTest::shouldReturnEntityObjectSuccessfully', + 1 => 'EntityTest::shouldCompareTwoEntityObjectSuccessfully', + 2 => 'EntityTest::shouldFailForRequiredInput', + ), + 32 => + array ( + 0 => 'EntityTest::shouldReturnEntityObjectSuccessfully', + 1 => 'EntityTest::shouldCompareTwoEntityObjectSuccessfully', + 2 => 'EntityTest::shouldFailForRequiredInput', + ), + 36 => + array ( + 0 => 'EntityTest::shouldReturnEntityObjectSuccessfully', + 1 => 'EntityTest::shouldCompareTwoEntityObjectSuccessfully', + 2 => 'EntityTest::shouldFailForRequiredInput', + ), + 37 => + array ( + 0 => 'EntityTest::shouldReturnEntityObjectSuccessfully', + 1 => 'EntityTest::shouldCompareTwoEntityObjectSuccessfully', + 2 => 'EntityTest::shouldFailForRequiredInput', + ), + 39 => + array ( + 0 => 'EntityTest::shouldReturnEntityObjectSuccessfully', + 1 => 'EntityTest::shouldCompareTwoEntityObjectSuccessfully', + 2 => 'EntityTest::shouldFailForRequiredInput', + ), + 43 => + array ( + 0 => 'EntityTest::shouldReturnEntityObjectSuccessfully', + 1 => 'EntityTest::shouldCompareTwoEntityObjectSuccessfully', + ), + 44 => NULL, + 48 => + array ( + 0 => 'EntityTest::shouldReturnEntityObjectSuccessfully', + 1 => 'EntityTest::shouldCompareTwoEntityObjectSuccessfully', + 2 => 'EntityTest::shouldFailForRequiredInput', + ), + 49 => + array ( + 0 => 'EntityTest::shouldReturnEntityObjectSuccessfully', + 1 => 'EntityTest::shouldCompareTwoEntityObjectSuccessfully', + 2 => 'EntityTest::shouldFailForRequiredInput', + ), + 53 => + array ( + 0 => 'EntityTest::shouldReturnEntityObjectSuccessfully', + ), + 54 => NULL, + 58 => + array ( + 0 => 'EntityTest::shouldReturnEntityObjectSuccessfully', + ), + 59 => + array ( + 0 => 'EntityTest::shouldReturnEntityObjectSuccessfully', + ), + 63 => + array ( + 0 => 'EntityTest::shouldReturnEntityObjectSuccessfully', + 1 => 'EntityTest::shouldFailForRequiredInput', + ), + 64 => + array ( + 0 => 'EntityTest::shouldReturnEntityObjectSuccessfully', + 1 => 'EntityTest::shouldFailForRequiredInput', + ), + 65 => + array ( + 0 => 'EntityTest::shouldFailForRequiredInput', + ), + 66 => + array ( + 0 => 'EntityTest::shouldFailForRequiredInput', + ), + 67 => + array ( + 0 => 'EntityTest::shouldFailForRequiredInput', + ), + 68 => + array ( + 0 => 'EntityTest::shouldFailForRequiredInput', + ), + 69 => + array ( + 0 => 'EntityTest::shouldFailForRequiredInput', + ), + 70 => + array ( + 0 => 'EntityTest::shouldFailForRequiredInput', + ), + 71 => + array ( + 0 => 'EntityTest::shouldFailForRequiredInput', + ), + 72 => + array ( + 0 => 'EntityTest::shouldFailForRequiredInput', + ), + 74 => + array ( + 0 => 'EntityTest::shouldFailForRequiredInput', + ), + 75 => + array ( + 0 => 'EntityTest::shouldFailForRequiredInput', + ), + 78 => + array ( + 0 => 'EntityTest::shouldReturnEntityObjectSuccessfully', + ), + 79 => NULL, + 83 => + array ( + 0 => 'EntityTest::shouldCompareTwoEntityObjectSuccessfully', + ), + 84 => NULL, + 88 => + array ( + 0 => 'EntityTest::shouldReturnEntityObjectSuccessfully', + 1 => 'EntityTest::shouldCompareTwoEntityObjectSuccessfully', + ), + 89 => NULL, + 93 => + array ( + 0 => 'EntityTest::shouldReturnEntityObjectSuccessfully', + 1 => 'EntityTest::shouldCompareTwoEntityObjectSuccessfully', + ), + 94 => NULL, + 98 => + array ( + 0 => 'EntityTest::shouldReturnEntityObjectSuccessfully', + 1 => 'EntityTest::shouldCompareTwoEntityObjectSuccessfully', + 2 => 'EntityTest::shouldFailForAModelFileDoesNotExist', + ), + 99 => + array ( + 0 => 'EntityTest::shouldFailForAModelFileDoesNotExist', + ), + 101 => + array ( + 0 => 'EntityTest::shouldReturnEntityObjectSuccessfully', + 1 => 'EntityTest::shouldCompareTwoEntityObjectSuccessfully', + ), + 102 => + array ( + 0 => 'EntityTest::shouldReturnEntityObjectSuccessfully', + 1 => 'EntityTest::shouldCompareTwoEntityObjectSuccessfully', + ), + 103 => NULL, + 107 => + array ( + 0 => 'EntityTest::shouldReturnEntityObjectSuccessfully', + 1 => 'EntityTest::shouldCompareTwoEntityObjectSuccessfully', + ), + 108 => NULL, + ), + '/Volumes/MK/Projects/selamiphp/entity/src/Model.php' => + array ( + 15 => + array ( + 0 => 'EntityTest::shouldReturnEntityObjectSuccessfully', + 1 => 'EntityTest::shouldCompareTwoEntityObjectSuccessfully', + 2 => 'EntityTest::shouldFailForRequiredInput', + 3 => 'ModelTest::shouldReturnModelObjectSuccessfully', + 4 => 'ModelTest::shouldFailForAFileThatContainsInvalidJson', + ), + 16 => + array ( + 0 => 'EntityTest::shouldReturnEntityObjectSuccessfully', + 1 => 'EntityTest::shouldCompareTwoEntityObjectSuccessfully', + 2 => 'EntityTest::shouldFailForRequiredInput', + 3 => 'ModelTest::shouldReturnModelObjectSuccessfully', + ), + 20 => + array ( + 0 => 'EntityTest::shouldReturnEntityObjectSuccessfully', + 1 => 'EntityTest::shouldFailForRequiredInput', + 2 => 'ModelTest::shouldReturnModelObjectSuccessfully', + ), + 21 => NULL, + 25 => + array ( + 0 => 'EntityTest::shouldFailForRequiredInput', + 1 => 'ModelTest::shouldReturnModelObjectSuccessfully', + 2 => 'ModelTest::shouldFailForAFileThatDoesNotExist', + 3 => 'ModelTest::shouldFailForAFileThatContainsInvalidJson', + ), + 26 => + array ( + 0 => 'ModelTest::shouldFailForAFileThatDoesNotExist', + ), + 28 => + array ( + 0 => 'EntityTest::shouldFailForRequiredInput', + 1 => 'ModelTest::shouldReturnModelObjectSuccessfully', + 2 => 'ModelTest::shouldFailForAFileThatContainsInvalidJson', + ), + 29 => NULL, + ), + '/Volumes/MK/Projects/selamiphp/entity/src/Exception/InvalidArgumentException.php' => + array ( + ), + '/Volumes/MK/Projects/selamiphp/entity/src/Exception/UnexpectedValueException.php' => + array ( + ), +)); +$coverage->setTests(array ( + 'EntityTest::shouldReturnEntityObjectSuccessfully' => + array ( + 'size' => 'unknown', + 'status' => 0, + ), + 'EntityTest::shouldCompareTwoEntityObjectSuccessfully' => + array ( + 'size' => 'unknown', + 'status' => 0, + ), + 'EntityTest::shouldFailForRequiredInput' => + array ( + 'size' => 'unknown', + 'status' => 0, + ), + 'EntityTest::shouldFailForAModelFileDoesNotExist' => + array ( + 'size' => 'unknown', + 'status' => 0, + ), + 'ModelTest::shouldReturnModelObjectSuccessfully' => + array ( + 'size' => 'unknown', + 'status' => 0, + ), + 'ModelTest::shouldFailForAFileThatDoesNotExist' => + array ( + 'size' => 'unknown', + 'status' => 0, + ), + 'ModelTest::shouldFailForAFileThatContainsInvalidJson' => + array ( + 'size' => 'unknown', + 'status' => 0, + ), +)); + +$filter = $coverage->filter(); +$filter->setWhitelistedFiles(array ( + '/Volumes/MK/Projects/selamiphp/entity/src/Entity.php' => true, + '/Volumes/MK/Projects/selamiphp/entity/src/Exception/InvalidArgumentException.php' => true, + '/Volumes/MK/Projects/selamiphp/entity/src/Exception/UnexpectedValueException.php' => true, + '/Volumes/MK/Projects/selamiphp/entity/src/Model.php' => true, +)); + +return $coverage; \ No newline at end of file diff --git a/tests/_support/AcceptanceTester.php b/tests/_support/AcceptanceTester.php new file mode 100644 index 0000000..4c7dcbb --- /dev/null +++ b/tests/_support/AcceptanceTester.php @@ -0,0 +1,26 @@ +getScenario()->runStep(new \Codeception\Step\Action('setHeader', func_get_args())); + } + + + /** + * [!] Method is generated. Documentation taken from corresponding module. + * + * Authenticates user for HTTP_AUTH + * + * @param $username + * @param $password + * @see \Codeception\Module\PhpBrowser::amHttpAuthenticated() + */ + public function amHttpAuthenticated($username, $password) { + return $this->getScenario()->runStep(new \Codeception\Step\Condition('amHttpAuthenticated', func_get_args())); + } + + + /** + * [!] Method is generated. Documentation taken from corresponding module. + * + * Open web page at the given absolute URL and sets its hostname as the base host. + * + * ``` php + * amOnUrl('http://codeception.com'); + * $I->amOnPage('/quickstart'); // moves to http://codeception.com/quickstart + * ?> + * ``` + * @see \Codeception\Module\PhpBrowser::amOnUrl() + */ + public function amOnUrl($url) { + return $this->getScenario()->runStep(new \Codeception\Step\Condition('amOnUrl', func_get_args())); + } + + + /** + * [!] Method is generated. Documentation taken from corresponding module. + * + * Changes the subdomain for the 'url' configuration parameter. + * Does not open a page; use `amOnPage` for that. + * + * ``` php + * amOnSubdomain('user'); + * $I->amOnPage('/'); + * // moves to http://user.mysite.com/ + * ?> + * ``` + * + * @param $subdomain + * + * @return mixed + * @see \Codeception\Module\PhpBrowser::amOnSubdomain() + */ + public function amOnSubdomain($subdomain) { + return $this->getScenario()->runStep(new \Codeception\Step\Condition('amOnSubdomain', func_get_args())); + } + + + /** + * [!] Method is generated. Documentation taken from corresponding module. + * + * Low-level API method. + * If Codeception commands are not enough, use [Guzzle HTTP Client](http://guzzlephp.org/) methods directly + * + * Example: + * + * ``` php + * executeInGuzzle(function (\GuzzleHttp\Client $client) { + * $client->get('/get', ['query' => ['foo' => 'bar']]); + * }); + * ?> + * ``` + * + * It is not recommended to use this command on a regular basis. + * If Codeception lacks important Guzzle Client methods, implement them and submit patches. + * + * @param callable $function + * @see \Codeception\Module\PhpBrowser::executeInGuzzle() + */ + public function executeInGuzzle($function) { + return $this->getScenario()->runStep(new \Codeception\Step\Action('executeInGuzzle', func_get_args())); + } + + + /** + * [!] Method is generated. Documentation taken from corresponding module. + * + * Sets the HTTP header to the passed value - which is used on + * subsequent HTTP requests through PhpBrowser. + * + * Example: + * ```php + * haveHttpHeader('X-Requested-With', 'Codeception'); + * $I->amOnPage('test-headers.php'); + * ?> + * ``` + * + * To use special chars in Header Key use HTML Character Entities: + * Example: + * Header with underscore - 'Client_Id' + * should be represented as - 'Client_Id' or 'Client_Id' + * + * ```php + * haveHttpHeader('Client_Id', 'Codeception'); + * ?> + * ``` + * + * @param string $name the name of the request header + * @param string $value the value to set it to for subsequent + * requests + * @see \Codeception\Lib\InnerBrowser::haveHttpHeader() + */ + public function haveHttpHeader($name, $value) { + return $this->getScenario()->runStep(new \Codeception\Step\Action('haveHttpHeader', func_get_args())); + } + + + /** + * [!] Method is generated. Documentation taken from corresponding module. + * + * Deletes the header with the passed name. Subsequent requests + * will not have the deleted header in its request. + * + * Example: + * ```php + * haveHttpHeader('X-Requested-With', 'Codeception'); + * $I->amOnPage('test-headers.php'); + * // ... + * $I->deleteHeader('X-Requested-With'); + * $I->amOnPage('some-other-page.php'); + * ?> + * ``` + * + * @param string $name the name of the header to delete. + * @see \Codeception\Lib\InnerBrowser::deleteHeader() + */ + public function deleteHeader($name) { + return $this->getScenario()->runStep(new \Codeception\Step\Action('deleteHeader', func_get_args())); + } + + + /** + * [!] Method is generated. Documentation taken from corresponding module. + * + * Opens the page for the given relative URI. + * + * ``` php + * amOnPage('/'); + * // opens /register page + * $I->amOnPage('/register'); + * ``` + * + * @param string $page + * @see \Codeception\Lib\InnerBrowser::amOnPage() + */ + public function amOnPage($page) { + return $this->getScenario()->runStep(new \Codeception\Step\Condition('amOnPage', func_get_args())); + } + + + /** + * [!] Method is generated. Documentation taken from corresponding module. + * + * Perform a click on a link or a button, given by a locator. + * If a fuzzy locator is given, the page will be searched for a button, link, or image matching the locator string. + * For buttons, the "value" attribute, "name" attribute, and inner text are searched. + * For links, the link text is searched. + * For images, the "alt" attribute and inner text of any parent links are searched. + * + * The second parameter is a context (CSS or XPath locator) to narrow the search. + * + * Note that if the locator matches a button of type `submit`, the form will be submitted. + * + * ``` php + * click('Logout'); + * // button of form + * $I->click('Submit'); + * // CSS button + * $I->click('#form input[type=submit]'); + * // XPath + * $I->click('//form/*[@type=submit]'); + * // link in context + * $I->click('Logout', '#nav'); + * // using strict locator + * $I->click(['link' => 'Login']); + * ?> + * ``` + * + * @param $link + * @param $context + * @see \Codeception\Lib\InnerBrowser::click() + */ + public function click($link, $context = null) { + return $this->getScenario()->runStep(new \Codeception\Step\Action('click', func_get_args())); + } + + + /** + * [!] Method is generated. Documentation taken from corresponding module. + * + * Checks that the current page contains the given string (case insensitive). + * + * You can specify a specific HTML element (via CSS or XPath) as the second + * parameter to only search within that element. + * + * ``` php + * see('Logout'); // I can suppose user is logged in + * $I->see('Sign Up', 'h1'); // I can suppose it's a signup page + * $I->see('Sign Up', '//body/h1'); // with XPath + * $I->see('Sign Up', ['css' => 'body h1']); // with strict CSS locator + * ``` + * + * Note that the search is done after stripping all HTML tags from the body, + * so `$I->see('strong')` will return true for strings like: + * + * - `

I am Stronger than thou

` + * - `` + * + * But will *not* be true for strings like: + * + * - `Home` + * - `
Home` + * - `` + * + * For checking the raw source code, use `seeInSource()`. + * + * @param string $text + * @param string $selector optional + * Conditional Assertion: Test won't be stopped on fail + * @see \Codeception\Lib\InnerBrowser::see() + */ + public function canSee($text, $selector = null) { + return $this->getScenario()->runStep(new \Codeception\Step\ConditionalAssertion('see', func_get_args())); + } + /** + * [!] Method is generated. Documentation taken from corresponding module. + * + * Checks that the current page contains the given string (case insensitive). + * + * You can specify a specific HTML element (via CSS or XPath) as the second + * parameter to only search within that element. + * + * ``` php + * see('Logout'); // I can suppose user is logged in + * $I->see('Sign Up', 'h1'); // I can suppose it's a signup page + * $I->see('Sign Up', '//body/h1'); // with XPath + * $I->see('Sign Up', ['css' => 'body h1']); // with strict CSS locator + * ``` + * + * Note that the search is done after stripping all HTML tags from the body, + * so `$I->see('strong')` will return true for strings like: + * + * - `

I am Stronger than thou

` + * - `` + * + * But will *not* be true for strings like: + * + * - `Home` + * - `
Home` + * - `` + * + * For checking the raw source code, use `seeInSource()`. + * + * @param string $text + * @param string $selector optional + * @see \Codeception\Lib\InnerBrowser::see() + */ + public function see($text, $selector = null) { + return $this->getScenario()->runStep(new \Codeception\Step\Assertion('see', func_get_args())); + } + + + /** + * [!] Method is generated. Documentation taken from corresponding module. + * + * Checks that the current page doesn't contain the text specified (case insensitive). + * Give a locator as the second parameter to match a specific region. + * + * ```php + * dontSee('Login'); // I can suppose user is already logged in + * $I->dontSee('Sign Up','h1'); // I can suppose it's not a signup page + * $I->dontSee('Sign Up','//body/h1'); // with XPath + * $I->dontSee('Sign Up', ['css' => 'body h1']); // with strict CSS locator + * ``` + * + * Note that the search is done after stripping all HTML tags from the body, + * so `$I->dontSee('strong')` will fail on strings like: + * + * - `

I am Stronger than thou

` + * - `` + * + * But will ignore strings like: + * + * - `Home` + * - `
Home` + * - `` + * + * For checking the raw source code, use `seeInSource()`. + * + * @param string $text + * @param string $selector optional + * Conditional Assertion: Test won't be stopped on fail + * @see \Codeception\Lib\InnerBrowser::dontSee() + */ + public function cantSee($text, $selector = null) { + return $this->getScenario()->runStep(new \Codeception\Step\ConditionalAssertion('dontSee', func_get_args())); + } + /** + * [!] Method is generated. Documentation taken from corresponding module. + * + * Checks that the current page doesn't contain the text specified (case insensitive). + * Give a locator as the second parameter to match a specific region. + * + * ```php + * dontSee('Login'); // I can suppose user is already logged in + * $I->dontSee('Sign Up','h1'); // I can suppose it's not a signup page + * $I->dontSee('Sign Up','//body/h1'); // with XPath + * $I->dontSee('Sign Up', ['css' => 'body h1']); // with strict CSS locator + * ``` + * + * Note that the search is done after stripping all HTML tags from the body, + * so `$I->dontSee('strong')` will fail on strings like: + * + * - `

I am Stronger than thou

` + * - `` + * + * But will ignore strings like: + * + * - `Home` + * - `
Home` + * - `` + * + * For checking the raw source code, use `seeInSource()`. + * + * @param string $text + * @param string $selector optional + * @see \Codeception\Lib\InnerBrowser::dontSee() + */ + public function dontSee($text, $selector = null) { + return $this->getScenario()->runStep(new \Codeception\Step\Assertion('dontSee', func_get_args())); + } + + + /** + * [!] Method is generated. Documentation taken from corresponding module. + * + * Checks that the current page contains the given string in its + * raw source code. + * + * ``` php + * seeInSource('

Green eggs & ham

'); + * ``` + * + * @param $raw + * Conditional Assertion: Test won't be stopped on fail + * @see \Codeception\Lib\InnerBrowser::seeInSource() + */ + public function canSeeInSource($raw) { + return $this->getScenario()->runStep(new \Codeception\Step\ConditionalAssertion('seeInSource', func_get_args())); + } + /** + * [!] Method is generated. Documentation taken from corresponding module. + * + * Checks that the current page contains the given string in its + * raw source code. + * + * ``` php + * seeInSource('

Green eggs & ham

'); + * ``` + * + * @param $raw + * @see \Codeception\Lib\InnerBrowser::seeInSource() + */ + public function seeInSource($raw) { + return $this->getScenario()->runStep(new \Codeception\Step\Assertion('seeInSource', func_get_args())); + } + + + /** + * [!] Method is generated. Documentation taken from corresponding module. + * + * Checks that the current page contains the given string in its + * raw source code. + * + * ```php + * dontSeeInSource('

Green eggs & ham

'); + * ``` + * + * @param $raw + * Conditional Assertion: Test won't be stopped on fail + * @see \Codeception\Lib\InnerBrowser::dontSeeInSource() + */ + public function cantSeeInSource($raw) { + return $this->getScenario()->runStep(new \Codeception\Step\ConditionalAssertion('dontSeeInSource', func_get_args())); + } + /** + * [!] Method is generated. Documentation taken from corresponding module. + * + * Checks that the current page contains the given string in its + * raw source code. + * + * ```php + * dontSeeInSource('

Green eggs & ham

'); + * ``` + * + * @param $raw + * @see \Codeception\Lib\InnerBrowser::dontSeeInSource() + */ + public function dontSeeInSource($raw) { + return $this->getScenario()->runStep(new \Codeception\Step\Assertion('dontSeeInSource', func_get_args())); + } + + + /** + * [!] Method is generated. Documentation taken from corresponding module. + * + * Checks that there's a link with the specified text. + * Give a full URL as the second parameter to match links with that exact URL. + * + * ``` php + * seeLink('Logout'); // matches Logout + * $I->seeLink('Logout','/logout'); // matches Logout + * ?> + * ``` + * + * @param string $text + * @param string $url optional + * Conditional Assertion: Test won't be stopped on fail + * @see \Codeception\Lib\InnerBrowser::seeLink() + */ + public function canSeeLink($text, $url = null) { + return $this->getScenario()->runStep(new \Codeception\Step\ConditionalAssertion('seeLink', func_get_args())); + } + /** + * [!] Method is generated. Documentation taken from corresponding module. + * + * Checks that there's a link with the specified text. + * Give a full URL as the second parameter to match links with that exact URL. + * + * ``` php + * seeLink('Logout'); // matches Logout + * $I->seeLink('Logout','/logout'); // matches Logout + * ?> + * ``` + * + * @param string $text + * @param string $url optional + * @see \Codeception\Lib\InnerBrowser::seeLink() + */ + public function seeLink($text, $url = null) { + return $this->getScenario()->runStep(new \Codeception\Step\Assertion('seeLink', func_get_args())); + } + + + /** + * [!] Method is generated. Documentation taken from corresponding module. + * + * Checks that the page doesn't contain a link with the given string. + * If the second parameter is given, only links with a matching "href" attribute will be checked. + * + * ``` php + * dontSeeLink('Logout'); // I suppose user is not logged in + * $I->dontSeeLink('Checkout now', '/store/cart.php'); + * ?> + * ``` + * + * @param string $text + * @param string $url optional + * Conditional Assertion: Test won't be stopped on fail + * @see \Codeception\Lib\InnerBrowser::dontSeeLink() + */ + public function cantSeeLink($text, $url = null) { + return $this->getScenario()->runStep(new \Codeception\Step\ConditionalAssertion('dontSeeLink', func_get_args())); + } + /** + * [!] Method is generated. Documentation taken from corresponding module. + * + * Checks that the page doesn't contain a link with the given string. + * If the second parameter is given, only links with a matching "href" attribute will be checked. + * + * ``` php + * dontSeeLink('Logout'); // I suppose user is not logged in + * $I->dontSeeLink('Checkout now', '/store/cart.php'); + * ?> + * ``` + * + * @param string $text + * @param string $url optional + * @see \Codeception\Lib\InnerBrowser::dontSeeLink() + */ + public function dontSeeLink($text, $url = null) { + return $this->getScenario()->runStep(new \Codeception\Step\Assertion('dontSeeLink', func_get_args())); + } + + + /** + * [!] Method is generated. Documentation taken from corresponding module. + * + * Checks that current URI contains the given string. + * + * ``` php + * seeInCurrentUrl('home'); + * // to match: /users/1 + * $I->seeInCurrentUrl('/users/'); + * ?> + * ``` + * + * @param string $uri + * Conditional Assertion: Test won't be stopped on fail + * @see \Codeception\Lib\InnerBrowser::seeInCurrentUrl() + */ + public function canSeeInCurrentUrl($uri) { + return $this->getScenario()->runStep(new \Codeception\Step\ConditionalAssertion('seeInCurrentUrl', func_get_args())); + } + /** + * [!] Method is generated. Documentation taken from corresponding module. + * + * Checks that current URI contains the given string. + * + * ``` php + * seeInCurrentUrl('home'); + * // to match: /users/1 + * $I->seeInCurrentUrl('/users/'); + * ?> + * ``` + * + * @param string $uri + * @see \Codeception\Lib\InnerBrowser::seeInCurrentUrl() + */ + public function seeInCurrentUrl($uri) { + return $this->getScenario()->runStep(new \Codeception\Step\Assertion('seeInCurrentUrl', func_get_args())); + } + + + /** + * [!] Method is generated. Documentation taken from corresponding module. + * + * Checks that the current URI doesn't contain the given string. + * + * ``` php + * dontSeeInCurrentUrl('/users/'); + * ?> + * ``` + * + * @param string $uri + * Conditional Assertion: Test won't be stopped on fail + * @see \Codeception\Lib\InnerBrowser::dontSeeInCurrentUrl() + */ + public function cantSeeInCurrentUrl($uri) { + return $this->getScenario()->runStep(new \Codeception\Step\ConditionalAssertion('dontSeeInCurrentUrl', func_get_args())); + } + /** + * [!] Method is generated. Documentation taken from corresponding module. + * + * Checks that the current URI doesn't contain the given string. + * + * ``` php + * dontSeeInCurrentUrl('/users/'); + * ?> + * ``` + * + * @param string $uri + * @see \Codeception\Lib\InnerBrowser::dontSeeInCurrentUrl() + */ + public function dontSeeInCurrentUrl($uri) { + return $this->getScenario()->runStep(new \Codeception\Step\Assertion('dontSeeInCurrentUrl', func_get_args())); + } + + + /** + * [!] Method is generated. Documentation taken from corresponding module. + * + * Checks that the current URL is equal to the given string. + * Unlike `seeInCurrentUrl`, this only matches the full URL. + * + * ``` php + * seeCurrentUrlEquals('/'); + * ?> + * ``` + * + * @param string $uri + * Conditional Assertion: Test won't be stopped on fail + * @see \Codeception\Lib\InnerBrowser::seeCurrentUrlEquals() + */ + public function canSeeCurrentUrlEquals($uri) { + return $this->getScenario()->runStep(new \Codeception\Step\ConditionalAssertion('seeCurrentUrlEquals', func_get_args())); + } + /** + * [!] Method is generated. Documentation taken from corresponding module. + * + * Checks that the current URL is equal to the given string. + * Unlike `seeInCurrentUrl`, this only matches the full URL. + * + * ``` php + * seeCurrentUrlEquals('/'); + * ?> + * ``` + * + * @param string $uri + * @see \Codeception\Lib\InnerBrowser::seeCurrentUrlEquals() + */ + public function seeCurrentUrlEquals($uri) { + return $this->getScenario()->runStep(new \Codeception\Step\Assertion('seeCurrentUrlEquals', func_get_args())); + } + + + /** + * [!] Method is generated. Documentation taken from corresponding module. + * + * Checks that the current URL doesn't equal the given string. + * Unlike `dontSeeInCurrentUrl`, this only matches the full URL. + * + * ``` php + * dontSeeCurrentUrlEquals('/'); + * ?> + * ``` + * + * @param string $uri + * Conditional Assertion: Test won't be stopped on fail + * @see \Codeception\Lib\InnerBrowser::dontSeeCurrentUrlEquals() + */ + public function cantSeeCurrentUrlEquals($uri) { + return $this->getScenario()->runStep(new \Codeception\Step\ConditionalAssertion('dontSeeCurrentUrlEquals', func_get_args())); + } + /** + * [!] Method is generated. Documentation taken from corresponding module. + * + * Checks that the current URL doesn't equal the given string. + * Unlike `dontSeeInCurrentUrl`, this only matches the full URL. + * + * ``` php + * dontSeeCurrentUrlEquals('/'); + * ?> + * ``` + * + * @param string $uri + * @see \Codeception\Lib\InnerBrowser::dontSeeCurrentUrlEquals() + */ + public function dontSeeCurrentUrlEquals($uri) { + return $this->getScenario()->runStep(new \Codeception\Step\Assertion('dontSeeCurrentUrlEquals', func_get_args())); + } + + + /** + * [!] Method is generated. Documentation taken from corresponding module. + * + * Checks that the current URL matches the given regular expression. + * + * ``` php + * seeCurrentUrlMatches('~^/users/(\d+)~'); + * ?> + * ``` + * + * @param string $uri + * Conditional Assertion: Test won't be stopped on fail + * @see \Codeception\Lib\InnerBrowser::seeCurrentUrlMatches() + */ + public function canSeeCurrentUrlMatches($uri) { + return $this->getScenario()->runStep(new \Codeception\Step\ConditionalAssertion('seeCurrentUrlMatches', func_get_args())); + } + /** + * [!] Method is generated. Documentation taken from corresponding module. + * + * Checks that the current URL matches the given regular expression. + * + * ``` php + * seeCurrentUrlMatches('~^/users/(\d+)~'); + * ?> + * ``` + * + * @param string $uri + * @see \Codeception\Lib\InnerBrowser::seeCurrentUrlMatches() + */ + public function seeCurrentUrlMatches($uri) { + return $this->getScenario()->runStep(new \Codeception\Step\Assertion('seeCurrentUrlMatches', func_get_args())); + } + + + /** + * [!] Method is generated. Documentation taken from corresponding module. + * + * Checks that current url doesn't match the given regular expression. + * + * ``` php + * dontSeeCurrentUrlMatches('~^/users/(\d+)~'); + * ?> + * ``` + * + * @param string $uri + * Conditional Assertion: Test won't be stopped on fail + * @see \Codeception\Lib\InnerBrowser::dontSeeCurrentUrlMatches() + */ + public function cantSeeCurrentUrlMatches($uri) { + return $this->getScenario()->runStep(new \Codeception\Step\ConditionalAssertion('dontSeeCurrentUrlMatches', func_get_args())); + } + /** + * [!] Method is generated. Documentation taken from corresponding module. + * + * Checks that current url doesn't match the given regular expression. + * + * ``` php + * dontSeeCurrentUrlMatches('~^/users/(\d+)~'); + * ?> + * ``` + * + * @param string $uri + * @see \Codeception\Lib\InnerBrowser::dontSeeCurrentUrlMatches() + */ + public function dontSeeCurrentUrlMatches($uri) { + return $this->getScenario()->runStep(new \Codeception\Step\Assertion('dontSeeCurrentUrlMatches', func_get_args())); + } + + + /** + * [!] Method is generated. Documentation taken from corresponding module. + * + * Executes the given regular expression against the current URI and returns the first capturing group. + * If no parameters are provided, the full URI is returned. + * + * ``` php + * grabFromCurrentUrl('~^/user/(\d+)/~'); + * $uri = $I->grabFromCurrentUrl(); + * ?> + * ``` + * + * @param string $uri optional + * + * @return mixed + * @see \Codeception\Lib\InnerBrowser::grabFromCurrentUrl() + */ + public function grabFromCurrentUrl($uri = null) { + return $this->getScenario()->runStep(new \Codeception\Step\Action('grabFromCurrentUrl', func_get_args())); + } + + + /** + * [!] Method is generated. Documentation taken from corresponding module. + * + * Checks that the specified checkbox is checked. + * + * ``` php + * seeCheckboxIsChecked('#agree'); // I suppose user agreed to terms + * $I->seeCheckboxIsChecked('#signup_form input[type=checkbox]'); // I suppose user agreed to terms, If there is only one checkbox in form. + * $I->seeCheckboxIsChecked('//form/input[@type=checkbox and @name=agree]'); + * ?> + * ``` + * + * @param $checkbox + * Conditional Assertion: Test won't be stopped on fail + * @see \Codeception\Lib\InnerBrowser::seeCheckboxIsChecked() + */ + public function canSeeCheckboxIsChecked($checkbox) { + return $this->getScenario()->runStep(new \Codeception\Step\ConditionalAssertion('seeCheckboxIsChecked', func_get_args())); + } + /** + * [!] Method is generated. Documentation taken from corresponding module. + * + * Checks that the specified checkbox is checked. + * + * ``` php + * seeCheckboxIsChecked('#agree'); // I suppose user agreed to terms + * $I->seeCheckboxIsChecked('#signup_form input[type=checkbox]'); // I suppose user agreed to terms, If there is only one checkbox in form. + * $I->seeCheckboxIsChecked('//form/input[@type=checkbox and @name=agree]'); + * ?> + * ``` + * + * @param $checkbox + * @see \Codeception\Lib\InnerBrowser::seeCheckboxIsChecked() + */ + public function seeCheckboxIsChecked($checkbox) { + return $this->getScenario()->runStep(new \Codeception\Step\Assertion('seeCheckboxIsChecked', func_get_args())); + } + + + /** + * [!] Method is generated. Documentation taken from corresponding module. + * + * Check that the specified checkbox is unchecked. + * + * ``` php + * dontSeeCheckboxIsChecked('#agree'); // I suppose user didn't agree to terms + * $I->seeCheckboxIsChecked('#signup_form input[type=checkbox]'); // I suppose user didn't check the first checkbox in form. + * ?> + * ``` + * + * @param $checkbox + * Conditional Assertion: Test won't be stopped on fail + * @see \Codeception\Lib\InnerBrowser::dontSeeCheckboxIsChecked() + */ + public function cantSeeCheckboxIsChecked($checkbox) { + return $this->getScenario()->runStep(new \Codeception\Step\ConditionalAssertion('dontSeeCheckboxIsChecked', func_get_args())); + } + /** + * [!] Method is generated. Documentation taken from corresponding module. + * + * Check that the specified checkbox is unchecked. + * + * ``` php + * dontSeeCheckboxIsChecked('#agree'); // I suppose user didn't agree to terms + * $I->seeCheckboxIsChecked('#signup_form input[type=checkbox]'); // I suppose user didn't check the first checkbox in form. + * ?> + * ``` + * + * @param $checkbox + * @see \Codeception\Lib\InnerBrowser::dontSeeCheckboxIsChecked() + */ + public function dontSeeCheckboxIsChecked($checkbox) { + return $this->getScenario()->runStep(new \Codeception\Step\Assertion('dontSeeCheckboxIsChecked', func_get_args())); + } + + + /** + * [!] Method is generated. Documentation taken from corresponding module. + * + * Checks that the given input field or textarea *equals* (i.e. not just contains) the given value. + * Fields are matched by label text, the "name" attribute, CSS, or XPath. + * + * ``` php + * seeInField('Body','Type your comment here'); + * $I->seeInField('form textarea[name=body]','Type your comment here'); + * $I->seeInField('form input[type=hidden]','hidden_value'); + * $I->seeInField('#searchform input','Search'); + * $I->seeInField('//form/*[@name=search]','Search'); + * $I->seeInField(['name' => 'search'], 'Search'); + * ?> + * ``` + * + * @param $field + * @param $value + * Conditional Assertion: Test won't be stopped on fail + * @see \Codeception\Lib\InnerBrowser::seeInField() + */ + public function canSeeInField($field, $value) { + return $this->getScenario()->runStep(new \Codeception\Step\ConditionalAssertion('seeInField', func_get_args())); + } + /** + * [!] Method is generated. Documentation taken from corresponding module. + * + * Checks that the given input field or textarea *equals* (i.e. not just contains) the given value. + * Fields are matched by label text, the "name" attribute, CSS, or XPath. + * + * ``` php + * seeInField('Body','Type your comment here'); + * $I->seeInField('form textarea[name=body]','Type your comment here'); + * $I->seeInField('form input[type=hidden]','hidden_value'); + * $I->seeInField('#searchform input','Search'); + * $I->seeInField('//form/*[@name=search]','Search'); + * $I->seeInField(['name' => 'search'], 'Search'); + * ?> + * ``` + * + * @param $field + * @param $value + * @see \Codeception\Lib\InnerBrowser::seeInField() + */ + public function seeInField($field, $value) { + return $this->getScenario()->runStep(new \Codeception\Step\Assertion('seeInField', func_get_args())); + } + + + /** + * [!] Method is generated. Documentation taken from corresponding module. + * + * Checks that an input field or textarea doesn't contain the given value. + * For fuzzy locators, the field is matched by label text, CSS and XPath. + * + * ``` php + * dontSeeInField('Body','Type your comment here'); + * $I->dontSeeInField('form textarea[name=body]','Type your comment here'); + * $I->dontSeeInField('form input[type=hidden]','hidden_value'); + * $I->dontSeeInField('#searchform input','Search'); + * $I->dontSeeInField('//form/*[@name=search]','Search'); + * $I->dontSeeInField(['name' => 'search'], 'Search'); + * ?> + * ``` + * + * @param $field + * @param $value + * Conditional Assertion: Test won't be stopped on fail + * @see \Codeception\Lib\InnerBrowser::dontSeeInField() + */ + public function cantSeeInField($field, $value) { + return $this->getScenario()->runStep(new \Codeception\Step\ConditionalAssertion('dontSeeInField', func_get_args())); + } + /** + * [!] Method is generated. Documentation taken from corresponding module. + * + * Checks that an input field or textarea doesn't contain the given value. + * For fuzzy locators, the field is matched by label text, CSS and XPath. + * + * ``` php + * dontSeeInField('Body','Type your comment here'); + * $I->dontSeeInField('form textarea[name=body]','Type your comment here'); + * $I->dontSeeInField('form input[type=hidden]','hidden_value'); + * $I->dontSeeInField('#searchform input','Search'); + * $I->dontSeeInField('//form/*[@name=search]','Search'); + * $I->dontSeeInField(['name' => 'search'], 'Search'); + * ?> + * ``` + * + * @param $field + * @param $value + * @see \Codeception\Lib\InnerBrowser::dontSeeInField() + */ + public function dontSeeInField($field, $value) { + return $this->getScenario()->runStep(new \Codeception\Step\Assertion('dontSeeInField', func_get_args())); + } + + + /** + * [!] Method is generated. Documentation taken from corresponding module. + * + * Checks if the array of form parameters (name => value) are set on the form matched with the + * passed selector. + * + * ``` php + * seeInFormFields('form[name=myform]', [ + * 'input1' => 'value', + * 'input2' => 'other value', + * ]); + * ?> + * ``` + * + * For multi-select elements, or to check values of multiple elements with the same name, an + * array may be passed: + * + * ``` php + * seeInFormFields('.form-class', [ + * 'multiselect' => [ + * 'value1', + * 'value2', + * ], + * 'checkbox[]' => [ + * 'a checked value', + * 'another checked value', + * ], + * ]); + * ?> + * ``` + * + * Additionally, checkbox values can be checked with a boolean. + * + * ``` php + * seeInFormFields('#form-id', [ + * 'checkbox1' => true, // passes if checked + * 'checkbox2' => false, // passes if unchecked + * ]); + * ?> + * ``` + * + * Pair this with submitForm for quick testing magic. + * + * ``` php + * 'value', + * 'field2' => 'another value', + * 'checkbox1' => true, + * // ... + * ]; + * $I->submitForm('//form[@id=my-form]', $form, 'submitButton'); + * // $I->amOnPage('/path/to/form-page') may be needed + * $I->seeInFormFields('//form[@id=my-form]', $form); + * ?> + * ``` + * + * @param $formSelector + * @param $params + * Conditional Assertion: Test won't be stopped on fail + * @see \Codeception\Lib\InnerBrowser::seeInFormFields() + */ + public function canSeeInFormFields($formSelector, $params) { + return $this->getScenario()->runStep(new \Codeception\Step\ConditionalAssertion('seeInFormFields', func_get_args())); + } + /** + * [!] Method is generated. Documentation taken from corresponding module. + * + * Checks if the array of form parameters (name => value) are set on the form matched with the + * passed selector. + * + * ``` php + * seeInFormFields('form[name=myform]', [ + * 'input1' => 'value', + * 'input2' => 'other value', + * ]); + * ?> + * ``` + * + * For multi-select elements, or to check values of multiple elements with the same name, an + * array may be passed: + * + * ``` php + * seeInFormFields('.form-class', [ + * 'multiselect' => [ + * 'value1', + * 'value2', + * ], + * 'checkbox[]' => [ + * 'a checked value', + * 'another checked value', + * ], + * ]); + * ?> + * ``` + * + * Additionally, checkbox values can be checked with a boolean. + * + * ``` php + * seeInFormFields('#form-id', [ + * 'checkbox1' => true, // passes if checked + * 'checkbox2' => false, // passes if unchecked + * ]); + * ?> + * ``` + * + * Pair this with submitForm for quick testing magic. + * + * ``` php + * 'value', + * 'field2' => 'another value', + * 'checkbox1' => true, + * // ... + * ]; + * $I->submitForm('//form[@id=my-form]', $form, 'submitButton'); + * // $I->amOnPage('/path/to/form-page') may be needed + * $I->seeInFormFields('//form[@id=my-form]', $form); + * ?> + * ``` + * + * @param $formSelector + * @param $params + * @see \Codeception\Lib\InnerBrowser::seeInFormFields() + */ + public function seeInFormFields($formSelector, $params) { + return $this->getScenario()->runStep(new \Codeception\Step\Assertion('seeInFormFields', func_get_args())); + } + + + /** + * [!] Method is generated. Documentation taken from corresponding module. + * + * Checks if the array of form parameters (name => value) are not set on the form matched with + * the passed selector. + * + * ``` php + * dontSeeInFormFields('form[name=myform]', [ + * 'input1' => 'non-existent value', + * 'input2' => 'other non-existent value', + * ]); + * ?> + * ``` + * + * To check that an element hasn't been assigned any one of many values, an array can be passed + * as the value: + * + * ``` php + * dontSeeInFormFields('.form-class', [ + * 'fieldName' => [ + * 'This value shouldn\'t be set', + * 'And this value shouldn\'t be set', + * ], + * ]); + * ?> + * ``` + * + * Additionally, checkbox values can be checked with a boolean. + * + * ``` php + * dontSeeInFormFields('#form-id', [ + * 'checkbox1' => true, // fails if checked + * 'checkbox2' => false, // fails if unchecked + * ]); + * ?> + * ``` + * + * @param $formSelector + * @param $params + * Conditional Assertion: Test won't be stopped on fail + * @see \Codeception\Lib\InnerBrowser::dontSeeInFormFields() + */ + public function cantSeeInFormFields($formSelector, $params) { + return $this->getScenario()->runStep(new \Codeception\Step\ConditionalAssertion('dontSeeInFormFields', func_get_args())); + } + /** + * [!] Method is generated. Documentation taken from corresponding module. + * + * Checks if the array of form parameters (name => value) are not set on the form matched with + * the passed selector. + * + * ``` php + * dontSeeInFormFields('form[name=myform]', [ + * 'input1' => 'non-existent value', + * 'input2' => 'other non-existent value', + * ]); + * ?> + * ``` + * + * To check that an element hasn't been assigned any one of many values, an array can be passed + * as the value: + * + * ``` php + * dontSeeInFormFields('.form-class', [ + * 'fieldName' => [ + * 'This value shouldn\'t be set', + * 'And this value shouldn\'t be set', + * ], + * ]); + * ?> + * ``` + * + * Additionally, checkbox values can be checked with a boolean. + * + * ``` php + * dontSeeInFormFields('#form-id', [ + * 'checkbox1' => true, // fails if checked + * 'checkbox2' => false, // fails if unchecked + * ]); + * ?> + * ``` + * + * @param $formSelector + * @param $params + * @see \Codeception\Lib\InnerBrowser::dontSeeInFormFields() + */ + public function dontSeeInFormFields($formSelector, $params) { + return $this->getScenario()->runStep(new \Codeception\Step\Assertion('dontSeeInFormFields', func_get_args())); + } + + + /** + * [!] Method is generated. Documentation taken from corresponding module. + * + * Submits the given form on the page, with the given form + * values. Pass the form field's values as an array in the second + * parameter. + * + * Although this function can be used as a short-hand version of + * `fillField()`, `selectOption()`, `click()` etc. it has some important + * differences: + * + * * Only field *names* may be used, not CSS/XPath selectors nor field labels + * * If a field is sent to this function that does *not* exist on the page, + * it will silently be added to the HTTP request. This is helpful for testing + * some types of forms, but be aware that you will *not* get an exception + * like you would if you called `fillField()` or `selectOption()` with + * a missing field. + * + * Fields that are not provided will be filled by their values from the page, + * or from any previous calls to `fillField()`, `selectOption()` etc. + * You don't need to click the 'Submit' button afterwards. + * This command itself triggers the request to form's action. + * + * You can optionally specify which button's value to include + * in the request with the last parameter (as an alternative to + * explicitly setting its value in the second parameter), as + * button values are not otherwise included in the request. + * + * Examples: + * + * ``` php + * submitForm('#login', [ + * 'login' => 'davert', + * 'password' => '123456' + * ]); + * // or + * $I->submitForm('#login', [ + * 'login' => 'davert', + * 'password' => '123456' + * ], 'submitButtonName'); + * + * ``` + * + * For example, given this sample "Sign Up" form: + * + * ``` html + *
+ * Login: + *
+ * Password: + *
+ * Do you agree to our terms? + *
+ * Select pricing plan: + * + * + *
+ * ``` + * + * You could write the following to submit it: + * + * ``` php + * submitForm( + * '#userForm', + * [ + * 'user' => [ + * 'login' => 'Davert', + * 'password' => '123456', + * 'agree' => true + * ] + * ], + * 'submitButton' + * ); + * ``` + * Note that "2" will be the submitted value for the "plan" field, as it is + * the selected option. + * + * You can also emulate a JavaScript submission by not specifying any + * buttons in the third parameter to submitForm. + * + * ```php + * submitForm( + * '#userForm', + * [ + * 'user' => [ + * 'login' => 'Davert', + * 'password' => '123456', + * 'agree' => true + * ] + * ] + * ); + * ``` + * + * This function works well when paired with `seeInFormFields()` + * for quickly testing CRUD interfaces and form validation logic. + * + * ``` php + * 'value', + * 'field2' => 'another value', + * 'checkbox1' => true, + * // ... + * ]; + * $I->submitForm('#my-form', $form, 'submitButton'); + * // $I->amOnPage('/path/to/form-page') may be needed + * $I->seeInFormFields('#my-form', $form); + * ``` + * + * Parameter values can be set to arrays for multiple input fields + * of the same name, or multi-select combo boxes. For checkboxes, + * you can use either the string value or boolean `true`/`false` which will + * be replaced by the checkbox's value in the DOM. + * + * ``` php + * submitForm('#my-form', [ + * 'field1' => 'value', + * 'checkbox' => [ + * 'value of first checkbox', + * 'value of second checkbox', + * ], + * 'otherCheckboxes' => [ + * true, + * false, + * false + * ], + * 'multiselect' => [ + * 'first option value', + * 'second option value' + * ] + * ]); + * ``` + * + * Mixing string and boolean values for a checkbox's value is not supported + * and may produce unexpected results. + * + * Field names ending in `[]` must be passed without the trailing square + * bracket characters, and must contain an array for its value. This allows + * submitting multiple values with the same name, consider: + * + * ```php + * submitForm('#my-form', [ + * 'field[]' => 'value', + * 'field[]' => 'another value', // 'field[]' is already a defined key + * ]); + * ``` + * + * The solution is to pass an array value: + * + * ```php + * submitForm('#my-form', [ + * 'field' => [ + * 'value', + * 'another value', + * ] + * ]); + * ``` + * + * @param $selector + * @param $params + * @param $button + * @see \Codeception\Lib\InnerBrowser::submitForm() + */ + public function submitForm($selector, $params, $button = null) { + return $this->getScenario()->runStep(new \Codeception\Step\Action('submitForm', func_get_args())); + } + + + /** + * [!] Method is generated. Documentation taken from corresponding module. + * + * Fills a text field or textarea with the given string. + * + * ``` php + * fillField("//input[@type='text']", "Hello World!"); + * $I->fillField(['name' => 'email'], 'jon@mail.com'); + * ?> + * ``` + * + * @param $field + * @param $value + * @see \Codeception\Lib\InnerBrowser::fillField() + */ + public function fillField($field, $value) { + return $this->getScenario()->runStep(new \Codeception\Step\Action('fillField', func_get_args())); + } + + + /** + * [!] Method is generated. Documentation taken from corresponding module. + * + * Selects an option in a select tag or in radio button group. + * + * ``` php + * selectOption('form select[name=account]', 'Premium'); + * $I->selectOption('form input[name=payment]', 'Monthly'); + * $I->selectOption('//form/select[@name=account]', 'Monthly'); + * ?> + * ``` + * + * Provide an array for the second argument to select multiple options: + * + * ``` php + * selectOption('Which OS do you use?', array('Windows','Linux')); + * ?> + * ``` + * + * Or provide an associative array for the second argument to specifically define which selection method should be used: + * + * ``` php + * selectOption('Which OS do you use?', array('text' => 'Windows')); // Only search by text 'Windows' + * $I->selectOption('Which OS do you use?', array('value' => 'windows')); // Only search by value 'windows' + * ?> + * ``` + * + * @param $select + * @param $option + * @see \Codeception\Lib\InnerBrowser::selectOption() + */ + public function selectOption($select, $option) { + return $this->getScenario()->runStep(new \Codeception\Step\Action('selectOption', func_get_args())); + } + + + /** + * [!] Method is generated. Documentation taken from corresponding module. + * + * Ticks a checkbox. For radio buttons, use the `selectOption` method instead. + * + * ``` php + * checkOption('#agree'); + * ?> + * ``` + * + * @param $option + * @see \Codeception\Lib\InnerBrowser::checkOption() + */ + public function checkOption($option) { + return $this->getScenario()->runStep(new \Codeception\Step\Action('checkOption', func_get_args())); + } + + + /** + * [!] Method is generated. Documentation taken from corresponding module. + * + * Unticks a checkbox. + * + * ``` php + * uncheckOption('#notify'); + * ?> + * ``` + * + * @param $option + * @see \Codeception\Lib\InnerBrowser::uncheckOption() + */ + public function uncheckOption($option) { + return $this->getScenario()->runStep(new \Codeception\Step\Action('uncheckOption', func_get_args())); + } + + + /** + * [!] Method is generated. Documentation taken from corresponding module. + * + * Attaches a file relative to the Codeception `_data` directory to the given file upload field. + * + * ``` php + * attachFile('input[@type="file"]', 'prices.xls'); + * ?> + * ``` + * + * @param $field + * @param $filename + * @see \Codeception\Lib\InnerBrowser::attachFile() + */ + public function attachFile($field, $filename) { + return $this->getScenario()->runStep(new \Codeception\Step\Action('attachFile', func_get_args())); + } + + + /** + * [!] Method is generated. Documentation taken from corresponding module. + * + * If your page triggers an ajax request, you can perform it manually. + * This action sends a GET ajax request with specified params. + * + * See ->sendAjaxPostRequest for examples. + * + * @param $uri + * @param $params + * @see \Codeception\Lib\InnerBrowser::sendAjaxGetRequest() + */ + public function sendAjaxGetRequest($uri, $params = null) { + return $this->getScenario()->runStep(new \Codeception\Step\Action('sendAjaxGetRequest', func_get_args())); + } + + + /** + * [!] Method is generated. Documentation taken from corresponding module. + * + * If your page triggers an ajax request, you can perform it manually. + * This action sends a POST ajax request with specified params. + * Additional params can be passed as array. + * + * Example: + * + * Imagine that by clicking checkbox you trigger ajax request which updates user settings. + * We emulate that click by running this ajax request manually. + * + * ``` php + * sendAjaxPostRequest('/updateSettings', array('notifications' => true)); // POST + * $I->sendAjaxGetRequest('/updateSettings', array('notifications' => true)); // GET + * + * ``` + * + * @param $uri + * @param $params + * @see \Codeception\Lib\InnerBrowser::sendAjaxPostRequest() + */ + public function sendAjaxPostRequest($uri, $params = null) { + return $this->getScenario()->runStep(new \Codeception\Step\Action('sendAjaxPostRequest', func_get_args())); + } + + + /** + * [!] Method is generated. Documentation taken from corresponding module. + * + * If your page triggers an ajax request, you can perform it manually. + * This action sends an ajax request with specified method and params. + * + * Example: + * + * You need to perform an ajax request specifying the HTTP method. + * + * ``` php + * sendAjaxRequest('PUT', '/posts/7', array('title' => 'new title')); + * + * ``` + * + * @param $method + * @param $uri + * @param $params + * @see \Codeception\Lib\InnerBrowser::sendAjaxRequest() + */ + public function sendAjaxRequest($method, $uri, $params = null) { + return $this->getScenario()->runStep(new \Codeception\Step\Action('sendAjaxRequest', func_get_args())); + } + + + /** + * [!] Method is generated. Documentation taken from corresponding module. + * + * Finds and returns the text contents of the given element. + * If a fuzzy locator is used, the element is found using CSS, XPath, + * and by matching the full page source by regular expression. + * + * ``` php + * grabTextFrom('h1'); + * $heading = $I->grabTextFrom('descendant-or-self::h1'); + * $value = $I->grabTextFrom('~ + * ``` + * + * @param $cssOrXPathOrRegex + * + * @return mixed + * @see \Codeception\Lib\InnerBrowser::grabTextFrom() + */ + public function grabTextFrom($cssOrXPathOrRegex) { + return $this->getScenario()->runStep(new \Codeception\Step\Action('grabTextFrom', func_get_args())); + } + + + /** + * [!] Method is generated. Documentation taken from corresponding module. + * + * Grabs the value of the given attribute value from the given element. + * Fails if element is not found. + * + * ``` php + * grabAttributeFrom('#tooltip', 'title'); + * ?> + * ``` + * + * + * @param $cssOrXpath + * @param $attribute + * + * @return mixed + * @see \Codeception\Lib\InnerBrowser::grabAttributeFrom() + */ + public function grabAttributeFrom($cssOrXpath, $attribute) { + return $this->getScenario()->runStep(new \Codeception\Step\Action('grabAttributeFrom', func_get_args())); + } + + + /** + * [!] Method is generated. Documentation taken from corresponding module. + * + * Grabs either the text content, or attribute values, of nodes + * matched by $cssOrXpath and returns them as an array. + * + * ```html + * First + * Second + * Third + * ``` + * + * ```php + * grabMultiple('a'); + * + * // would return ['#first', '#second', '#third'] + * $aLinks = $I->grabMultiple('a', 'href'); + * ?> + * ``` + * + * @param $cssOrXpath + * @param $attribute + * @return string[] + * @see \Codeception\Lib\InnerBrowser::grabMultiple() + */ + public function grabMultiple($cssOrXpath, $attribute = null) { + return $this->getScenario()->runStep(new \Codeception\Step\Action('grabMultiple', func_get_args())); + } + + + /** + * [!] Method is generated. Documentation taken from corresponding module. + * + * @param $field + * + * @return array|mixed|null|string + * @see \Codeception\Lib\InnerBrowser::grabValueFrom() + */ + public function grabValueFrom($field) { + return $this->getScenario()->runStep(new \Codeception\Step\Action('grabValueFrom', func_get_args())); + } + + + /** + * [!] Method is generated. Documentation taken from corresponding module. + * + * Sets a cookie with the given name and value. + * You can set additional cookie params like `domain`, `path`, `expires`, `secure` in array passed as last argument. + * + * ``` php + * setCookie('PHPSESSID', 'el4ukv0kqbvoirg7nkp4dncpk3'); + * ?> + * ``` + * + * @param $name + * @param $val + * @param array $params + * + * @return mixed + * @see \Codeception\Lib\InnerBrowser::setCookie() + */ + public function setCookie($name, $val, $params = null) { + return $this->getScenario()->runStep(new \Codeception\Step\Action('setCookie', func_get_args())); + } + + + /** + * [!] Method is generated. Documentation taken from corresponding module. + * + * Grabs a cookie value. + * You can set additional cookie params like `domain`, `path` in array passed as last argument. + * + * @param $cookie + * + * @param array $params + * @return mixed + * @see \Codeception\Lib\InnerBrowser::grabCookie() + */ + public function grabCookie($cookie, $params = null) { + return $this->getScenario()->runStep(new \Codeception\Step\Action('grabCookie', func_get_args())); + } + + + /** + * [!] Method is generated. Documentation taken from corresponding module. + * + * Grabs current page source code. + * + * @throws ModuleException if no page was opened. + * + * @return string Current page source code. + * @see \Codeception\Lib\InnerBrowser::grabPageSource() + */ + public function grabPageSource() { + return $this->getScenario()->runStep(new \Codeception\Step\Action('grabPageSource', func_get_args())); + } + + + /** + * [!] Method is generated. Documentation taken from corresponding module. + * + * Checks that a cookie with the given name is set. + * You can set additional cookie params like `domain`, `path` as array passed in last argument. + * + * ``` php + * seeCookie('PHPSESSID'); + * ?> + * ``` + * + * @param $cookie + * @param array $params + * @return mixed + * Conditional Assertion: Test won't be stopped on fail + * @see \Codeception\Lib\InnerBrowser::seeCookie() + */ + public function canSeeCookie($cookie, $params = null) { + return $this->getScenario()->runStep(new \Codeception\Step\ConditionalAssertion('seeCookie', func_get_args())); + } + /** + * [!] Method is generated. Documentation taken from corresponding module. + * + * Checks that a cookie with the given name is set. + * You can set additional cookie params like `domain`, `path` as array passed in last argument. + * + * ``` php + * seeCookie('PHPSESSID'); + * ?> + * ``` + * + * @param $cookie + * @param array $params + * @return mixed + * @see \Codeception\Lib\InnerBrowser::seeCookie() + */ + public function seeCookie($cookie, $params = null) { + return $this->getScenario()->runStep(new \Codeception\Step\Assertion('seeCookie', func_get_args())); + } + + + /** + * [!] Method is generated. Documentation taken from corresponding module. + * + * Checks that there isn't a cookie with the given name. + * You can set additional cookie params like `domain`, `path` as array passed in last argument. + * + * @param $cookie + * + * @param array $params + * @return mixed + * Conditional Assertion: Test won't be stopped on fail + * @see \Codeception\Lib\InnerBrowser::dontSeeCookie() + */ + public function cantSeeCookie($cookie, $params = null) { + return $this->getScenario()->runStep(new \Codeception\Step\ConditionalAssertion('dontSeeCookie', func_get_args())); + } + /** + * [!] Method is generated. Documentation taken from corresponding module. + * + * Checks that there isn't a cookie with the given name. + * You can set additional cookie params like `domain`, `path` as array passed in last argument. + * + * @param $cookie + * + * @param array $params + * @return mixed + * @see \Codeception\Lib\InnerBrowser::dontSeeCookie() + */ + public function dontSeeCookie($cookie, $params = null) { + return $this->getScenario()->runStep(new \Codeception\Step\Assertion('dontSeeCookie', func_get_args())); + } + + + /** + * [!] Method is generated. Documentation taken from corresponding module. + * + * Unsets cookie with the given name. + * You can set additional cookie params like `domain`, `path` in array passed as last argument. + * + * @param $cookie + * + * @param array $params + * @return mixed + * @see \Codeception\Lib\InnerBrowser::resetCookie() + */ + public function resetCookie($name, $params = null) { + return $this->getScenario()->runStep(new \Codeception\Step\Action('resetCookie', func_get_args())); + } + + + /** + * [!] Method is generated. Documentation taken from corresponding module. + * + * Checks that the given element exists on the page and is visible. + * You can also specify expected attributes of this element. + * + * ``` php + * seeElement('.error'); + * $I->seeElement('//form/input[1]'); + * $I->seeElement('input', ['name' => 'login']); + * $I->seeElement('input', ['value' => '123456']); + * + * // strict locator in first arg, attributes in second + * $I->seeElement(['css' => 'form input'], ['name' => 'login']); + * ?> + * ``` + * + * @param $selector + * @param array $attributes + * @return + * Conditional Assertion: Test won't be stopped on fail + * @see \Codeception\Lib\InnerBrowser::seeElement() + */ + public function canSeeElement($selector, $attributes = null) { + return $this->getScenario()->runStep(new \Codeception\Step\ConditionalAssertion('seeElement', func_get_args())); + } + /** + * [!] Method is generated. Documentation taken from corresponding module. + * + * Checks that the given element exists on the page and is visible. + * You can also specify expected attributes of this element. + * + * ``` php + * seeElement('.error'); + * $I->seeElement('//form/input[1]'); + * $I->seeElement('input', ['name' => 'login']); + * $I->seeElement('input', ['value' => '123456']); + * + * // strict locator in first arg, attributes in second + * $I->seeElement(['css' => 'form input'], ['name' => 'login']); + * ?> + * ``` + * + * @param $selector + * @param array $attributes + * @return + * @see \Codeception\Lib\InnerBrowser::seeElement() + */ + public function seeElement($selector, $attributes = null) { + return $this->getScenario()->runStep(new \Codeception\Step\Assertion('seeElement', func_get_args())); + } + + + /** + * [!] Method is generated. Documentation taken from corresponding module. + * + * Checks that the given element is invisible or not present on the page. + * You can also specify expected attributes of this element. + * + * ``` php + * dontSeeElement('.error'); + * $I->dontSeeElement('//form/input[1]'); + * $I->dontSeeElement('input', ['name' => 'login']); + * $I->dontSeeElement('input', ['value' => '123456']); + * ?> + * ``` + * + * @param $selector + * @param array $attributes + * Conditional Assertion: Test won't be stopped on fail + * @see \Codeception\Lib\InnerBrowser::dontSeeElement() + */ + public function cantSeeElement($selector, $attributes = null) { + return $this->getScenario()->runStep(new \Codeception\Step\ConditionalAssertion('dontSeeElement', func_get_args())); + } + /** + * [!] Method is generated. Documentation taken from corresponding module. + * + * Checks that the given element is invisible or not present on the page. + * You can also specify expected attributes of this element. + * + * ``` php + * dontSeeElement('.error'); + * $I->dontSeeElement('//form/input[1]'); + * $I->dontSeeElement('input', ['name' => 'login']); + * $I->dontSeeElement('input', ['value' => '123456']); + * ?> + * ``` + * + * @param $selector + * @param array $attributes + * @see \Codeception\Lib\InnerBrowser::dontSeeElement() + */ + public function dontSeeElement($selector, $attributes = null) { + return $this->getScenario()->runStep(new \Codeception\Step\Assertion('dontSeeElement', func_get_args())); + } + + + /** + * [!] Method is generated. Documentation taken from corresponding module. + * + * Checks that there are a certain number of elements matched by the given locator on the page. + * + * ``` php + * seeNumberOfElements('tr', 10); + * $I->seeNumberOfElements('tr', [0,10]); // between 0 and 10 elements + * ?> + * ``` + * @param $selector + * @param mixed $expected int or int[] + * Conditional Assertion: Test won't be stopped on fail + * @see \Codeception\Lib\InnerBrowser::seeNumberOfElements() + */ + public function canSeeNumberOfElements($selector, $expected) { + return $this->getScenario()->runStep(new \Codeception\Step\ConditionalAssertion('seeNumberOfElements', func_get_args())); + } + /** + * [!] Method is generated. Documentation taken from corresponding module. + * + * Checks that there are a certain number of elements matched by the given locator on the page. + * + * ``` php + * seeNumberOfElements('tr', 10); + * $I->seeNumberOfElements('tr', [0,10]); // between 0 and 10 elements + * ?> + * ``` + * @param $selector + * @param mixed $expected int or int[] + * @see \Codeception\Lib\InnerBrowser::seeNumberOfElements() + */ + public function seeNumberOfElements($selector, $expected) { + return $this->getScenario()->runStep(new \Codeception\Step\Assertion('seeNumberOfElements', func_get_args())); + } + + + /** + * [!] Method is generated. Documentation taken from corresponding module. + * + * Checks that the given option is selected. + * + * ``` php + * seeOptionIsSelected('#form input[name=payment]', 'Visa'); + * ?> + * ``` + * + * @param $selector + * @param $optionText + * + * @return mixed + * Conditional Assertion: Test won't be stopped on fail + * @see \Codeception\Lib\InnerBrowser::seeOptionIsSelected() + */ + public function canSeeOptionIsSelected($selector, $optionText) { + return $this->getScenario()->runStep(new \Codeception\Step\ConditionalAssertion('seeOptionIsSelected', func_get_args())); + } + /** + * [!] Method is generated. Documentation taken from corresponding module. + * + * Checks that the given option is selected. + * + * ``` php + * seeOptionIsSelected('#form input[name=payment]', 'Visa'); + * ?> + * ``` + * + * @param $selector + * @param $optionText + * + * @return mixed + * @see \Codeception\Lib\InnerBrowser::seeOptionIsSelected() + */ + public function seeOptionIsSelected($selector, $optionText) { + return $this->getScenario()->runStep(new \Codeception\Step\Assertion('seeOptionIsSelected', func_get_args())); + } + + + /** + * [!] Method is generated. Documentation taken from corresponding module. + * + * Checks that the given option is not selected. + * + * ``` php + * dontSeeOptionIsSelected('#form input[name=payment]', 'Visa'); + * ?> + * ``` + * + * @param $selector + * @param $optionText + * + * @return mixed + * Conditional Assertion: Test won't be stopped on fail + * @see \Codeception\Lib\InnerBrowser::dontSeeOptionIsSelected() + */ + public function cantSeeOptionIsSelected($selector, $optionText) { + return $this->getScenario()->runStep(new \Codeception\Step\ConditionalAssertion('dontSeeOptionIsSelected', func_get_args())); + } + /** + * [!] Method is generated. Documentation taken from corresponding module. + * + * Checks that the given option is not selected. + * + * ``` php + * dontSeeOptionIsSelected('#form input[name=payment]', 'Visa'); + * ?> + * ``` + * + * @param $selector + * @param $optionText + * + * @return mixed + * @see \Codeception\Lib\InnerBrowser::dontSeeOptionIsSelected() + */ + public function dontSeeOptionIsSelected($selector, $optionText) { + return $this->getScenario()->runStep(new \Codeception\Step\Assertion('dontSeeOptionIsSelected', func_get_args())); + } + + + /** + * [!] Method is generated. Documentation taken from corresponding module. + * + * Asserts that current page has 404 response status code. + * Conditional Assertion: Test won't be stopped on fail + * @see \Codeception\Lib\InnerBrowser::seePageNotFound() + */ + public function canSeePageNotFound() { + return $this->getScenario()->runStep(new \Codeception\Step\ConditionalAssertion('seePageNotFound', func_get_args())); + } + /** + * [!] Method is generated. Documentation taken from corresponding module. + * + * Asserts that current page has 404 response status code. + * @see \Codeception\Lib\InnerBrowser::seePageNotFound() + */ + public function seePageNotFound() { + return $this->getScenario()->runStep(new \Codeception\Step\Assertion('seePageNotFound', func_get_args())); + } + + + /** + * [!] Method is generated. Documentation taken from corresponding module. + * + * Checks that response code is equal to value provided. + * + * ```php + * seeResponseCodeIs(200); + * + * // recommended \Codeception\Util\HttpCode + * $I->seeResponseCodeIs(\Codeception\Util\HttpCode::OK); + * ``` + * + * @param $code + * Conditional Assertion: Test won't be stopped on fail + * @see \Codeception\Lib\InnerBrowser::seeResponseCodeIs() + */ + public function canSeeResponseCodeIs($code) { + return $this->getScenario()->runStep(new \Codeception\Step\ConditionalAssertion('seeResponseCodeIs', func_get_args())); + } + /** + * [!] Method is generated. Documentation taken from corresponding module. + * + * Checks that response code is equal to value provided. + * + * ```php + * seeResponseCodeIs(200); + * + * // recommended \Codeception\Util\HttpCode + * $I->seeResponseCodeIs(\Codeception\Util\HttpCode::OK); + * ``` + * + * @param $code + * @see \Codeception\Lib\InnerBrowser::seeResponseCodeIs() + */ + public function seeResponseCodeIs($code) { + return $this->getScenario()->runStep(new \Codeception\Step\Assertion('seeResponseCodeIs', func_get_args())); + } + + + /** + * [!] Method is generated. Documentation taken from corresponding module. + * + * Checks that response code is between a certain range. Between actually means [from <= CODE <= to] + * + * @param $from + * @param $to + * Conditional Assertion: Test won't be stopped on fail + * @see \Codeception\Lib\InnerBrowser::seeResponseCodeIsBetween() + */ + public function canSeeResponseCodeIsBetween($from, $to) { + return $this->getScenario()->runStep(new \Codeception\Step\ConditionalAssertion('seeResponseCodeIsBetween', func_get_args())); + } + /** + * [!] Method is generated. Documentation taken from corresponding module. + * + * Checks that response code is between a certain range. Between actually means [from <= CODE <= to] + * + * @param $from + * @param $to + * @see \Codeception\Lib\InnerBrowser::seeResponseCodeIsBetween() + */ + public function seeResponseCodeIsBetween($from, $to) { + return $this->getScenario()->runStep(new \Codeception\Step\Assertion('seeResponseCodeIsBetween', func_get_args())); + } + + + /** + * [!] Method is generated. Documentation taken from corresponding module. + * + * Checks that response code is equal to value provided. + * + * ```php + * dontSeeResponseCodeIs(200); + * + * // recommended \Codeception\Util\HttpCode + * $I->dontSeeResponseCodeIs(\Codeception\Util\HttpCode::OK); + * ``` + * @param $code + * Conditional Assertion: Test won't be stopped on fail + * @see \Codeception\Lib\InnerBrowser::dontSeeResponseCodeIs() + */ + public function cantSeeResponseCodeIs($code) { + return $this->getScenario()->runStep(new \Codeception\Step\ConditionalAssertion('dontSeeResponseCodeIs', func_get_args())); + } + /** + * [!] Method is generated. Documentation taken from corresponding module. + * + * Checks that response code is equal to value provided. + * + * ```php + * dontSeeResponseCodeIs(200); + * + * // recommended \Codeception\Util\HttpCode + * $I->dontSeeResponseCodeIs(\Codeception\Util\HttpCode::OK); + * ``` + * @param $code + * @see \Codeception\Lib\InnerBrowser::dontSeeResponseCodeIs() + */ + public function dontSeeResponseCodeIs($code) { + return $this->getScenario()->runStep(new \Codeception\Step\Assertion('dontSeeResponseCodeIs', func_get_args())); + } + + + /** + * [!] Method is generated. Documentation taken from corresponding module. + * + * Checks that the response code 2xx + * Conditional Assertion: Test won't be stopped on fail + * @see \Codeception\Lib\InnerBrowser::seeResponseCodeIsSuccessful() + */ + public function canSeeResponseCodeIsSuccessful() { + return $this->getScenario()->runStep(new \Codeception\Step\ConditionalAssertion('seeResponseCodeIsSuccessful', func_get_args())); + } + /** + * [!] Method is generated. Documentation taken from corresponding module. + * + * Checks that the response code 2xx + * @see \Codeception\Lib\InnerBrowser::seeResponseCodeIsSuccessful() + */ + public function seeResponseCodeIsSuccessful() { + return $this->getScenario()->runStep(new \Codeception\Step\Assertion('seeResponseCodeIsSuccessful', func_get_args())); + } + + + /** + * [!] Method is generated. Documentation taken from corresponding module. + * + * Checks that the response code 3xx + * Conditional Assertion: Test won't be stopped on fail + * @see \Codeception\Lib\InnerBrowser::seeResponseCodeIsRedirection() + */ + public function canSeeResponseCodeIsRedirection() { + return $this->getScenario()->runStep(new \Codeception\Step\ConditionalAssertion('seeResponseCodeIsRedirection', func_get_args())); + } + /** + * [!] Method is generated. Documentation taken from corresponding module. + * + * Checks that the response code 3xx + * @see \Codeception\Lib\InnerBrowser::seeResponseCodeIsRedirection() + */ + public function seeResponseCodeIsRedirection() { + return $this->getScenario()->runStep(new \Codeception\Step\Assertion('seeResponseCodeIsRedirection', func_get_args())); + } + + + /** + * [!] Method is generated. Documentation taken from corresponding module. + * + * Checks that the response code is 4xx + * Conditional Assertion: Test won't be stopped on fail + * @see \Codeception\Lib\InnerBrowser::seeResponseCodeIsClientError() + */ + public function canSeeResponseCodeIsClientError() { + return $this->getScenario()->runStep(new \Codeception\Step\ConditionalAssertion('seeResponseCodeIsClientError', func_get_args())); + } + /** + * [!] Method is generated. Documentation taken from corresponding module. + * + * Checks that the response code is 4xx + * @see \Codeception\Lib\InnerBrowser::seeResponseCodeIsClientError() + */ + public function seeResponseCodeIsClientError() { + return $this->getScenario()->runStep(new \Codeception\Step\Assertion('seeResponseCodeIsClientError', func_get_args())); + } + + + /** + * [!] Method is generated. Documentation taken from corresponding module. + * + * Checks that the response code is 5xx + * Conditional Assertion: Test won't be stopped on fail + * @see \Codeception\Lib\InnerBrowser::seeResponseCodeIsServerError() + */ + public function canSeeResponseCodeIsServerError() { + return $this->getScenario()->runStep(new \Codeception\Step\ConditionalAssertion('seeResponseCodeIsServerError', func_get_args())); + } + /** + * [!] Method is generated. Documentation taken from corresponding module. + * + * Checks that the response code is 5xx + * @see \Codeception\Lib\InnerBrowser::seeResponseCodeIsServerError() + */ + public function seeResponseCodeIsServerError() { + return $this->getScenario()->runStep(new \Codeception\Step\Assertion('seeResponseCodeIsServerError', func_get_args())); + } + + + /** + * [!] Method is generated. Documentation taken from corresponding module. + * + * Checks that the page title contains the given string. + * + * ``` php + * seeInTitle('Blog - Post #1'); + * ?> + * ``` + * + * @param $title + * + * @return mixed + * Conditional Assertion: Test won't be stopped on fail + * @see \Codeception\Lib\InnerBrowser::seeInTitle() + */ + public function canSeeInTitle($title) { + return $this->getScenario()->runStep(new \Codeception\Step\ConditionalAssertion('seeInTitle', func_get_args())); + } + /** + * [!] Method is generated. Documentation taken from corresponding module. + * + * Checks that the page title contains the given string. + * + * ``` php + * seeInTitle('Blog - Post #1'); + * ?> + * ``` + * + * @param $title + * + * @return mixed + * @see \Codeception\Lib\InnerBrowser::seeInTitle() + */ + public function seeInTitle($title) { + return $this->getScenario()->runStep(new \Codeception\Step\Assertion('seeInTitle', func_get_args())); + } + + + /** + * [!] Method is generated. Documentation taken from corresponding module. + * + * Checks that the page title does not contain the given string. + * + * @param $title + * + * @return mixed + * Conditional Assertion: Test won't be stopped on fail + * @see \Codeception\Lib\InnerBrowser::dontSeeInTitle() + */ + public function cantSeeInTitle($title) { + return $this->getScenario()->runStep(new \Codeception\Step\ConditionalAssertion('dontSeeInTitle', func_get_args())); + } + /** + * [!] Method is generated. Documentation taken from corresponding module. + * + * Checks that the page title does not contain the given string. + * + * @param $title + * + * @return mixed + * @see \Codeception\Lib\InnerBrowser::dontSeeInTitle() + */ + public function dontSeeInTitle($title) { + return $this->getScenario()->runStep(new \Codeception\Step\Assertion('dontSeeInTitle', func_get_args())); + } + + + /** + * [!] Method is generated. Documentation taken from corresponding module. + * + * Switch to iframe or frame on the page. + * + * Example: + * ``` html + *