diff --git a/.php_cs b/.php_cs index cdb2e305..01c6a900 100644 --- a/.php_cs +++ b/.php_cs @@ -6,7 +6,8 @@ return PhpCsFixer\Config::create() 'array_syntax' => ['syntax' => 'short'], 'blank_line_after_opening_tag' => true, 'single_blank_line_before_namespace' => true, - 'no_unused_imports' => true + 'no_unused_imports' => true, + 'single_quote' => true ]) ->setFinder( PhpCsFixer\Finder::create() diff --git a/README.md b/README.md index eb4a891c..7fd4b5b4 100644 --- a/README.md +++ b/README.md @@ -4,12 +4,14 @@ [![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/coduo/php-matcher/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/coduo/php-matcher/?branch=master) -* [![Build Status](https://travis-ci.org/coduo/php-matcher.svg)](https://travis-ci.org/coduo/php-matcher) - master (3.0.*) +* [![Build Status](https://travis-ci.org/coduo/php-matcher.svg)](https://travis-ci.org/coduo/php-matcher) - master (3.1.*) +* [![Build Status](https://travis-ci.org/coduo/php-matcher.svg?branch=3.0)](https://travis-ci.org/coduo/php-matcher) - 3.0.* * [![Build Status](https://travis-ci.org/coduo/php-matcher.svg?branch=2.2)](https://travis-ci.org/coduo/php-matcher) - 2.2.* * [![Build Status](https://travis-ci.org/coduo/php-matcher.svg?branch=2.1)](https://travis-ci.org/coduo/php-matcher) - 2.1.* * [![Build Status](https://travis-ci.org/coduo/php-matcher.svg?branch=2.0)](https://travis-ci.org/coduo/php-matcher) - 2.0.* -[Readme for master (3.0) version](https://github.com/coduo/php-matcher/tree/master/README.md) +[Readme for master (3.1) version](https://github.com/coduo/php-matcher/tree/master/README.md) +[Readme for 3.0 version](https://github.com/coduo/php-matcher/tree/3.0/README.md) [Readme for 2.2 version](https://github.com/coduo/php-matcher/tree/2.2/README.md) [Readme for 2.1 version](https://github.com/coduo/php-matcher/tree/2.1/README.md) [Readme for 2.0 version](https://github.com/coduo/php-matcher/tree/2.0/README.md) @@ -100,7 +102,7 @@ $factory = new SimpleFactory(); $matcher = $factory->createMatcher(); $matcher->match(1, 1); -$matcher->match('string', 'string') +$matcher->match('string', 'string'); ``` ### String matching @@ -114,7 +116,7 @@ $factory = new SimpleFactory(); $matcher = $factory->createMatcher(); $matcher->match('Norbert', '@string@'); -$matcher->match("lorem ipsum dolor", "@string@.startsWith('lorem').contains('ipsum').endsWith('dolor')") +$matcher->match("lorem ipsum dolor", "@string@.startsWith('lorem').contains('ipsum').endsWith('dolor')"); ``` @@ -188,12 +190,12 @@ use Coduo\PHPMatcher\Factory\SimpleFactory; $factory = new SimpleFactory(); $matcher = $factory->createMatcher(); -$matcher->match("@integer@", "@*@"), -$matcher->match("foobar", "@*@"), -$matcher->match(true, "@*@"), -$matcher->match(6.66, "@*@"), -$matcher->match(array("bar"), "@wildcard@"), -$matcher->match(new \stdClass, "@wildcard@"), +$matcher->match("@integer@", "@*@"); +$matcher->match("foobar", "@*@"); +$matcher->match(true, "@*@"); +$matcher->match(6.66, "@*@"); +$matcher->match(array("bar"), "@wildcard@"); +$matcher->match(new \stdClass, "@wildcard@"); ``` ### Expression matching @@ -279,7 +281,7 @@ $matcher->match( '@boolean@', '@double@' ) -) +); ``` ### Json matching @@ -313,8 +315,7 @@ $matcher->match( } ] }' -) - +); ``` ### Xml matching diff --git a/src/Exception/UnknownTypeException.php b/src/Exception/UnknownTypeException.php index bed58117..619fcab3 100644 --- a/src/Exception/UnknownTypeException.php +++ b/src/Exception/UnknownTypeException.php @@ -10,8 +10,8 @@ class UnknownTypeException extends Exception public function __construct(string $type) { - $this->type = "@" . $type . "@"; - parent::__construct(sprintf("Type pattern \"%s\" is not supported.", $this->type), 0, null); + $this->type = '@' . $type . '@'; + parent::__construct(sprintf('Type pattern "%s" is not supported.', $this->type), 0, null); } public function getType() : string diff --git a/src/Lexer.php b/src/Lexer.php index b4a299dc..c2d70631 100644 --- a/src/Lexer.php +++ b/src/Lexer.php @@ -27,12 +27,12 @@ final class Lexer extends AbstractLexer protected function getCatchablePatterns() : array { return [ - "\\.?[a-zA-Z0-9_]+\\(", // expander name - "[a-zA-Z0-9.]*", // words - "\\-?[0-9]*\\.?[0-9]*", // numbers + '\\.?[a-zA-Z0-9_]+\\(', // expander name + '[a-zA-Z0-9.]*', // words + '\\-?[0-9]*\\.?[0-9]*', // numbers "'(?:[^']|'')*'", // string between ' character - "\"(?:[^\"]|\"\")*\"", // string between " character, - "@[a-zA-Z0-9\\*]+@", // type pattern + '"(?:[^"]|"")*"', // string between " character, + '@[a-zA-Z0-9\\*]+@', // type pattern ]; } @@ -42,7 +42,7 @@ protected function getCatchablePatterns() : array protected function getNonCatchablePatterns() : array { return [ - "\\s+", + '\\s+', ]; } @@ -107,7 +107,7 @@ protected function getType(&$value) : int protected function isStringToken(string $value) : bool { - return in_array(substr($value, 0, 1), ["\"", "'"]); + return in_array(substr($value, 0, 1), ['"', "'"]); } protected function isBooleanToken(string $value) : bool diff --git a/src/Matcher/ArrayMatcher.php b/src/Matcher/ArrayMatcher.php index 5bbbee75..63d25596 100644 --- a/src/Matcher/ArrayMatcher.php +++ b/src/Matcher/ArrayMatcher.php @@ -35,7 +35,7 @@ public function match($value, $pattern) : bool } if (!is_array($value)) { - $this->error = sprintf("%s \"%s\" is not a valid array.", gettype($value), new StringConverter($value)); + $this->error = sprintf('%s "%s" is not a valid array.', gettype($value), new StringConverter($value)); return false; } @@ -64,7 +64,7 @@ private function isArrayPattern($pattern) : bool return $this->parser->hasValidSyntax($pattern) && $this->parser->parse($pattern)->is(self::PATTERN); } - private function iterateMatch(array $values, array $patterns, string $parentPath = "") : bool + private function iterateMatch(array $values, array $patterns, string $parentPath = '') : bool { $pattern = null; foreach ($values as $key => $value) { @@ -222,12 +222,12 @@ private function setMissingElementInError(string $place, string $path) private function formatAccessPath($key) : string { - return sprintf("[%s]", $key); + return sprintf('[%s]', $key); } private function formatFullPath(string $parentPath, string $path) : string { - return sprintf("%s%s", $parentPath, $path); + return sprintf('%s%s', $parentPath, $path); } private function shouldSkippValueMatchingFor($lastPattern) : bool diff --git a/src/Matcher/BooleanMatcher.php b/src/Matcher/BooleanMatcher.php index 3231f6d2..3d9f5065 100644 --- a/src/Matcher/BooleanMatcher.php +++ b/src/Matcher/BooleanMatcher.php @@ -21,7 +21,7 @@ public function __construct(Parser $parser) public function match($value, $pattern) : bool { if (!is_bool($value)) { - $this->error = sprintf("%s \"%s\" is not a valid boolean.", gettype($value), new StringConverter($value)); + $this->error = sprintf('%s "%s" is not a valid boolean.', gettype($value), new StringConverter($value)); return false; } diff --git a/src/Matcher/DoubleMatcher.php b/src/Matcher/DoubleMatcher.php index 8ae5765d..6d639e02 100644 --- a/src/Matcher/DoubleMatcher.php +++ b/src/Matcher/DoubleMatcher.php @@ -21,7 +21,7 @@ public function __construct(Parser $parser) public function match($value, $pattern) : bool { if (!is_double($value)) { - $this->error = sprintf("%s \"%s\" is not a valid double.", gettype($value), new StringConverter($value)); + $this->error = sprintf('%s "%s" is not a valid double.', gettype($value), new StringConverter($value)); return false; } diff --git a/src/Matcher/ExpressionMatcher.php b/src/Matcher/ExpressionMatcher.php index ef99b164..3b6c99f7 100644 --- a/src/Matcher/ExpressionMatcher.php +++ b/src/Matcher/ExpressionMatcher.php @@ -18,7 +18,7 @@ public function match($value, $pattern) : bool $expressionResult = $language->evaluate($matches[1], ['value' => $value]); if (!$expressionResult) { - $this->error = sprintf("\"%s\" expression fails for value \"%s\".", $pattern, new StringConverter($value)); + $this->error = sprintf('"%s" expression fails for value "%s".', $pattern, new StringConverter($value)); } return (bool) $expressionResult; diff --git a/src/Matcher/IntegerMatcher.php b/src/Matcher/IntegerMatcher.php index 1c669e6d..14656920 100644 --- a/src/Matcher/IntegerMatcher.php +++ b/src/Matcher/IntegerMatcher.php @@ -21,7 +21,7 @@ public function __construct(Parser $parser) public function match($value, $pattern) : bool { if (!is_integer($value)) { - $this->error = sprintf("%s \"%s\" is not a valid integer.", gettype($value), new StringConverter($value)); + $this->error = sprintf('%s "%s" is not a valid integer.', gettype($value), new StringConverter($value)); return false; } diff --git a/src/Matcher/JsonMatcher.php b/src/Matcher/JsonMatcher.php index d457b6dd..f208b297 100644 --- a/src/Matcher/JsonMatcher.php +++ b/src/Matcher/JsonMatcher.php @@ -22,12 +22,12 @@ public function match($value, $pattern) : bool } if (!Json::isValid($value)) { - $this->error = sprintf("Invalid given JSON of value. %s", $this->getErrorMessage()); + $this->error = sprintf('Invalid given JSON of value. %s', $this->getErrorMessage()); return false; } if (!Json::isValidPattern($pattern)) { - $this->error = sprintf("Invalid given JSON of pattern. %s", $this->getErrorMessage()); + $this->error = sprintf('Invalid given JSON of pattern. %s', $this->getErrorMessage()); return false; } diff --git a/src/Matcher/NullMatcher.php b/src/Matcher/NullMatcher.php index 68e388b0..381f8f81 100644 --- a/src/Matcher/NullMatcher.php +++ b/src/Matcher/NullMatcher.php @@ -8,7 +8,7 @@ final class NullMatcher extends Matcher { - const MATCH_PATTERN = "/^@null@$/"; + const MATCH_PATTERN = '/^@null@$/'; /** * {@inheritDoc} @@ -16,7 +16,7 @@ final class NullMatcher extends Matcher public function match($value, $pattern) : bool { if (null !== $value) { - $this->error = sprintf("%s \"%s\" does not match null.", gettype($value), new StringConverter($value)); + $this->error = sprintf('%s "%s" does not match null.', gettype($value), new StringConverter($value)); return false; } diff --git a/src/Matcher/NumberMatcher.php b/src/Matcher/NumberMatcher.php index 69bcfe45..b1d8ee2f 100644 --- a/src/Matcher/NumberMatcher.php +++ b/src/Matcher/NumberMatcher.php @@ -21,7 +21,7 @@ public function __construct(Parser $parser) public function match($value, $pattern) : bool { if (!is_numeric($value)) { - $this->error = sprintf("%s \"%s\" is not a valid number.", gettype($value), new StringConverter($value)); + $this->error = sprintf('%s "%s" is not a valid number.', gettype($value), new StringConverter($value)); return false; } diff --git a/src/Matcher/Pattern/Expander/Contains.php b/src/Matcher/Pattern/Expander/Contains.php index d941fce4..4bad1d78 100644 --- a/src/Matcher/Pattern/Expander/Contains.php +++ b/src/Matcher/Pattern/Expander/Contains.php @@ -43,7 +43,7 @@ public function __construct(string $string, $ignoreCase = false) public function match($value) : bool { if (!is_string($value)) { - $this->error = sprintf("Contains expander require \"string\", got \"%s\".", new StringConverter($value)); + $this->error = sprintf('Contains expander require "string", got "%s".', new StringConverter($value)); return false; } diff --git a/src/Matcher/Pattern/Expander/Count.php b/src/Matcher/Pattern/Expander/Count.php index 681d0e43..3f3b9f48 100644 --- a/src/Matcher/Pattern/Expander/Count.php +++ b/src/Matcher/Pattern/Expander/Count.php @@ -28,12 +28,12 @@ public function __construct(int $value) public function match($value) :bool { if (!is_array($value)) { - $this->error = sprintf("Count expander require \"array\", got \"%s\".", new StringConverter($value)); + $this->error = sprintf('Count expander require "array", got "%s".', new StringConverter($value)); return false; } if (count($value) !== $this->value) { - $this->error = sprintf("Expected count of %s is %s.", new StringConverter($value), new StringConverter($this->value)); + $this->error = sprintf('Expected count of %s is %s.', new StringConverter($value), new StringConverter($this->value)); return false; } diff --git a/src/Matcher/Pattern/Expander/EndsWith.php b/src/Matcher/Pattern/Expander/EndsWith.php index d192e50f..6b28866c 100644 --- a/src/Matcher/Pattern/Expander/EndsWith.php +++ b/src/Matcher/Pattern/Expander/EndsWith.php @@ -20,7 +20,7 @@ final class EndsWith implements PatternExpander public function __construct(string $stringEnding, bool $ignoreCase = false) { if (!is_string($stringEnding)) { - throw new \InvalidArgumentException("String ending must be a valid string."); + throw new \InvalidArgumentException('String ending must be a valid string.'); } $this->stringEnding = $stringEnding; @@ -35,7 +35,7 @@ public static function is(string $name) : bool public function match($value) : bool { if (!is_string($value)) { - $this->error = sprintf("EndsWith expander require \"string\", got \"%s\".", new StringConverter($value)); + $this->error = sprintf('EndsWith expander require "string", got "%s".', new StringConverter($value)); return false; } diff --git a/src/Matcher/Pattern/Expander/GreaterThan.php b/src/Matcher/Pattern/Expander/GreaterThan.php index a52453e7..5bd3fe2c 100644 --- a/src/Matcher/Pattern/Expander/GreaterThan.php +++ b/src/Matcher/Pattern/Expander/GreaterThan.php @@ -18,7 +18,7 @@ final class GreaterThan implements PatternExpander public function __construct($boundary) { if (!is_float($boundary) && !is_int($boundary)) { - throw new \InvalidArgumentException(sprintf("Boundary value \"%s\" is not a valid number.", new StringConverter($boundary))); + throw new \InvalidArgumentException(sprintf('Boundary value "%s" is not a valid number.', new StringConverter($boundary))); } $this->boundary = $boundary; @@ -32,12 +32,12 @@ public static function is(string $name) : bool public function match($value) : bool { if (!is_float($value) && !is_int($value) && !is_numeric($value)) { - $this->error = sprintf("Value \"%s\" is not a valid number.", new StringConverter($value)); + $this->error = sprintf('Value "%s" is not a valid number.', new StringConverter($value)); return false; } if ($value <= $this->boundary) { - $this->error = sprintf("Value \"%s\" is not greater than \"%s\".", new StringConverter($value), new StringConverter($this->boundary)); + $this->error = sprintf('Value "%s" is not greater than "%s".', new StringConverter($value), new StringConverter($this->boundary)); return false; } diff --git a/src/Matcher/Pattern/Expander/InArray.php b/src/Matcher/Pattern/Expander/InArray.php index d385cdb4..c226f9a7 100644 --- a/src/Matcher/Pattern/Expander/InArray.php +++ b/src/Matcher/Pattern/Expander/InArray.php @@ -28,7 +28,7 @@ public static function is(string $name) : bool public function match($value) : bool { if (!is_array($value)) { - $this->error = sprintf("InArray expander require \"array\", got \"%s\".", new StringConverter($value)); + $this->error = sprintf('InArray expander require "array", got "%s".', new StringConverter($value)); return false; } diff --git a/src/Matcher/Pattern/Expander/IsDateTime.php b/src/Matcher/Pattern/Expander/IsDateTime.php index 92b2518f..19ae7d29 100644 --- a/src/Matcher/Pattern/Expander/IsDateTime.php +++ b/src/Matcher/Pattern/Expander/IsDateTime.php @@ -21,12 +21,12 @@ public static function is(string $name) : bool public function match($value) : bool { if (false === is_string($value)) { - $this->error = sprintf("IsDateTime expander require \"string\", got \"%s\".", new StringConverter($value)); + $this->error = sprintf('IsDateTime expander require "string", got "%s".', new StringConverter($value)); return false; } if (false === $this->matchValue($value)) { - $this->error = sprintf("string \"%s\" is not a valid date.", $value); + $this->error = sprintf('string "%s" is not a valid date.', $value); return false; } diff --git a/src/Matcher/Pattern/Expander/IsEmail.php b/src/Matcher/Pattern/Expander/IsEmail.php index acde0409..d1de7616 100644 --- a/src/Matcher/Pattern/Expander/IsEmail.php +++ b/src/Matcher/Pattern/Expander/IsEmail.php @@ -21,12 +21,12 @@ public static function is(string $name) : bool public function match($value) : bool { if (false === is_string($value)) { - $this->error = sprintf("IsEmail expander require \"string\", got \"%s\".", new StringConverter($value)); + $this->error = sprintf('IsEmail expander require "string", got "%s".', new StringConverter($value)); return false; } if (false === $this->matchValue($value)) { - $this->error = sprintf("string \"%s\" is not a valid e-mail address.", $value); + $this->error = sprintf('string "%s" is not a valid e-mail address.', $value); return false; } diff --git a/src/Matcher/Pattern/Expander/IsEmpty.php b/src/Matcher/Pattern/Expander/IsEmpty.php index dea00962..41ab5578 100644 --- a/src/Matcher/Pattern/Expander/IsEmpty.php +++ b/src/Matcher/Pattern/Expander/IsEmpty.php @@ -21,7 +21,7 @@ public static function is(string $name) : bool public function match($value) : bool { if (!empty($value)) { - $this->error = sprintf("Value %s is not empty.", new StringConverter($value)); + $this->error = sprintf('Value %s is not empty.', new StringConverter($value)); return false; } diff --git a/src/Matcher/Pattern/Expander/IsNotEmpty.php b/src/Matcher/Pattern/Expander/IsNotEmpty.php index 6ea4dd31..69215752 100644 --- a/src/Matcher/Pattern/Expander/IsNotEmpty.php +++ b/src/Matcher/Pattern/Expander/IsNotEmpty.php @@ -21,7 +21,7 @@ public static function is(string $name) : bool public function match($value) : bool { if (false === $value || (empty($value) && '0' != $value)) { - $this->error = sprintf("Value %s is not blank.", new StringConverter($value)); + $this->error = sprintf('Value %s is not blank.', new StringConverter($value)); return false; } diff --git a/src/Matcher/Pattern/Expander/IsUrl.php b/src/Matcher/Pattern/Expander/IsUrl.php index 8663f1e5..257aed0b 100644 --- a/src/Matcher/Pattern/Expander/IsUrl.php +++ b/src/Matcher/Pattern/Expander/IsUrl.php @@ -21,12 +21,12 @@ public static function is(string $name) : bool public function match($value) : bool { if (false === is_string($value)) { - $this->error = sprintf("IsUrl expander require \"string\", got \"%s\".", new StringConverter($value)); + $this->error = sprintf('IsUrl expander require "string", got "%s".', new StringConverter($value)); return false; } if (false === $this->matchValue($value)) { - $this->error = sprintf("string \"%s\" is not a valid URL.", $value); + $this->error = sprintf('string "%s" is not a valid URL.', $value); return false; } diff --git a/src/Matcher/Pattern/Expander/LowerThan.php b/src/Matcher/Pattern/Expander/LowerThan.php index 39a744b9..d752e9ea 100644 --- a/src/Matcher/Pattern/Expander/LowerThan.php +++ b/src/Matcher/Pattern/Expander/LowerThan.php @@ -19,7 +19,7 @@ final class LowerThan implements PatternExpander public function __construct($boundary) { if (!is_float($boundary) && !is_integer($boundary) && !is_double($boundary)) { - throw new \InvalidArgumentException(sprintf("Boundary value \"%s\" is not a valid number.", new StringConverter($boundary))); + throw new \InvalidArgumentException(sprintf('Boundary value "%s" is not a valid number.', new StringConverter($boundary))); } $this->boundary = $boundary; @@ -33,12 +33,12 @@ public static function is(string $name) : bool public function match($value) : bool { if (!is_float($value) && !is_integer($value) && !is_double($value)) { - $this->error = sprintf("Value \"%s\" is not a valid number.", new StringConverter($value)); + $this->error = sprintf('Value "%s" is not a valid number.', new StringConverter($value)); return false; } if ($value >= $this->boundary) { - $this->error = sprintf("Value \"%s\" is not lower than \"%s\".", new StringConverter($value), new StringConverter($this->boundary)); + $this->error = sprintf('Value "%s" is not lower than "%s".', new StringConverter($value), new StringConverter($this->boundary)); return false; } diff --git a/src/Matcher/Pattern/Expander/MatchRegex.php b/src/Matcher/Pattern/Expander/MatchRegex.php index 6ac87b35..f82e33a2 100644 --- a/src/Matcher/Pattern/Expander/MatchRegex.php +++ b/src/Matcher/Pattern/Expander/MatchRegex.php @@ -18,11 +18,11 @@ final class MatchRegex implements PatternExpander public function __construct($pattern) { if (!is_string($pattern)) { - throw new \InvalidArgumentException("Regex pattern must be a string."); + throw new \InvalidArgumentException('Regex pattern must be a string.'); } if (!is_string($pattern) || @preg_match($pattern, '') === false) { - throw new \InvalidArgumentException("Regex pattern must be a valid one."); + throw new \InvalidArgumentException('Regex pattern must be a valid one.'); } $this->pattern = $pattern; @@ -36,7 +36,7 @@ public static function is(string $name) : bool public function match($value) : bool { if (false === is_string($value)) { - $this->error = sprintf("Match expander require \"string\", got \"%s\".", new StringConverter($value)); + $this->error = sprintf('Match expander require "string", got "%s".', new StringConverter($value)); return false; } diff --git a/src/Matcher/Pattern/Expander/OneOf.php b/src/Matcher/Pattern/Expander/OneOf.php index 70e668e0..23195328 100644 --- a/src/Matcher/Pattern/Expander/OneOf.php +++ b/src/Matcher/Pattern/Expander/OneOf.php @@ -21,11 +21,11 @@ final class OneOf implements PatternExpander public function __construct() { if (func_num_args() < 2) { - throw new \InvalidArgumentException("OneOf expander require at least two expanders."); + throw new \InvalidArgumentException('OneOf expander require at least two expanders.'); } foreach (func_get_args() as $argument) { if (!$argument instanceof PatternExpander) { - throw new \InvalidArgumentException("OneOf expander require each argument to be a valid PatternExpander."); + throw new \InvalidArgumentException('OneOf expander require each argument to be a valid PatternExpander.'); } $this->expanders[] = $argument; @@ -45,7 +45,7 @@ public function match($value) : bool } } - $this->error = sprintf("Any expander available in OneOf expander does not match \"%s\".", new StringConverter($value)); + $this->error = sprintf('Any expander available in OneOf expander does not match "%s".', new StringConverter($value)); return false; } diff --git a/src/Matcher/Pattern/Expander/Repeat.php b/src/Matcher/Pattern/Expander/Repeat.php index 852caf7e..dc2b26a7 100644 --- a/src/Matcher/Pattern/Expander/Repeat.php +++ b/src/Matcher/Pattern/Expander/Repeat.php @@ -47,7 +47,7 @@ public static function is(string $name) : bool public function __construct(string $pattern, bool $isStrict = true) { if (!is_string($pattern)) { - throw new \InvalidArgumentException("Repeat pattern must be a string."); + throw new \InvalidArgumentException('Repeat pattern must be a string.'); } $this->pattern = $pattern; @@ -69,7 +69,7 @@ public function __construct(string $pattern, bool $isStrict = true) public function match($values) : bool { if (!is_array($values)) { - $this->error = sprintf("Repeat expander require \"array\", got \"%s\".", new StringConverter($values)); + $this->error = sprintf('Repeat expander require "array", got "%s".', new StringConverter($values)); return false; } @@ -102,7 +102,7 @@ private function matchScalar(array $values, Matcher $matcher) : bool $match = $matcher->match($value, $this->pattern); if (!$match) { - $this->error = sprintf("Repeat expander, entry n°%d, find error : %s", $index, $matcher->getError()); + $this->error = sprintf('Repeat expander, entry n°%d, find error : %s', $index, $matcher->getError()); return false; } } @@ -125,20 +125,20 @@ private function matchJson(array $values, Matcher $matcher) : bool $valueKeysLength = count($valueKeys); if ($this->isStrict && $patternKeysLength !== $valueKeysLength) { - $this->error = sprintf("Repeat expander expect to have %d keys in array but get : %d", $patternKeysLength, $valueKeysLength); + $this->error = sprintf('Repeat expander expect to have %d keys in array but get : %d', $patternKeysLength, $valueKeysLength); return false; } foreach ($patternKeys as $key) { if (!array_key_exists($key, $value)) { - $this->error = sprintf("Repeat expander, entry n°%d, require \"array\" to have key \"%s\".", $index, $key); + $this->error = sprintf('Repeat expander, entry n°%d, require "array" to have key "%s".', $index, $key); return false; } $match = $matcher->match($value[$key], $this->pattern[$key]); if (!$match) { - $this->error = sprintf("Repeat expander, entry n°%d, key \"%s\", find error : %s", $index, $key, $matcher->getError()); + $this->error = sprintf('Repeat expander, entry n°%d, key "%s", find error : %s', $index, $key, $matcher->getError()); return false; } } diff --git a/src/Matcher/Pattern/Expander/StartsWith.php b/src/Matcher/Pattern/Expander/StartsWith.php index 347ae23d..8fb95138 100644 --- a/src/Matcher/Pattern/Expander/StartsWith.php +++ b/src/Matcher/Pattern/Expander/StartsWith.php @@ -20,7 +20,7 @@ final class StartsWith implements PatternExpander public function __construct(string $stringBeginning, bool $ignoreCase = false) { if (!is_string($stringBeginning)) { - throw new \InvalidArgumentException("String beginning must be a valid string."); + throw new \InvalidArgumentException('String beginning must be a valid string.'); } $this->stringBeginning = $stringBeginning; @@ -36,7 +36,7 @@ public static function is(string $name) : bool public function match($value) : bool { if (!is_string($value)) { - $this->error = sprintf("StartsWith expander require \"string\", got \"%s\".", new StringConverter($value)); + $this->error = sprintf('StartsWith expander require "string", got "%s".', new StringConverter($value)); return false; } diff --git a/src/Matcher/Pattern/RegexConverter.php b/src/Matcher/Pattern/RegexConverter.php index d580926d..d405750e 100644 --- a/src/Matcher/Pattern/RegexConverter.php +++ b/src/Matcher/Pattern/RegexConverter.php @@ -14,13 +14,13 @@ public function toRegex(TypePattern $typePattern) : string case 'string': case 'wildcard': case '*': - return "(.+)"; + return '(.+)'; case 'number': - return "(\\-?[0-9]*[\\.|\\,]?[0-9]*)"; + return '(\\-?[0-9]*[\\.|\\,]?[0-9]*)'; case 'integer': - return "(\\-?[0-9]*)"; + return '(\\-?[0-9]*)'; case 'double': - return "(\\-?[0-9]*[\\.|\\,][0-9]*)"; + return '(\\-?[0-9]*[\\.|\\,][0-9]*)'; default: throw new UnknownTypeException($typePattern->getType()); } diff --git a/src/Matcher/ScalarMatcher.php b/src/Matcher/ScalarMatcher.php index 9247aa61..6d28653d 100644 --- a/src/Matcher/ScalarMatcher.php +++ b/src/Matcher/ScalarMatcher.php @@ -11,7 +11,7 @@ final class ScalarMatcher extends Matcher public function match($value, $pattern) : bool { if ($value !== $pattern) { - $this->error = sprintf("\"%s\" does not match \"%s\".", new StringConverter($value), new StringConverter($pattern)); + $this->error = sprintf('"%s" does not match "%s".', new StringConverter($value), new StringConverter($pattern)); return false; } diff --git a/src/Matcher/StringMatcher.php b/src/Matcher/StringMatcher.php index b1f25a73..eb23be0a 100644 --- a/src/Matcher/StringMatcher.php +++ b/src/Matcher/StringMatcher.php @@ -21,7 +21,7 @@ public function __construct(Parser $parser) public function match($value, $pattern) : bool { if (!is_string($value)) { - $this->error = sprintf("%s \"%s\" is not a valid string.", gettype($value), new StringConverter($value)); + $this->error = sprintf('%s "%s" is not a valid string.', gettype($value), new StringConverter($value)); return false; } diff --git a/src/Matcher/TextMatcher.php b/src/Matcher/TextMatcher.php index 74cef7db..93a335d2 100644 --- a/src/Matcher/TextMatcher.php +++ b/src/Matcher/TextMatcher.php @@ -16,7 +16,7 @@ final class TextMatcher extends Matcher { const PATTERN_REGEXP = "/@[a-zA-Z\\.]+@(\\.[a-zA-Z0-9_]+\\([a-zA-Z0-9{},:@\\.\"'\\(\\)]*\\))*/"; - const PATTERN_REGEXP_PLACEHOLDER_TEMPLATE = "__PLACEHOLDER%d__"; + const PATTERN_REGEXP_PLACEHOLDER_TEMPLATE = '__PLACEHOLDER%d__'; /** * @var Parser @@ -44,7 +44,7 @@ public function __construct(ValueMatcher $matcher, Parser $parser) public function match($value, $pattern) : bool { if (!is_string($value)) { - $this->error = sprintf("%s \"%s\" is not a valid string.", gettype($value), new StringConverter($value)); + $this->error = sprintf('%s "%s" is not a valid string.', gettype($value), new StringConverter($value)); return false; } @@ -54,19 +54,19 @@ public function match($value, $pattern) : bool try { $patternRegex = $this->replacePlaceholderWithPatternRegexes($patternRegex, $patternsReplacedWithRegex); } catch (UnknownTypeException $exception) { - $this->error = sprintf(sprintf("Type pattern \"%s\" is not supported by TextMatcher.", $exception->getType())); + $this->error = sprintf(sprintf('Type pattern "%s" is not supported by TextMatcher.', $exception->getType())); return false; } if (!preg_match($patternRegex, $value, $matchedValues)) { - $this->error = sprintf("\"%s\" does not match \"%s\" pattern", $value, $pattern); + $this->error = sprintf('"%s" does not match "%s" pattern', $value, $pattern); return false; } array_shift($matchedValues); // remove matched string if (count($patternsReplacedWithRegex) !== count($matchedValues)) { - $this->error = "Unexpected TextMatcher error."; + $this->error = 'Unexpected TextMatcher error.'; return false; } @@ -160,6 +160,6 @@ private function replacePlaceholderWithPatternRegexes(string $patternRegex, arra */ private function prepareRegex(string $patternRegex) : string { - return "/^" . preg_quote($patternRegex, '/') . "$/"; + return '/^' . preg_quote($patternRegex, '/') . '$/'; } } diff --git a/src/Matcher/UuidMatcher.php b/src/Matcher/UuidMatcher.php index 251a65cf..1fc2097b 100644 --- a/src/Matcher/UuidMatcher.php +++ b/src/Matcher/UuidMatcher.php @@ -23,7 +23,7 @@ public function match($value, $pattern) : bool { if (!is_string($value)) { $this->error = sprintf( - "%s \"%s\" is not a valid UUID: not a string.", + '%s "%s" is not a valid UUID: not a string.', gettype($value), new StringConverter($value) ); @@ -32,7 +32,7 @@ public function match($value, $pattern) : bool if (1 !== preg_match(self::UUID_FORMAT_PATTERN, $value)) { $this->error = sprintf( - "%s \"%s\" is not a valid UUID: invalid format.", + '%s "%s" is not a valid UUID: invalid format.', gettype($value), $value ); diff --git a/src/Parser.php b/src/Parser.php index c22c6be7..0480c384 100644 --- a/src/Parser.php +++ b/src/Parser.php @@ -59,7 +59,7 @@ private function getPattern() : AST\Pattern $pattern = new AST\Pattern(new AST\Type($this->lexer->lookahead['value'])); break; default: - $this->unexpectedSyntaxError($this->lexer->lookahead, "@type@ pattern"); + $this->unexpectedSyntaxError($this->lexer->lookahead, '@type@ pattern'); break; } @@ -93,17 +93,17 @@ private function getNextExpanderNode() $expander = new AST\Expander($this->getExpanderName()); if ($this->endOfPattern()) { - $this->unexpectedEndOfString(")"); + $this->unexpectedEndOfString(')'); } $this->addArgumentValues($expander); if ($this->endOfPattern()) { - $this->unexpectedEndOfString(")"); + $this->unexpectedEndOfString(')'); } if (!$this->isNextCloseParenthesis()) { - $this->unexpectedSyntaxError($this->lexer->lookahead, ")"); + $this->unexpectedSyntaxError($this->lexer->lookahead, ')'); } return $expander; @@ -112,7 +112,7 @@ private function getNextExpanderNode() private function getExpanderName() { if ($this->lexer->lookahead['type'] !== Lexer::T_EXPANDER_NAME) { - $this->unexpectedSyntaxError($this->lexer->lookahead, ".expanderName(args) definition"); + $this->unexpectedSyntaxError($this->lexer->lookahead, '.expanderName(args) definition'); } $expander = $this->lexer->lookahead['value']; $this->lexer->moveNext(); @@ -137,7 +137,7 @@ private function addArgumentValues(AST\Expander $expander) $this->lexer->moveNext(); if ($this->lexer->isNextToken(Lexer::T_CLOSE_PARENTHESIS)) { - $this->unexpectedSyntaxError($this->lexer->lookahead, "string, number, boolean or null argument"); + $this->unexpectedSyntaxError($this->lexer->lookahead, 'string, number, boolean or null argument'); } } } @@ -169,7 +169,7 @@ private function getNextArgumentValue() } if (!$this->lexer->isNextTokenAny($validArgumentTypes)) { - $this->unexpectedSyntaxError($this->lexer->lookahead, "string, number, boolean or null argument"); + $this->unexpectedSyntaxError($this->lexer->lookahead, 'string, number, boolean or null argument'); } $tokenType = $this->lexer->lookahead['type']; @@ -193,7 +193,7 @@ private function getArrayArgument() : array } if (!$this->lexer->isNextToken(Lexer::T_CLOSE_CURLY_BRACE)) { - $this->unexpectedSyntaxError($this->lexer->lookahead, "}"); + $this->unexpectedSyntaxError($this->lexer->lookahead, '}'); } $this->lexer->moveNext(); @@ -209,11 +209,11 @@ private function getNextArrayElement(array &$array) $key = $this->getNextArgumentValue(); if ($key === self::NULL_VALUE) { - $key = ""; + $key = ''; } if (!$this->lexer->isNextToken(Lexer::T_COLON)) { - $this->unexpectedSyntaxError($this->lexer->lookahead, ":"); + $this->unexpectedSyntaxError($this->lexer->lookahead, ':'); } $this->lexer->moveNext(); @@ -248,9 +248,9 @@ private function isNextCloseParenthesis() : bool private function unexpectedSyntaxError(array $unexpectedToken, string $expected = null) { $tokenPos = (isset($unexpectedToken['position'])) ? $unexpectedToken['position'] : '-1'; - $message = sprintf("line 0, col %d: Error: ", $tokenPos); - $message .= (isset($expected)) ? sprintf("Expected \"%s\", got ", $expected) : "Unexpected"; - $message .= sprintf("\"%s\"", $unexpectedToken['value']); + $message = sprintf('line 0, col %d: Error: ', $tokenPos); + $message .= (isset($expected)) ? sprintf('Expected "%s", got ', $expected) : 'Unexpected'; + $message .= sprintf('"%s"', $unexpectedToken['value']); throw PatternException::syntaxError($message); } @@ -262,9 +262,9 @@ private function unexpectedSyntaxError(array $unexpectedToken, string $expected private function unexpectedEndOfString(string $expected = null) { $tokenPos = (isset($this->lexer->token['position'])) ? $this->lexer->token['position'] + strlen((string) $this->lexer->token['value']) : '-1'; - $message = sprintf("line 0, col %d: Error: ", $tokenPos); - $message .= (isset($expected)) ? sprintf("Expected \"%s\", got end of string.", $expected) : "Unexpected"; - $message .= "end of string"; + $message = sprintf('line 0, col %d: Error: ', $tokenPos); + $message .= (isset($expected)) ? sprintf('Expected "%s", got end of string.', $expected) : 'Unexpected'; + $message .= 'end of string'; throw PatternException::syntaxError($message); } diff --git a/src/Parser/ExpanderInitializer.php b/src/Parser/ExpanderInitializer.php index 21b712f0..84f49ad0 100644 --- a/src/Parser/ExpanderInitializer.php +++ b/src/Parser/ExpanderInitializer.php @@ -36,7 +36,7 @@ final class ExpanderInitializer public function setExpanderDefinition(string $expanderName, string $expanderFQCN) { if (!class_exists($expanderFQCN)) { - throw new UnknownExpanderClassException(sprintf("Class \"%s\" does not exists.", $expanderFQCN)); + throw new UnknownExpanderClassException(sprintf('Class "%s" does not exists.', $expanderFQCN)); } $this->expanderDefinitions[$expanderName] = $expanderFQCN; @@ -50,7 +50,7 @@ public function hasExpanderDefinition(string $expanderName) : bool public function getExpanderDefinition(string $expanderName) : string { if (!$this->hasExpanderDefinition($expanderName)) { - throw new InvalidArgumentException(sprintf("Definition for \"%s\" expander does not exists.", $expanderName)); + throw new InvalidArgumentException(sprintf('Definition for "%s" expander does not exists.', $expanderName)); } return $this->expanderDefinitions[$expanderName]; @@ -59,7 +59,7 @@ public function getExpanderDefinition(string $expanderName) : string public function initialize(ExpanderNode $expanderNode) : PatternExpander { if (!array_key_exists($expanderNode->getName(), $this->expanderDefinitions)) { - throw new UnknownExpanderException(sprintf("Unknown expander \"%s\"", $expanderNode->getName())); + throw new UnknownExpanderException(sprintf('Unknown expander "%s"', $expanderNode->getName())); } $reflection = new \ReflectionClass($this->expanderDefinitions[$expanderNode->getName()]); diff --git a/tests/LexerTest.php b/tests/LexerTest.php index c36d5976..17239ae4 100644 --- a/tests/LexerTest.php +++ b/tests/LexerTest.php @@ -48,12 +48,12 @@ public static function validNumberValuesProvider() [1, 1], [1.25, 1.25], [0, 0], - ["125", 125], - ["12.15", 12.15], + ['125', 125], + ['12.15', 12.15], [-10, -10], [-1.124, -1.124], - ["-10", -10], - ["-1.24", -1.24] + ['-10', -10], + ['-1.24', -1.24] ]; } @@ -72,10 +72,10 @@ public function test_boolean_values($value, $expectedValue) public static function validBooleanValuesProvider() { return [ - ["true", true], - ["false", false], - ["TRUE", true], - ["fAlSe", false] + ['true', true], + ['false', false], + ['TRUE', true], + ['fAlSe', false] ]; } @@ -94,9 +94,9 @@ public function test_null_values($value) public static function validNullValuesProvider() { return [ - ["null"], - ["NULL"], - ["NuLl"], + ['null'], + ['NULL'], + ['NuLl'], ]; } @@ -114,10 +114,10 @@ public function test_non_token_values($value) public static function validNonTokenValuesProvider() { return [ - ["@integer"], - ["integer@"], - ["test"], - ["@"] + ['@integer'], + ['integer@'], + ['test'], + ['@'] ]; } @@ -170,18 +170,18 @@ public function test_type_pattern($value) $lexer->setInput($value); $lexer->moveNext(); $this->assertEquals($lexer->lookahead['type'], Lexer::T_TYPE_PATTERN); - $this->assertEquals($lexer->lookahead['value'], trim($value, "@")); + $this->assertEquals($lexer->lookahead['value'], trim($value, '@')); } public static function validMatcherTypePatterns() { return [ - ["@string@"], - ["@boolean@"], - ["@integer@"], - ["@number@"], - ["@*@"], - ["@wildcard@"] + ['@string@'], + ['@boolean@'], + ['@integer@'], + ['@number@'], + ['@*@'], + ['@wildcard@'] ]; } @@ -200,15 +200,15 @@ public function test_expander_name($value, $expectedTokenValue) public static function validExpanderNamesProvider() { return [ - ["expanderName(", "expanderName"], - ["e(", "e"], - [".e(", "e"] + ['expanderName(', 'expanderName'], + ['e(', 'e'], + ['.e(', 'e'] ]; } public function test_ignore_whitespaces_between_parenthesis() { - $expectedTokens = ["type", "expander", "arg1", ",", 2, ",", "arg3", ",", 4, ")"]; + $expectedTokens = ['type', 'expander', 'arg1', ',', 2, ',', 'arg3', ',', 4, ')']; $lexer = new Lexer(); $lexer->setInput("@type@.expander( 'arg1', 2 ,'arg3',4)"); diff --git a/tests/Matcher/ArrayMatcherTest.php b/tests/Matcher/ArrayMatcherTest.php index fef8a0f1..2cadbff4 100644 --- a/tests/Matcher/ArrayMatcherTest.php +++ b/tests/Matcher/ArrayMatcherTest.php @@ -108,19 +108,19 @@ public function test_error_when_matching_fail() public function test_error_message_when_matching_non_array_value() { - $this->assertFalse($this->matcher->match(new \DateTime(), "@array@")); - $this->assertEquals($this->matcher->getError(), "object \"\\DateTime\" is not a valid array."); + $this->assertFalse($this->matcher->match(new \DateTime(), '@array@')); + $this->assertEquals($this->matcher->getError(), 'object "\\DateTime" is not a valid array.'); } public function test_matching_array_to_array_pattern() { - $this->assertTrue($this->matcher->match(["foo", "bar"], "@array@")); - $this->assertTrue($this->matcher->match(["foo"], "@array@.inArray(\"foo\")")); + $this->assertTrue($this->matcher->match(['foo', 'bar'], '@array@')); + $this->assertTrue($this->matcher->match(['foo'], '@array@.inArray("foo")')); $this->assertTrue($this->matcher->match( - ["foo", ["bar"]], + ['foo', ['bar']], [ - "@string@", - "@array@.inArray(\"bar\")" + '@string@', + '@array@.inArray("bar")' ] )); } @@ -163,7 +163,7 @@ public static function positiveMatchData() [$simpleArr, $simpleArrPattern], [[], []], [['foo' => null], ['foo' => null]], - [['foo' => null], ['foo' => "@null@"]], + [['foo' => null], ['foo' => '@null@']], [['key' => 'val'], ['key' => 'val']], [[1], [1]], [ @@ -226,7 +226,7 @@ public static function negativeMatchData() return [ [$simpleArr, $simpleDiff], - [["status" => "ok", "data" => [['foo']]], ["status" => "ok", "data" => []]], + [['status' => 'ok', 'data' => [['foo']]], ['status' => 'ok', 'data' => []]], [[1], []], [['key' => 'val'], ['key' => 'val2']], [[1], [2]], diff --git a/tests/Matcher/BooleanMatcherTest.php b/tests/Matcher/BooleanMatcherTest.php index 45d497a0..bee2225e 100644 --- a/tests/Matcher/BooleanMatcherTest.php +++ b/tests/Matcher/BooleanMatcherTest.php @@ -65,22 +65,22 @@ public function test_negative_match_description($value, $pattern, $error) public static function positiveCanMatchData() { return [ - ["@boolean@"] + ['@boolean@'] ]; } public static function positiveMatchData() { return [ - [true, "@boolean@"], + [true, '@boolean@'], ]; } public static function negativeCanMatchData() { return [ - ["@boolean"], - ["boolean"], + ['@boolean'], + ['boolean'], [1] ]; } @@ -88,18 +88,18 @@ public static function negativeCanMatchData() public static function negativeMatchData() { return [ - ["1", "@boolean@"], - [new \DateTime(), "@boolean@"] + ['1', '@boolean@'], + [new \DateTime(), '@boolean@'] ]; } public static function negativeMatchDescription() { return [ - [new \stdClass, "@boolean@", "object \"\\stdClass\" is not a valid boolean."], - [1.1, "@boolean@", "double \"1.1\" is not a valid boolean."], - ["true", "@string@", "string \"true\" is not a valid boolean."], - [['test'], "@boolean@", "array \"Array(1)\" is not a valid boolean."] + [new \stdClass, '@boolean@', 'object "\\stdClass" is not a valid boolean.'], + [1.1, '@boolean@', 'double "1.1" is not a valid boolean.'], + ['true', '@string@', 'string "true" is not a valid boolean.'], + [['test'], '@boolean@', 'array "Array(1)" is not a valid boolean.'] ]; } } diff --git a/tests/Matcher/DoubleMatcherTest.php b/tests/Matcher/DoubleMatcherTest.php index 6df50c27..e315ec7a 100644 --- a/tests/Matcher/DoubleMatcherTest.php +++ b/tests/Matcher/DoubleMatcherTest.php @@ -65,23 +65,23 @@ public function test_negative_match_description($value, $pattern, $error) public static function positiveCanMatchData() { return [ - ["@double@"] + ['@double@'] ]; } public static function positiveMatchData() { return [ - [10.1, "@double@"], - [10.1, "@double@.lowerThan(50.12).greaterThan(10)"], + [10.1, '@double@'], + [10.1, '@double@.lowerThan(50.12).greaterThan(10)'], ]; } public static function negativeCanMatchData() { return [ - ["@double"], - ["double"], + ['@double'], + ['double'], [1], ]; } @@ -89,21 +89,21 @@ public static function negativeCanMatchData() public static function negativeMatchData() { return [ - ["1", "@double@"], - [new \DateTime(), "@double@"], - [10, "@double@"], - [4.9, "@double@.greaterThan(5)"], - [4.9, "@double@.lowerThan(20).greaterThan(5)"], + ['1', '@double@'], + [new \DateTime(), '@double@'], + [10, '@double@'], + [4.9, '@double@.greaterThan(5)'], + [4.9, '@double@.lowerThan(20).greaterThan(5)'], ]; } public static function negativeMatchDescription() { return [ - [new \stdClass, "@integer@", "object \"\\stdClass\" is not a valid double."], - [25, "@integer@", "integer \"25\" is not a valid double."], - [false, "@integer@", "boolean \"false\" is not a valid double."], - [['test'], "@integer@", "array \"Array(1)\" is not a valid double."] + [new \stdClass, '@integer@', 'object "\\stdClass" is not a valid double.'], + [25, '@integer@', 'integer "25" is not a valid double.'], + [false, '@integer@', 'boolean "false" is not a valid double.'], + [['test'], '@integer@', 'array "Array(1)" is not a valid double.'] ]; } } diff --git a/tests/Matcher/ExpressionMatcherTest.php b/tests/Matcher/ExpressionMatcherTest.php index 9c39dcaf..9a4b10dc 100644 --- a/tests/Matcher/ExpressionMatcherTest.php +++ b/tests/Matcher/ExpressionMatcherTest.php @@ -76,7 +76,7 @@ public function test_negative_regex_matches($value, $pattern) public static function positiveCanMatchData() { return [ - ["expr(1 > 2)"], + ['expr(1 > 2)'], ["expr(value == 'foo')"], ]; } @@ -84,19 +84,19 @@ public static function positiveCanMatchData() public static function negativeCanMatchData() { return [ - ["@integer"], - ["expr("], - ["@string"], + ['@integer'], + ['expr('], + ['@string'], [new \stdClass], - [["foobar"]] + [['foobar']] ]; } public static function positiveMatchData() { return [ - [4, "expr(value > 2)"], - ["foo", "expr(value == 'foo')"], + [4, 'expr(value > 2)'], + ['foo', "expr(value == 'foo')"], [new \DateTime('2014-04-01'), "expr(value.format('Y-m-d') == '2014-04-01')"] ]; } @@ -104,15 +104,15 @@ public static function positiveMatchData() public static function negativeMatchData() { return [ - [4, "expr(value < 2)"], - ["foo", "expr(value != 'foo')"], + [4, 'expr(value < 2)'], + ['foo', "expr(value != 'foo')"], ]; } public static function negativeMatchDescription() { return [ - [4, "expr(value < 2)", "\"expr(value < 2)\" expression fails for value \"4\"."], + [4, 'expr(value < 2)', '"expr(value < 2)" expression fails for value "4".'], [ new \DateTime('2014-04-01'), "expr(value.format('Y-m-d') == '2014-04-02')", diff --git a/tests/Matcher/IntegerMatcherTest.php b/tests/Matcher/IntegerMatcherTest.php index fbaf2bbf..390da7e1 100644 --- a/tests/Matcher/IntegerMatcherTest.php +++ b/tests/Matcher/IntegerMatcherTest.php @@ -65,23 +65,23 @@ public function test_negative_match_description($value, $pattern, $error) public static function positiveCanMatchData() { return [ - ["@integer@"] + ['@integer@'] ]; } public static function positiveMatchData() { return [ - [10, "@integer@"], - [10, "@integer@.lowerThan(50).greaterThan(1)"], + [10, '@integer@'], + [10, '@integer@.lowerThan(50).greaterThan(1)'], ]; } public static function negativeCanMatchData() { return [ - ["@integer"], - ["integer"], + ['@integer'], + ['integer'], [1] ]; } @@ -89,18 +89,18 @@ public static function negativeCanMatchData() public static function negativeMatchData() { return [ - ["1", "@integer@"], - [new \DateTime(), "@integer@"] + ['1', '@integer@'], + [new \DateTime(), '@integer@'] ]; } public static function negativeMatchDescription() { return [ - [new \stdClass, "@integer@", "object \"\\stdClass\" is not a valid integer."], - [1.1, "@integer@", "double \"1.1\" is not a valid integer."], - [false, "@integer@", "boolean \"false\" is not a valid integer."], - [['test'], "@integer@", "array \"Array(1)\" is not a valid integer."] + [new \stdClass, '@integer@', 'object "\\stdClass" is not a valid integer.'], + [1.1, '@integer@', 'double "1.1" is not a valid integer.'], + [false, '@integer@', 'boolean "false" is not a valid integer.'], + [['test'], '@integer@', 'array "Array(1)" is not a valid integer.'] ]; } } diff --git a/tests/Matcher/NullMatcherTest.php b/tests/Matcher/NullMatcherTest.php index 66a2c4cb..b876d1c3 100644 --- a/tests/Matcher/NullMatcherTest.php +++ b/tests/Matcher/NullMatcherTest.php @@ -65,7 +65,7 @@ public function test_negative_match_description($value, $pattern, $error) public static function positiveCanMatchData() { return [ - ["@null@"], + ['@null@'], [null] ]; } @@ -73,7 +73,7 @@ public static function positiveCanMatchData() public static function positiveMatchData() { return [ - [null, "@null@"], + [null, '@null@'], [null, null], ]; } @@ -81,8 +81,8 @@ public static function positiveMatchData() public static function negativeCanMatchData() { return [ - ["@null"], - ["null"], + ['@null'], + ['null'], [0] ]; } @@ -90,19 +90,19 @@ public static function negativeCanMatchData() public static function negativeMatchData() { return [ - ["null", "@null@"], - [0, "@null@"] + ['null', '@null@'], + [0, '@null@'] ]; } public static function negativeMatchDescription() { return [ - ["test", "@null@", "string \"test\" does not match null."], - [new \stdClass, "@null@", "object \"\\stdClass\" does not match null."], - [1.1, "@null@", "double \"1.1\" does not match null."], - [false, "@null@", "boolean \"false\" does not match null."], - [1, "@null@", "integer \"1\" does not match null."] + ['test', '@null@', 'string "test" does not match null.'], + [new \stdClass, '@null@', 'object "\\stdClass" does not match null.'], + [1.1, '@null@', 'double "1.1" does not match null.'], + [false, '@null@', 'boolean "false" does not match null.'], + [1, '@null@', 'integer "1" does not match null.'] ]; } } diff --git a/tests/Matcher/NumberMatcherTest.php b/tests/Matcher/NumberMatcherTest.php index f44d1b02..591d194b 100644 --- a/tests/Matcher/NumberMatcherTest.php +++ b/tests/Matcher/NumberMatcherTest.php @@ -65,25 +65,25 @@ public function test_negative_match_description($value, $pattern, $error) public static function positiveCanMatchData() { return [ - ["@number@"] + ['@number@'] ]; } public static function positiveMatchData() { return [ - [10.1, "@number@"], - [10, "@number@"], - ["25", "@number@"], - [10, "@number@.lowerThan(50).greaterThan(1)"], + [10.1, '@number@'], + [10, '@number@'], + ['25', '@number@'], + [10, '@number@.lowerThan(50).greaterThan(1)'], ]; } public static function negativeCanMatchData() { return [ - ["@number"], - ["number"], + ['@number'], + ['number'], [1] ]; } @@ -91,17 +91,17 @@ public static function negativeCanMatchData() public static function negativeMatchData() { return [ - [["test"], "@number@"], - [new \DateTime(), "@number@"], + [['test'], '@number@'], + [new \DateTime(), '@number@'], ]; } public static function negativeMatchDescription() { return [ - [new \stdClass, "@number@", "object \"\\stdClass\" is not a valid number."], - [false, "@number@", "boolean \"false\" is not a valid number."], - [['test'], "@number@", "array \"Array(1)\" is not a valid number."] + [new \stdClass, '@number@', 'object "\\stdClass" is not a valid number.'], + [false, '@number@', 'boolean "false" is not a valid number.'], + [['test'], '@number@', 'array "Array(1)" is not a valid number.'] ]; } } diff --git a/tests/Matcher/OrMatcherTest.php b/tests/Matcher/OrMatcherTest.php index b2a5f7aa..a9098ab3 100644 --- a/tests/Matcher/OrMatcherTest.php +++ b/tests/Matcher/OrMatcherTest.php @@ -144,7 +144,7 @@ public static function negativeMatchData() return [ [$simpleArr, $simpleDiff], - [["status" => "ok", "data" => [['foo']]], ["status" => "ok", "data" => []]], + [['status' => 'ok', 'data' => [['foo']]], ['status' => 'ok', 'data' => []]], [[1], []], [['key' => 'val'], ['key' => 'val2']], [[1], [2]], diff --git a/tests/Matcher/Pattern/Expander/ContainsTest.php b/tests/Matcher/Pattern/Expander/ContainsTest.php index 3fbc7c5d..f0113751 100644 --- a/tests/Matcher/Pattern/Expander/ContainsTest.php +++ b/tests/Matcher/Pattern/Expander/ContainsTest.php @@ -21,10 +21,10 @@ public function test_matching_values_ignore_case($needle, $haystack, $expectedRe public static function examplesIgnoreCaseProvider() { return [ - ["ipsum", "lorem ipsum", true], - ["wor", "this is my hello world string", true], - ["lol", "lorem ipsum", false], - ["NO", "norbert", false] + ['ipsum', 'lorem ipsum', true], + ['wor', 'this is my hello world string', true], + ['lol', 'lorem ipsum', false], + ['NO', 'norbert', false] ]; } @@ -40,10 +40,10 @@ public function test_matching_values($needle, $haystack, $expectedResult) public static function examplesProvider() { return [ - ["IpSum", "lorem ipsum", true], - ["wor", "this is my hello WORLD string", true], - ["lol", "LOREM ipsum", false], - ["NO", "NORBERT", true] + ['IpSum', 'lorem ipsum', true], + ['wor', 'this is my hello WORLD string', true], + ['lol', 'LOREM ipsum', false], + ['NO', 'NORBERT', true] ]; } @@ -60,8 +60,8 @@ public function test_error_when_matching_fail($string, $value, $errorMessage) public static function invalidCasesProvider() { return [ - ["ipsum", "hello world", "String \"hello world\" doesn't contains \"ipsum\"."], - ["lorem", new \DateTime(), "Contains expander require \"string\", got \"\\DateTime\"."], + ['ipsum', 'hello world', "String \"hello world\" doesn't contains \"ipsum\"."], + ['lorem', new \DateTime(), 'Contains expander require "string", got "\\DateTime".'], ]; } } diff --git a/tests/Matcher/Pattern/Expander/CountTest.php b/tests/Matcher/Pattern/Expander/CountTest.php index f8cd9722..153f25f6 100644 --- a/tests/Matcher/Pattern/Expander/CountTest.php +++ b/tests/Matcher/Pattern/Expander/CountTest.php @@ -21,8 +21,8 @@ public function test_matching_values($needle, $haystack, $expectedResult) public static function examplesProvider() { return [ - [1, ["ipsum"], true], - [2, ["foo", 1], true], + [1, ['ipsum'], true], + [2, ['foo', 1], true], ]; } @@ -39,8 +39,8 @@ public function test_error_when_matching_fail($boundary, $value, $errorMessage) public static function invalidCasesProvider() { return [ - [2, [1, 2, 3], "Expected count of Array(3) is 2."], - [2, new \DateTime(), "Count expander require \"array\", got \"\\DateTime\"."], + [2, [1, 2, 3], 'Expected count of Array(3) is 2.'], + [2, new \DateTime(), 'Count expander require "array", got "\\DateTime".'], ]; } } diff --git a/tests/Matcher/Pattern/Expander/EndsWithTest.php b/tests/Matcher/Pattern/Expander/EndsWithTest.php index fc04d018..b00043d5 100644 --- a/tests/Matcher/Pattern/Expander/EndsWithTest.php +++ b/tests/Matcher/Pattern/Expander/EndsWithTest.php @@ -21,11 +21,11 @@ public function test_examples_not_ignoring_case($stringEnding, $value, $expected public static function notIgnoringCaseExamplesProvider() { return [ - ["ipsum", "lorem ipsum", true], - ["ipsum", "Lorem IPSUM", false], - ["", "lorem ipsum", true], - ["ipsum", "lorem ipsum", true], - ["lorem", "lorem ipsum", false] + ['ipsum', 'lorem ipsum', true], + ['ipsum', 'Lorem IPSUM', false], + ['', 'lorem ipsum', true], + ['ipsum', 'lorem ipsum', true], + ['lorem', 'lorem ipsum', false] ]; } @@ -41,9 +41,9 @@ public function test_examples_ignoring_case($stringEnding, $value, $expectedResu public static function ignoringCaseExamplesProvider() { return [ - ["Ipsum", "Lorem ipsum", true], - ["iPsUm", "lorem ipsum", true], - ["IPSUM", "LoReM ipsum", true], + ['Ipsum', 'Lorem ipsum', true], + ['iPsUm', 'lorem ipsum', true], + ['IPSUM', 'LoReM ipsum', true], ]; } @@ -60,8 +60,8 @@ public function test_error_when_matching_fail($stringBeginning, $value, $errorMe public static function invalidCasesProvider() { return [ - ["ipsum", "ipsum lorem", "string \"ipsum lorem\" doesn't ends with string \"ipsum\"."], - ["lorem", new \DateTime(), "EndsWith expander require \"string\", got \"\\DateTime\"."], + ['ipsum', 'ipsum lorem', "string \"ipsum lorem\" doesn't ends with string \"ipsum\"."], + ['lorem', new \DateTime(), 'EndsWith expander require "string", got "\\DateTime".'], ]; } } diff --git a/tests/Matcher/Pattern/Expander/GreaterThanTest.php b/tests/Matcher/Pattern/Expander/GreaterThanTest.php index 237b74de..cb8fcd69 100644 --- a/tests/Matcher/Pattern/Expander/GreaterThanTest.php +++ b/tests/Matcher/Pattern/Expander/GreaterThanTest.php @@ -25,7 +25,7 @@ public static function examplesProvider() [-20, -10.5, true], [10, 1, false], [1, 1, false], - [10, "20", true] + [10, '20', true] ]; } @@ -42,9 +42,9 @@ public function test_error_when_matching_fail($boundary, $value, $errorMessage) public static function invalidCasesProvider() { return [ - [1, "ipsum lorem", "Value \"ipsum lorem\" is not a valid number."], - [10, 5, "Value \"5\" is not greater than \"10\"."], - [5, 5, "Value \"5\" is not greater than \"5\"."], + [1, 'ipsum lorem', 'Value "ipsum lorem" is not a valid number.'], + [10, 5, 'Value "5" is not greater than "10".'], + [5, 5, 'Value "5" is not greater than "5".'], ]; } } diff --git a/tests/Matcher/Pattern/Expander/InArrayTest.php b/tests/Matcher/Pattern/Expander/InArrayTest.php index 12db3136..ea73fe06 100644 --- a/tests/Matcher/Pattern/Expander/InArrayTest.php +++ b/tests/Matcher/Pattern/Expander/InArrayTest.php @@ -21,9 +21,9 @@ public function test_matching_values($needle, $haystack, $expectedResult) public static function examplesProvider() { return [ - ["ipsum", ["ipsum"], true], - [1, ["foo", 1], true], - [["foo" => "bar"], [["foo" => "bar"]], true], + ['ipsum', ['ipsum'], true], + [1, ['foo', 1], true], + [['foo' => 'bar'], [['foo' => 'bar']], true], ]; } @@ -40,8 +40,8 @@ public function test_error_when_matching_fail($boundary, $value, $errorMessage) public static function invalidCasesProvider() { return [ - ["ipsum", ["ipsum lorem"], "Array(1) doesn't have \"ipsum\" element."], - ["lorem", new \DateTime(), "InArray expander require \"array\", got \"\\DateTime\"."], + ['ipsum', ['ipsum lorem'], "Array(1) doesn't have \"ipsum\" element."], + ['lorem', new \DateTime(), 'InArray expander require "array", got "\\DateTime".'], ]; } } diff --git a/tests/Matcher/Pattern/Expander/IsDateTimeTest.php b/tests/Matcher/Pattern/Expander/IsDateTimeTest.php index 10459932..0bf74822 100644 --- a/tests/Matcher/Pattern/Expander/IsDateTimeTest.php +++ b/tests/Matcher/Pattern/Expander/IsDateTimeTest.php @@ -21,10 +21,10 @@ public function test_dates($date, $expectedResult) public static function examplesDatesProvider() { return [ - ["201-20-44", false], - ["2012-10-11", true], - ["invalid", false], - ["Monday, 15-Aug-2005 15:52:01 UTC", true] + ['201-20-44', false], + ['2012-10-11', true], + ['invalid', false], + ['Monday, 15-Aug-2005 15:52:01 UTC', true] ]; } } diff --git a/tests/Matcher/Pattern/Expander/IsEmailTest.php b/tests/Matcher/Pattern/Expander/IsEmailTest.php index 3f34e76f..a5a4cdc0 100644 --- a/tests/Matcher/Pattern/Expander/IsEmailTest.php +++ b/tests/Matcher/Pattern/Expander/IsEmailTest.php @@ -21,10 +21,10 @@ public function test_emails($email, $expectedResult) public static function examplesEmailsProvider() { return [ - ["valid@email.com", true], - ["valid+12345@email.com", true], - ["...@domain.com", false], - ["2222----###@domain.co", true] + ['valid@email.com', true], + ['valid+12345@email.com', true], + ['...@domain.com', false], + ['2222----###@domain.co', true] ]; } } diff --git a/tests/Matcher/Pattern/Expander/IsNotEmptyTest.php b/tests/Matcher/Pattern/Expander/IsNotEmptyTest.php index 34d40618..d935fcf2 100644 --- a/tests/Matcher/Pattern/Expander/IsNotEmptyTest.php +++ b/tests/Matcher/Pattern/Expander/IsNotEmptyTest.php @@ -21,10 +21,10 @@ public function test_examples_not_ignoring_case($value, $expectedResult) public static function examplesProvider() { return [ - ["lorem", true], - ["0", true], + ['lorem', true], + ['0', true], [new \DateTime(), true], - ["", false], + ['', false], [null, false], [[], false] ]; diff --git a/tests/Matcher/Pattern/Expander/IsUrlTest.php b/tests/Matcher/Pattern/Expander/IsUrlTest.php index 81588273..90a79906 100644 --- a/tests/Matcher/Pattern/Expander/IsUrlTest.php +++ b/tests/Matcher/Pattern/Expander/IsUrlTest.php @@ -21,13 +21,13 @@ public function test_urls($url, $expectedResult) public static function examplesUrlsProvider() { return [ - ["http://example.com/test.html", true], - ["https://example.com/test.html", true], - ["https://example.com/user/{id}/", true], - ["mailto:email@example.com", true], - ["//example.com/test/", false], - ["example", false], - ["", false] + ['http://example.com/test.html', true], + ['https://example.com/test.html', true], + ['https://example.com/user/{id}/', true], + ['mailto:email@example.com', true], + ['//example.com/test/', false], + ['example', false], + ['', false] ]; } } diff --git a/tests/Matcher/Pattern/Expander/LowerThanTest.php b/tests/Matcher/Pattern/Expander/LowerThanTest.php index cd09a967..e72b73b7 100644 --- a/tests/Matcher/Pattern/Expander/LowerThanTest.php +++ b/tests/Matcher/Pattern/Expander/LowerThanTest.php @@ -41,9 +41,9 @@ public function test_error_when_matching_fail($boundary, $value, $errorMessage) public static function invalidCasesProvider() { return [ - [1, "ipsum lorem", "Value \"ipsum lorem\" is not a valid number."], - [5, 10, "Value \"10\" is not lower than \"5\"."], - [5, 5, "Value \"5\" is not lower than \"5\"."], + [1, 'ipsum lorem', 'Value "ipsum lorem" is not a valid number.'], + [5, 10, 'Value "10" is not lower than "5".'], + [5, 5, 'Value "5" is not lower than "5".'], ]; } } diff --git a/tests/Matcher/Pattern/Expander/OneOfTest.php b/tests/Matcher/Pattern/Expander/OneOfTest.php index 94992222..a433015a 100644 --- a/tests/Matcher/Pattern/Expander/OneOfTest.php +++ b/tests/Matcher/Pattern/Expander/OneOfTest.php @@ -25,29 +25,29 @@ public function test_not_enough_arguments() */ public function test_invalid_argument_types() { - $expander = new OneOf("arg1", ["test"]); + $expander = new OneOf('arg1', ['test']); } public function test_positive_match() { $expander = new OneOf( - new Contains("lorem"), - new Contains("test") + new Contains('lorem'), + new Contains('test') ); - $this->assertTrue($expander->match("lorem ipsum")); + $this->assertTrue($expander->match('lorem ipsum')); } public function test_negative_match() { $expander = new OneOf( - new Contains("lorem"), - new Contains("test") + new Contains('lorem'), + new Contains('test') ); - $this->assertFalse($expander->match("this is random stiring")); + $this->assertFalse($expander->match('this is random stiring')); $this->assertSame( - "Any expander available in OneOf expander does not match \"this is random stiring\".", + 'Any expander available in OneOf expander does not match "this is random stiring".', $expander->getError() ); } diff --git a/tests/Matcher/Pattern/Expander/RepeatTest.php b/tests/Matcher/Pattern/Expander/RepeatTest.php index 520b17a5..1427120f 100644 --- a/tests/Matcher/Pattern/Expander/RepeatTest.php +++ b/tests/Matcher/Pattern/Expander/RepeatTest.php @@ -23,20 +23,20 @@ public static function examplesProvider() $jsonPattern = '{"name": "@string@", "activated": "@boolean@"}'; $jsonTest = [ - ["name" => "toto", "activated" => true], - ["name" => "titi", "activated" => false], - ["name" => "tate", "activated" => true] + ['name' => 'toto', 'activated' => true], + ['name' => 'titi', 'activated' => false], + ['name' => 'tate', 'activated' => true] ]; - $scalarPattern = "@string@"; + $scalarPattern = '@string@'; $scalarTest = [ - "toto", - "titi", - "tata" + 'toto', + 'titi', + 'tata' ]; $strictTest = [ - ["name" => "toto", "activated" => true, "offset" => "offset"] + ['name' => 'toto', 'activated' => true, 'offset' => 'offset'] ]; return [ @@ -61,22 +61,22 @@ public static function invalidCasesProvider() $pattern = '{"name": "@string@", "activated": "@boolean@"}'; $valueTest = [ - ["name" => 1, "activated" => "yes"] + ['name' => 1, 'activated' => 'yes'] ]; $keyTest = [ - ["offset" => true, "foe" => "bar"] + ['offset' => true, 'foe' => 'bar'] ]; $strictTest = [ - ["name" => 1, "activated" => "yes", "offset" => true] + ['name' => 1, 'activated' => 'yes', 'offset' => true] ]; return [ [$pattern, $valueTest, 'Repeat expander, entry n°0, key "name", find error : integer "1" is not a valid string.'], [$pattern, $keyTest, 'Repeat expander, entry n°0, require "array" to have key "name".'], [$pattern, $strictTest, 'Repeat expander expect to have 2 keys in array but get : 3'], - [$pattern, "", 'Repeat expander require "array", got "".'] + [$pattern, '', 'Repeat expander require "array", got "".'] ]; } } diff --git a/tests/Matcher/Pattern/Expander/StartsWithTest.php b/tests/Matcher/Pattern/Expander/StartsWithTest.php index ab711299..3caec5c2 100644 --- a/tests/Matcher/Pattern/Expander/StartsWithTest.php +++ b/tests/Matcher/Pattern/Expander/StartsWithTest.php @@ -21,11 +21,11 @@ public function test_examples_not_ignoring_case($stringBeginning, $value, $expec public static function notIgnoringCaseExamplesProvider() { return [ - ["lorem", "lorem ipsum", true], - ["lorem", "Lorem ipsum", false], - ["", "lorem ipsum", true], - ["lorem", "lorem ipsum", true], - ["ipsum", "lorem ipsum", false] + ['lorem', 'lorem ipsum', true], + ['lorem', 'Lorem ipsum', false], + ['', 'lorem ipsum', true], + ['lorem', 'lorem ipsum', true], + ['ipsum', 'lorem ipsum', false] ]; } @@ -41,9 +41,9 @@ public function test_examples_ignoring_case($stringBeginning, $value, $expectedR public static function ignoringCaseExamplesProvider() { return [ - ["lorem", "Lorem ipsum", true], - ["Lorem", "lorem ipsum", true], - ["LOREM", "LoReM ipsum", true], + ['lorem', 'Lorem ipsum', true], + ['Lorem', 'lorem ipsum', true], + ['LOREM', 'LoReM ipsum', true], ]; } @@ -60,8 +60,8 @@ public function test_error_when_matching_fail($stringBeginning, $value, $errorMe public static function invalidCasesProvider() { return [ - ["lorem", "ipsum lorem", "string \"ipsum lorem\" doesn't starts with string \"lorem\"."], - ["lorem", new \DateTime(), "StartsWith expander require \"string\", got \"\\DateTime\"."], + ['lorem', 'ipsum lorem', "string \"ipsum lorem\" doesn't starts with string \"lorem\"."], + ['lorem', new \DateTime(), 'StartsWith expander require "string", got "\\DateTime".'], ]; } } diff --git a/tests/Matcher/Pattern/PatternTest.php b/tests/Matcher/Pattern/PatternTest.php index 7af471c5..6f502775 100644 --- a/tests/Matcher/Pattern/PatternTest.php +++ b/tests/Matcher/Pattern/PatternTest.php @@ -37,11 +37,11 @@ public function test_has_expander($expander, $expectedResult) public static function examplesProvider() { return [ - ["isEmail", true], - ["isEmpty", true], - ["optional", true], - ["isUrl", false], - ["non existing expander", false], + ['isEmail', true], + ['isEmpty', true], + ['optional', true], + ['isUrl', false], + ['non existing expander', false], ]; } } diff --git a/tests/Matcher/Pattern/RegexConverterTest.php b/tests/Matcher/Pattern/RegexConverterTest.php index 0f04e885..7d695b10 100644 --- a/tests/Matcher/Pattern/RegexConverterTest.php +++ b/tests/Matcher/Pattern/RegexConverterTest.php @@ -25,6 +25,6 @@ public function setUp() */ public function test_convert_unknown_type() { - $this->converter->toRegex(new TypePattern("not_a_type")); + $this->converter->toRegex(new TypePattern('not_a_type')); } } diff --git a/tests/Matcher/ScalarMatcherTest.php b/tests/Matcher/ScalarMatcherTest.php index 952ef483..50587310 100644 --- a/tests/Matcher/ScalarMatcherTest.php +++ b/tests/Matcher/ScalarMatcherTest.php @@ -58,10 +58,10 @@ public function test_negative_match_description($value, $pattern, $error) public static function negativeMatches() { return [ - [false, "false"], + [false, 'false'], [false, 0], [true, 1], - ["array", []], + ['array', []], ]; } @@ -69,7 +69,7 @@ public static function positiveMatches() { return [ [1, 1], - ["michal", "michal"], + ['michal', 'michal'], [false, false], [6.66, 6.66], ]; @@ -79,7 +79,7 @@ public static function positiveCanMatches() { return [ [1], - ["michal"], + ['michal'], [true], [false], [6.66], @@ -97,10 +97,10 @@ public static function negativeCanMatches() public static function negativeMatchDescription() { return [ - ["test", "norbert", "\"test\" does not match \"norbert\"."], - [new \stdClass, 1, "\"\\stdClass\" does not match \"1\"."], - [1.1, false, "\"1.1\" does not match \"false\"."], - [false, ['foo', 'bar'], "\"false\" does not match \"Array(2)\"."], + ['test', 'norbert', '"test" does not match "norbert".'], + [new \stdClass, 1, '"\\stdClass" does not match "1".'], + [1.1, false, '"1.1" does not match "false".'], + [false, ['foo', 'bar'], '"false" does not match "Array(2)".'], ]; } } diff --git a/tests/Matcher/StringMatcherTest.php b/tests/Matcher/StringMatcherTest.php index 42a65318..f0a90ee4 100644 --- a/tests/Matcher/StringMatcherTest.php +++ b/tests/Matcher/StringMatcherTest.php @@ -65,26 +65,26 @@ public function test_negative_match_description($value, $pattern, $error) public static function positiveCanMatchData() { return [ - ["@string@"] + ['@string@'] ]; } public static function positiveMatchData() { return [ - ["lorem ipsum", "@string@"], - ["lorem ipsum", "@string@.isNotEmpty()"], - ["lorem ipsum", "@string@.startsWith('lorem')"], - ["lorem ipsum", "@string@.endsWith('ipsum')"], - ["lorem ipsum dolor", "@string@.startsWith('lorem').contains('ipsum').endsWith('dolor')"], + ['lorem ipsum', '@string@'], + ['lorem ipsum', '@string@.isNotEmpty()'], + ['lorem ipsum', "@string@.startsWith('lorem')"], + ['lorem ipsum', "@string@.endsWith('ipsum')"], + ['lorem ipsum dolor', "@string@.startsWith('lorem').contains('ipsum').endsWith('dolor')"], ]; } public static function negativeCanMatchData() { return [ - ["@string"], - ["string"], + ['@string'], + ['string'], [1] ]; } @@ -92,19 +92,19 @@ public static function negativeCanMatchData() public static function negativeMatchData() { return [ - [1, "@string@"], - [0, "@string@"] + [1, '@string@'], + [0, '@string@'] ]; } public static function negativeMatchDescription() { return [ - [new \stdClass, "@string@", "object \"\\stdClass\" is not a valid string."], - [1.1, "@integer@", "double \"1.1\" is not a valid string."], - [false, "@double@", "boolean \"false\" is not a valid string."], - [1, "@array@", "integer \"1\" is not a valid string."], - ["lorem ipsum", "@array@.startsWith('ipsum')", "string \"lorem ipsum\" doesn't starts with string \"ipsum\"."] + [new \stdClass, '@string@', 'object "\\stdClass" is not a valid string.'], + [1.1, '@integer@', 'double "1.1" is not a valid string.'], + [false, '@double@', 'boolean "false" is not a valid string.'], + [1, '@array@', 'integer "1" is not a valid string.'], + ['lorem ipsum', "@array@.startsWith('ipsum')", "string \"lorem ipsum\" doesn't starts with string \"ipsum\"."] ]; } } diff --git a/tests/Matcher/TextMatcherTest.php b/tests/Matcher/TextMatcherTest.php index 160e229b..7318ec9b 100644 --- a/tests/Matcher/TextMatcherTest.php +++ b/tests/Matcher/TextMatcherTest.php @@ -83,29 +83,29 @@ public function test_ignore_valid_xml_patterns() public function test_error_when_unsupported_type_pattern_used() { - $pattern = "lorem ipsum @null@ bla bla"; - $value = "lorem ipsum bla bla"; + $pattern = 'lorem ipsum @null@ bla bla'; + $value = 'lorem ipsum bla bla'; $this->assertFalse($this->matcher->match($value, $pattern)); - $this->assertSame("Type pattern \"@null@\" is not supported by TextMatcher.", $this->matcher->getError()); + $this->assertSame('Type pattern "@null@" is not supported by TextMatcher.', $this->matcher->getError()); } public function matchingData() { return [ [ - "lorem ipsum lol lorem 24 dolorem", - "lorem ipsum @string@.startsWith(\"lo\") lorem @number@ dolorem", + 'lorem ipsum lol lorem 24 dolorem', + 'lorem ipsum @string@.startsWith("lo") lorem @number@ dolorem', true ], [ - "lorem ipsum 24 dolorem", - "lorem ipsum @integer@", + 'lorem ipsum 24 dolorem', + 'lorem ipsum @integer@', false ], [ - "/users/12345/active", - "/users/@integer@.greaterThan(0)/active", + '/users/12345/active', + '/users/@integer@.greaterThan(0)/active', true ] ]; diff --git a/tests/Matcher/UuidMatcherTest.php b/tests/Matcher/UuidMatcherTest.php index 31192103..86fa2357 100644 --- a/tests/Matcher/UuidMatcherTest.php +++ b/tests/Matcher/UuidMatcherTest.php @@ -64,26 +64,26 @@ public function test_negative_match_description($value, $pattern, $error) public static function positiveCanMatchData() { return [ - ["@uuid@"], + ['@uuid@'], ]; } public static function positiveMatchData() { return [ - ["21627164-acb7-11e6-80f5-76304dec7eb7", "@uuid@"], - ["d9c04bc2-173f-2cb7-ad4e-e4ca3b2c273f", "@uuid@"], - ["7b368038-a5ca-3aa3-b0db-1177d1761c9e", "@uuid@"], - ["9f4db639-0e87-4367-9beb-d64e3f42ae18", "@uuid@"], - ["1f2b1a18-81a0-5685-bca7-f23022ed7c7b", "@uuid@"], + ['21627164-acb7-11e6-80f5-76304dec7eb7', '@uuid@'], + ['d9c04bc2-173f-2cb7-ad4e-e4ca3b2c273f', '@uuid@'], + ['7b368038-a5ca-3aa3-b0db-1177d1761c9e', '@uuid@'], + ['9f4db639-0e87-4367-9beb-d64e3f42ae18', '@uuid@'], + ['1f2b1a18-81a0-5685-bca7-f23022ed7c7b', '@uuid@'], ]; } public static function negativeCanMatchData() { return [ - ["@uuid"], - ["uuid"], + ['@uuid'], + ['uuid'], [1], ]; } @@ -91,27 +91,27 @@ public static function negativeCanMatchData() public static function negativeMatchData() { return [ - [1, "@uuid@"], - [0, "@uuid@"], - ["9f4d-b639-0e87-4367-9beb-d64e3f42ae18", "@uuid@"], - ["9f4db639-0e87-4367-9beb-d64e3f42ae1", "@uuid@"], - ["9f4db639-0e87-4367-9beb-d64e3f42ae181", "@uuid@"], - ["9f4db6390e8743679bebd64e3f42ae18", "@uuid@"], - ["9f4db6390e87-4367-9beb-d64e-3f42ae18", "@uuid@"], - ["9f4db639-0e87-4367-9beb-d64e3f42ae1g", "@uuid@"], - ["9f4db639-0e87-0367-9beb-d64e3f42ae18", "@uuid@"], + [1, '@uuid@'], + [0, '@uuid@'], + ['9f4d-b639-0e87-4367-9beb-d64e3f42ae18', '@uuid@'], + ['9f4db639-0e87-4367-9beb-d64e3f42ae1', '@uuid@'], + ['9f4db639-0e87-4367-9beb-d64e3f42ae181', '@uuid@'], + ['9f4db6390e8743679bebd64e3f42ae18', '@uuid@'], + ['9f4db6390e87-4367-9beb-d64e-3f42ae18', '@uuid@'], + ['9f4db639-0e87-4367-9beb-d64e3f42ae1g', '@uuid@'], + ['9f4db639-0e87-0367-9beb-d64e3f42ae18', '@uuid@'], ]; } public static function negativeMatchDescription() { return [ - [new \stdClass, "@uuid@", "object \"\\stdClass\" is not a valid UUID: not a string."], - [1.1, "@uuid@", "double \"1.1\" is not a valid UUID: not a string."], - [false, "@uuid@", "boolean \"false\" is not a valid UUID: not a string."], - [1, "@uuid@", "integer \"1\" is not a valid UUID: not a string."], - ["lorem ipsum", "@uuid@", "string \"lorem ipsum\" is not a valid UUID: invalid format."], - ["9f4db639-0e87-4367-9beb-d64e3f42ae1z", "@uuid@", "string \"9f4db639-0e87-4367-9beb-d64e3f42ae1z\" is not a valid UUID: invalid format."], + [new \stdClass, '@uuid@', 'object "\\stdClass" is not a valid UUID: not a string.'], + [1.1, '@uuid@', 'double "1.1" is not a valid UUID: not a string.'], + [false, '@uuid@', 'boolean "false" is not a valid UUID: not a string.'], + [1, '@uuid@', 'integer "1" is not a valid UUID: not a string.'], + ['lorem ipsum', '@uuid@', 'string "lorem ipsum" is not a valid UUID: invalid format.'], + ['9f4db639-0e87-4367-9beb-d64e3f42ae1z', '@uuid@', 'string "9f4db639-0e87-4367-9beb-d64e3f42ae1z" is not a valid UUID: invalid format.'], ]; } } diff --git a/tests/Matcher/WildcardMatcherTest.php b/tests/Matcher/WildcardMatcherTest.php index cf061a64..5703111d 100644 --- a/tests/Matcher/WildcardMatcherTest.php +++ b/tests/Matcher/WildcardMatcherTest.php @@ -37,11 +37,11 @@ public function test_negative_can_match() public static function data() { return [ - ["@integer@"], - ["foobar"], + ['@integer@'], + ['foobar'], [true], [6.66], - [["bar"]], + [['bar']], [new \stdClass], ]; } @@ -49,8 +49,8 @@ public static function data() public static function positivePatterns() { return [ - ["@*@"], - ["@wildcard@"], + ['@*@'], + ['@wildcard@'], ]; } } diff --git a/tests/MatcherTest.php b/tests/MatcherTest.php index 5c3cf669..8e56b9cc 100644 --- a/tests/MatcherTest.php +++ b/tests/MatcherTest.php @@ -275,7 +275,7 @@ public function test_matcher_with_xml_including_optional_node() public function test_text_matcher() { - $value = "lorem ipsum 1234 random text"; + $value = 'lorem ipsum 1234 random text'; $pattern = "@string@.startsWith('lo') ipsum @number@.greaterThan(10) random text"; $this->assertTrue($this->matcher->match($value, $pattern)); $this->assertTrue(PHPMatcher::match($value, $pattern)); @@ -349,29 +349,29 @@ public function scalarValueExamples() public static function expanderExamples() { return [ - ["lorem ipsum", "@string@.startsWith(\"lorem\")", true], - ["lorem ipsum", "@string@.startsWith(\"LOREM\", true)", true], - ["lorem ipsum", "@string@.endsWith(\"ipsum\")", true], - ["lorem ipsum", "@string@.endsWith(\"IPSUM\", true)", true], - ["lorem ipsum", "@string@.contains(\"lorem\")", true], - ["norbert@coduo.pl", "@string@.isEmail()", true], - ["lorem ipsum", "@string@.isEmail()", false], - ["http://coduo.pl/", "@string@.isUrl()", true], - ["lorem ipsum", "@string@.isUrl()", false], - ["2014-08-19", "@string@.isDateTime()", true], - [100, "@integer@.lowerThan(101).greaterThan(10)", true], - ["", "@string@.isNotEmpty()", false], - ["lorem ipsum", "@string@.isNotEmpty()", true], - ["", "@string@.isEmpty()", true], - [["foo", "bar"], "@array@.inArray(\"bar\")", true], - [[], "@array@.isEmpty()", true], - [['foo'], "@array@.isEmpty()", false], - [[1, 2, 3], "@array@.count(3)", true], - [[1, 2, 3], "@array@.count(4)", false], - ["lorem ipsum", "@string@.oneOf(contains(\"lorem\"), contains(\"test\"))", true], - ["lorem ipsum", "@string@.oneOf(contains(\"lorem\"), contains(\"test\")).endsWith(\"ipsum\")", true], - ["lorem ipsum", "@string@.matchRegex(\"/^lorem \\w+$/\")", true], - ["lorem ipsum", "@string@.matchRegex(\"/^foo/\")", false], + ['lorem ipsum', '@string@.startsWith("lorem")', true], + ['lorem ipsum', '@string@.startsWith("LOREM", true)', true], + ['lorem ipsum', '@string@.endsWith("ipsum")', true], + ['lorem ipsum', '@string@.endsWith("IPSUM", true)', true], + ['lorem ipsum', '@string@.contains("lorem")', true], + ['norbert@coduo.pl', '@string@.isEmail()', true], + ['lorem ipsum', '@string@.isEmail()', false], + ['http://coduo.pl/', '@string@.isUrl()', true], + ['lorem ipsum', '@string@.isUrl()', false], + ['2014-08-19', '@string@.isDateTime()', true], + [100, '@integer@.lowerThan(101).greaterThan(10)', true], + ['', '@string@.isNotEmpty()', false], + ['lorem ipsum', '@string@.isNotEmpty()', true], + ['', '@string@.isEmpty()', true], + [['foo', 'bar'], '@array@.inArray("bar")', true], + [[], '@array@.isEmpty()', true], + [['foo'], '@array@.isEmpty()', false], + [[1, 2, 3], '@array@.count(3)', true], + [[1, 2, 3], '@array@.count(4)', false], + ['lorem ipsum', '@string@.oneOf(contains("lorem"), contains("test"))', true], + ['lorem ipsum', '@string@.oneOf(contains("lorem"), contains("test")).endsWith("ipsum")', true], + ['lorem ipsum', '@string@.matchRegex("/^lorem \\w+$/")', true], + ['lorem ipsum', '@string@.matchRegex("/^foo/")', false], [[], ['unexistent_key' => '@array@.optional()'], true], [[], ['unexistent_key' => '@boolean@.optional()'], true], [[], ['unexistent_key' => '@double@.optional()'], true], @@ -389,14 +389,14 @@ public static function expanderExamples() public static function orExamples() { return [ - ["lorem ipsum", "@string@.startsWith(\"lorem\")||@string@.contains(\"lorem\")", true], - ["ipsum lorem", "@string@.startsWith(\"lorem\")||@string@.contains(\"lorem\")", true], - ["norbert@coduo.pl", "@string@.isEmail()||@null@", true], - [null, "@string@.isEmail()||@null@", true], - [null, "@string@.isEmail()||@null@", true], - ["2014-08-19", "@string@.isDateTime()||@integer@", true], - [null, "@integer@||@string@", false], - [1, "@integer@.greaterThan(10)||@string@.contains(\"10\")", false], + ['lorem ipsum', '@string@.startsWith("lorem")||@string@.contains("lorem")', true], + ['ipsum lorem', '@string@.startsWith("lorem")||@string@.contains("lorem")', true], + ['norbert@coduo.pl', '@string@.isEmail()||@null@', true], + [null, '@string@.isEmail()||@null@', true], + [null, '@string@.isEmail()||@null@', true], + ['2014-08-19', '@string@.isDateTime()||@integer@', true], + [null, '@integer@||@string@', false], + [1, '@integer@.greaterThan(10)||@string@.contains("10")', false], ]; } diff --git a/tests/ParserSyntaxErrorTest.php b/tests/ParserSyntaxErrorTest.php index e5366796..7bcc8dbb 100644 --- a/tests/ParserSyntaxErrorTest.php +++ b/tests/ParserSyntaxErrorTest.php @@ -26,7 +26,7 @@ public function setUp() */ public function test_unexpected_statement_at_type_position() { - $this->parser->getAST("not_valid_type"); + $this->parser->getAST('not_valid_type'); } /** @@ -35,7 +35,7 @@ public function test_unexpected_statement_at_type_position() */ public function test_unexpected_statement_instead_of_expander() { - $this->parser->getAST("@type@anything"); + $this->parser->getAST('@type@anything'); } /** @@ -44,7 +44,7 @@ public function test_unexpected_statement_instead_of_expander() */ public function test_end_of_string_after_opening_parenthesis() { - $this->parser->getAST("@type@.expander("); + $this->parser->getAST('@type@.expander('); } /** @@ -53,7 +53,7 @@ public function test_end_of_string_after_opening_parenthesis() */ public function test_not_argument_after_opening_parenthesis() { - $this->parser->getAST("@type@.expander(not_argument"); + $this->parser->getAST('@type@.expander(not_argument'); } /** diff --git a/tests/ParserTest.php b/tests/ParserTest.php index 7d67c6c1..dc989eb2 100644 --- a/tests/ParserTest.php +++ b/tests/ParserTest.php @@ -23,17 +23,17 @@ public function setUp() public function test_simple_pattern_without_expanders() { - $pattern = "@type@"; + $pattern = '@type@'; - $this->assertEquals("type", $this->parser->getAST($pattern)->getType()); + $this->assertEquals('type', $this->parser->getAST($pattern)->getType()); $this->assertFalse($this->parser->getAST($pattern)->hasExpanders()); } public function test_single_expander_without_args() { - $pattern = "@type@.expander()"; + $pattern = '@type@.expander()'; - $this->assertEquals("type", $this->parser->getAST($pattern)->getType()); + $this->assertEquals('type', $this->parser->getAST($pattern)->getType()); $expanders = $this->parser->getAST($pattern)->getExpanders(); $this->assertEquals('expander', $expanders[0]->getName()); $this->assertFalse($expanders[0]->hasArguments()); @@ -42,13 +42,13 @@ public function test_single_expander_without_args() public function test_single_expander_with_arguments() { $pattern = "@type@.expander('arg1', 2, 2.24, \"arg3\")"; - $this->assertEquals("type", $this->parser->getAST($pattern)->getType()); + $this->assertEquals('type', $this->parser->getAST($pattern)->getType()); $expanders = $this->parser->getAST($pattern)->getExpanders(); $expectedArguments = [ - "arg1", + 'arg1', 2, 2.24, - "arg3" + 'arg3' ]; $this->assertEquals($expectedArguments, $expanders[0]->getArguments()); } @@ -63,7 +63,7 @@ public function test_many_expanders() ]; $expanders = $this->parser->getAST($pattern)->getExpanders(); - $this->assertEquals("type", $this->parser->getAST($pattern)->getType()); + $this->assertEquals('type', $this->parser->getAST($pattern)->getType()); $this->assertEquals('expander', $expanders[0]->getName()); $this->assertEquals('expander1', $expanders[1]->getName()); $this->assertEquals('expander', $expanders[2]->getName()); @@ -86,64 +86,64 @@ public static function expandersWithArrayArguments() { return [ [ - "@type@.expander({\"foo\":\"bar\"})", - [["foo" => "bar"]] + '@type@.expander({"foo":"bar"})', + [['foo' => 'bar']] ], [ - "@type@.expander({1 : \"bar\"})", - [[1 => "bar"]] + '@type@.expander({1 : "bar"})', + [[1 => 'bar']] ], [ - "@type@.expander({\"foo\":\"bar\"}, {\"foz\" : \"baz\"})", - [["foo" => "bar"], ["foz" => "baz"]] + '@type@.expander({"foo":"bar"}, {"foz" : "baz"})', + [['foo' => 'bar'], ['foz' => 'baz']] ], [ - "@type@.expander({1 : 1})", + '@type@.expander({1 : 1})', [[1 => 1]] ], [ - "@type@.expander({1 : true})", + '@type@.expander({1 : true})', [[1 => true]] ], [ - "@type@.expander({1 : 1}, {1 : 1})", + '@type@.expander({1 : 1}, {1 : 1})', [[1 => 1], [1 => 1]] ], [ - "@type@.expander({1 : {\"foo\" : \"bar\"}}, {1 : 1})", - [[1 => ["foo" => "bar"]], [1 => 1]] + '@type@.expander({1 : {"foo" : "bar"}}, {1 : 1})', + [[1 => ['foo' => 'bar']], [1 => 1]] ], [ - "@type@.expander({null: \"bar\"})", - [["" => "bar"]] + '@type@.expander({null: "bar"})', + [['' => 'bar']] ], [ - "@type@.expander({\"foo\": null})", - [["foo" => null]] + '@type@.expander({"foo": null})', + [['foo' => null]] ], [ - "@type@.expander({\"foo\" : \"bar\", \"foz\" : \"baz\"})", - [["foo" => "bar", "foz" => "baz"]] + '@type@.expander({"foo" : "bar", "foz" : "baz"})', + [['foo' => 'bar', 'foz' => 'baz']] ], [ - "@type@.expander({\"foo\" : \"bar\", \"foo\" : \"baz\"})", - [["foo" => "baz"]] + '@type@.expander({"foo" : "bar", "foo" : "baz"})', + [['foo' => 'baz']] ], [ - "@type@.expander({\"foo\" : \"bar\", 1 : {\"first\" : 1, \"second\" : 2}})", - [["foo" => "bar", 1 => ["first" => 1, "second" => 2]]] + '@type@.expander({"foo" : "bar", 1 : {"first" : 1, "second" : 2}})', + [['foo' => 'bar', 1 => ['first' => 1, 'second' => 2]]] ] ]; } public function test_expanders_that_takes_other_expanders_as_arguments() { - $pattern = "@type@.expander(expander(\"test\"), expander(1))"; + $pattern = '@type@.expander(expander("test"), expander(1))'; $expanders = $this->parser->getAST($pattern)->getExpanders(); - $firstExpander = new Expander("expander"); - $firstExpander->addArgument("test"); - $secondExpander = new Expander("expander"); + $firstExpander = new Expander('expander'); + $firstExpander->addArgument('test'); + $secondExpander = new Expander('expander'); $secondExpander->addArgument(1); $this->assertEquals(