diff --git a/.gitignore b/.gitignore index 3baf5d78..de79ae32 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,4 @@ bin/ composer.lock .DS_Store .idea +.phpunit.result.cache \ No newline at end of file diff --git a/.travis.yml b/.travis.yml index dd83baea..75f06c26 100644 --- a/.travis.yml +++ b/.travis.yml @@ -6,9 +6,8 @@ cache: matrix: include: - - php: 7.0 + - php: 7.2 env: DEPENDENCIES='low' - - php: 7.1 - php: 7.2 - php: 7.3 @@ -21,5 +20,4 @@ install: - if [ "$DEPENDENCIES" == "low" ]; then composer update --prefer-lowest; fi; script: - - ./bin/phpunit - - ./bin/php-cs-fixer fix -v --dry-run + - composer test diff --git a/CHANGELOG.md b/CHANGELOG.md deleted file mode 100644 index 2c8e3ca1..00000000 --- a/CHANGELOG.md +++ /dev/null @@ -1,52 +0,0 @@ -# 2.0.0-r2 - -* Added or operator ``@string@||@null@`` - @partikus - -# 2.0.0-r1 - -# 2.0.0-beta - -* Openssl/lib-array2xml dependency is now more flexible - @blazarecki - -# 2.0.0-alpha2 - -* PHPUnit integration - @jakzal - -# 2.0.0-alpha1 - -* Added support for PHP7 -* Updated dependencies to support Symfony3 components -* Added ``Coduo\PHPMatcher\Tests\Matcher\Pattern\Expander\MatchRegexTest`` expander - @blazarecki -* Added ``Coduo\PHPMatcher\Tests\Matcher\Pattern\Expander\IsEmpty`` expander - @blazarecki -* Added PHPMatcher facade in order to improve developers experience - - -# 1.1.0 - -* Added pattern expanders mechanism with following expanders: - * ``Coduo\PHPMatcher\Tests\Matcher\Pattern\Expander\Contains`` - * ``Coduo\PHPMatcher\Tests\Matcher\Pattern\Expander\EndsWith`` - * ``Coduo\PHPMatcher\Tests\Matcher\Pattern\Expander\GreaterThan`` - * ``Coduo\PHPMatcher\Tests\Matcher\Pattern\Expander\InArray`` - * ``Coduo\PHPMatcher\Tests\Matcher\Pattern\Expander\IsDateTime`` - * ``Coduo\PHPMatcher\Tests\Matcher\Pattern\Expander\IsEmail`` - * ``Coduo\PHPMatcher\Tests\Matcher\Pattern\Expander\IsUrl`` - * ``Coduo\PHPMatcher\Tests\Matcher\Pattern\Expander\LowerThan`` - * ``Coduo\PHPMatcher\Tests\Matcher\Pattern\Expander\MatchRegex`` - * ``Coduo\PHPMatcher\Tests\Matcher\Pattern\Expander\OneOf`` - * ``Coduo\PHPMatcher\Tests\Matcher\Pattern\Expander\StartsWith`` - -# 1.0.0 - -* PHPMatcher initial release with following matchers: - * ``Coduo\PHPMatcher\Tests\Matcher\Pattern\Expander\ArrayMatcher`` - * ``Coduo\PHPMatcher\Tests\Matcher\Pattern\Expander\CallbackMatcher`` - * ``Coduo\PHPMatcher\Tests\Matcher\Pattern\Expander\CaptureMatcher`` - * ``Coduo\PHPMatcher\Tests\Matcher\Pattern\Expander\ChainMatcher`` - * ``Coduo\PHPMatcher\Tests\Matcher\Pattern\Expander\ExpressionMatcher`` - * ``Coduo\PHPMatcher\Tests\Matcher\Pattern\Expander\JsonMatcher`` - * ``Coduo\PHPMatcher\Tests\Matcher\Pattern\Expander\NullMatcher`` - * ``Coduo\PHPMatcher\Tests\Matcher\Pattern\Expander\ScalarMatcher`` - * ``Coduo\PHPMatcher\Tests\Matcher\Pattern\Expander\TypeMatcher`` - * ``Coduo\PHPMatcher\Tests\Matcher\Pattern\Expander\WildcardMatcher`` - * ``Coduo\PHPMatcher\Tests\Matcher\Pattern\Expander\XmlMatcher`` diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index cb6ddcd5..47e4633c 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -6,22 +6,22 @@ 2. Clone the repo to local 3. Install dependencies: `composer update` (this assumes you have 'composer' aliased to wherever your composer.phar lives) 4. Run the tests. We only take pull requests with passing tests, and it's great to know that you have a clean slate: - `./bin/phpunit` + `composer test` -## Coding Standards +## Adding new features -Try use similar coding standards to what you see in the project to keep things clear to the contributors. If you're unsure, it's always a safe bet to fall-back to the PSR standards. +Pull requests with new features needs to be created against master branch. -[PSR-1: Basic Coding Standard](http://www.php-fig.org/psr/psr-1/) +If new feature require BC Break please note that in your PR comment, it will added in next major version. +New features that does not have any BC Breaks are going to be added in next minor version. -[PSR-2: Coding Style Guide](http://www.php-fig.org/psr/psr-2/) +## Codding standards -## Adding new features - -Pull requests with new features needs to be created against master branch. +In order to fix codding standards please exeecute: -If new feature require BC Breake please note that in your PR comment, it will added in next major version. -New features that does not have any BC Breakes are going to be added in next minor version. +``` +composer cs:php:fix +``` ## Patches and bugfixes diff --git a/LICENCE b/LICENCE index a56d5a08..7c9822dc 100644 --- a/LICENCE +++ b/LICENCE @@ -1,4 +1,4 @@ -Copyright (c) 2014-2018 Michal Dabrowski, Norbert Orzechowicz +Copyright (c) 2014-2019 Michal Dabrowski, Norbert Orzechowicz Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation diff --git a/README.md b/README.md index 67fcf05a..88fb3c59 100644 --- a/README.md +++ b/README.md @@ -8,9 +8,9 @@ PHPMatcher::match($value = '{"foo": "bar"}', $pattern = '{"foo": "@string@"}'); It was built to simplify API's functional testing. -* [![Build Status](https://travis-ci.org/coduo/php-matcher.svg)](https://travis-ci.org/coduo/php-matcher) - [3.3 (master) README](https://github.com/coduo/php-matcher/tree/master/README.md) -* [![Build Status](https://travis-ci.org/coduo/php-matcher.svg?branch=3.2)](https://travis-ci.org/coduo/php-matcher) - [3.2.* README](https://github.com/coduo/php-matcher/tree/3.2/README.md) -* [![Build Status](https://travis-ci.org/coduo/php-matcher.svg?branch=3.1)](https://travis-ci.org/coduo/php-matcher) - [3.1.* README](https://github.com/coduo/php-matcher/tree/3.1/README.md) +* [![Build Status](https://travis-ci.org/coduo/php-matcher.svg)](https://travis-ci.org/coduo/php-matcher) - [4.0 (master) README](https://github.com/coduo/php-matcher/tree/master/README.md) PHP >= 7.2 +* [![Build Status](https://travis-ci.org/coduo/php-matcher.svg?branch=3.2)](https://travis-ci.org/coduo/php-matcher) - [3.2.* README](https://github.com/coduo/php-matcher/tree/3.2/README.md) PHP >= 7.0 +* [![Build Status](https://travis-ci.org/coduo/php-matcher.svg?branch=3.1)](https://travis-ci.org/coduo/php-matcher) - [3.1.* README](https://github.com/coduo/php-matcher/tree/3.1/README.md) PHP >= 7.0 ## Installation @@ -36,7 +36,6 @@ if (!PHPMatcher::match("lorem ipsum dolor", "@string@", $error)) { ``` - ### Using Factory ```php @@ -65,6 +64,7 @@ $matcher->getError(); // returns null or error message * ``@*@`` || ``@wildcard@`` * ``expr(expression)`` * ``@uuid@`` +* ``@strig@||@integer@`` - string OR integer ### Available pattern expanders @@ -321,10 +321,10 @@ $matcher->match( '{ "users":[ { - "firstName": @string@, - "lastName": @string@, + "firstName": "@string@", + "lastName": "@string@", "created": "@string@.isDateTime()", - "roles": @array@, + "roles": "@array@", "position": "@string@.optional()" } ] @@ -372,12 +372,12 @@ $matcher->match( '{ "users":[ { - "firstName": @string@, - "lastName": @string@, + "firstName": "@string@", + "lastName": "@string@", "created": "@string@.isDateTime()", "roles": [ "ROLE_USER", - @...@ + "@...@" ], "attributes": { "isAdmin": @boolean@, @@ -465,17 +465,17 @@ Feature: Listing user toys """ [ { - "id": @string@, + "id": "@string@", "name": "Barbie", "_links: "@*@" }, { - "id": @string@, + "id": "@string@", "name": "GI Joe", "_links": "@*@" }, { - "id": @string@, + "id": "@string@", "name": "Optimus Prime", "_links": "@*@" } diff --git a/UPGRADE.md b/UPGRADE.md deleted file mode 100644 index 63941b71..00000000 --- a/UPGRADE.md +++ /dev/null @@ -1,12 +0,0 @@ -# Upgrade from 1.1 to 2.0 - -* All classes are now marked as final in order to close extra extension points -* ``Coduo\PHPMatcher\Matcher\CaptureMatcher`` was removed -* ``Coduo\PHPMatcher\Matcher\TypeMatcher`` was removed -* ``Coduo\PHPMatcher\Matcher\PropertyMatcher`` interface was remved -* Removed ``match`` function, use PHPMatcher facade instead -* Renamed ``@pattern@.notEmpty()`` expander into ``@pattern@.isNotEmpty()`` - -# Upgrade from 1.0 to 1.1 - -*No known BC Breakes* \ No newline at end of file diff --git a/composer.json b/composer.json index 6d94f252..185b1d09 100644 --- a/composer.json +++ b/composer.json @@ -15,7 +15,7 @@ } ], "require": { - "php": ">=7.0.0", + "php": ">=7.2", "ext-filter": "*", "ext-json": "*", "coduo/php-to-string": "^2", @@ -25,7 +25,7 @@ "openlss/lib-array2xml": "^1.0" }, "require-dev": { - "phpunit/phpunit": "^6.0|^7.0", + "phpunit/phpunit": "^7.0|^8.0", "friendsofphp/php-cs-fixer": "^2.4" }, "autoload": { @@ -39,11 +39,20 @@ } }, "config": { - "bin-dir": "bin" + "sort-packages": true + }, + "scripts": { + "cs:php:fix": [ + "php-cs-fixer fix --using-cache=no" + ], + "test" : [ + "phpunit", + "php-cs-fixer fix -v --dry-run" + ] }, "extra": { "branch-alias": { - "dev-master": "3.3-dev" + "dev-master": "4.0-dev" } } } diff --git a/src/Matcher.php b/src/Matcher.php index 9a971b31..ae0eedcc 100644 --- a/src/Matcher.php +++ b/src/Matcher.php @@ -29,7 +29,7 @@ public function match($value, $pattern) : bool /** * @return null|string */ - public function getError() + public function getError() : ?string { return $this->matcher->getError(); } diff --git a/src/Matcher/Matcher.php b/src/Matcher/Matcher.php index 65154a51..d3773b68 100644 --- a/src/Matcher/Matcher.php +++ b/src/Matcher/Matcher.php @@ -11,7 +11,7 @@ abstract class Matcher implements ValueMatcher /** * @inheritdoc */ - public function getError() + public function getError() : ?string { return $this->error; } @@ -28,7 +28,7 @@ public function match($value, $pattern) : bool return false; } - public function clearError() + public function clearError() : void { $this->error = null; } diff --git a/src/Matcher/ValueMatcher.php b/src/Matcher/ValueMatcher.php index ebf366cb..87585528 100644 --- a/src/Matcher/ValueMatcher.php +++ b/src/Matcher/ValueMatcher.php @@ -21,10 +21,10 @@ public function canMatch($pattern) : bool; * * @return null|string */ - public function getError(); + public function getError() :?string; /** * Clear last error */ - public function clearError(); + public function clearError() : void; } diff --git a/src/PHPUnit/PHPMatcherAssertions.php b/src/PHPUnit/PHPMatcherAssertions.php index 7f5e9adc..d6f32d5c 100644 --- a/src/PHPUnit/PHPMatcherAssertions.php +++ b/src/PHPUnit/PHPMatcherAssertions.php @@ -8,7 +8,7 @@ trait PHPMatcherAssertions { - protected function assertMatchesPattern($pattern, $value, string $message = '') + protected function assertMatchesPattern($pattern, $value, string $message = '') : void { TestCase::assertThat($value, self::matchesPattern($pattern), $message); } diff --git a/src/PHPUnit/PHPMatcherConstraint.php b/src/PHPUnit/PHPMatcherConstraint.php index e184da5d..abd57bc8 100644 --- a/src/PHPUnit/PHPMatcherConstraint.php +++ b/src/PHPUnit/PHPMatcherConstraint.php @@ -57,7 +57,7 @@ private function createMatcher() : Matcher /** * {@inheritdoc} */ - protected function fail($other, $description, ComparisonFailure $comparisonFailure = null): void + protected function fail($other, $description, ComparisonFailure $comparisonFailure = null) : void { if (null === $comparisonFailure && \is_string($other) diff --git a/src/Parser.php b/src/Parser.php index c43e3e09..09747633 100644 --- a/src/Parser.php +++ b/src/Parser.php @@ -76,7 +76,7 @@ private function getPattern() : AST\Pattern return $pattern; } - private function addExpanderNodes(AST\Pattern $pattern) + private function addExpanderNodes(AST\Pattern $pattern) : void { while (($expander = $this->getNextExpanderNode()) !== null) { $pattern->addExpander($expander); @@ -85,13 +85,11 @@ private function addExpanderNodes(AST\Pattern $pattern) /** * Try to get next expander, return null if there is no expander left - * - * @return AST\Expander|null */ - private function getNextExpanderNode() + private function getNextExpanderNode() : ?AST\Expander { if ($this->endOfPattern()) { - return ; + return null; } $expander = new AST\Expander($this->getExpanderName()); @@ -113,7 +111,7 @@ private function getNextExpanderNode() return $expander; } - private function getExpanderName() + private function getExpanderName() : string { if ($this->lexer->lookahead['type'] !== Lexer::T_EXPANDER_NAME) { $this->unexpectedSyntaxError($this->lexer->lookahead, '.expanderName(args) definition'); @@ -126,8 +124,6 @@ private function getExpanderName() /** * Add arguments to expander - * - * @param AST\Expander $expander */ private function addArgumentValues(AST\Expander $expander) { @@ -148,8 +144,6 @@ private function addArgumentValues(AST\Expander $expander) /** * Try to get next argument. Return false if there are no arguments left before ")" - * - * @return null|mixed */ private function getNextArgumentValue() { @@ -249,7 +243,7 @@ private function isNextCloseParenthesis() : bool * @param string $expected * @throws PatternException */ - private function unexpectedSyntaxError(array $unexpectedToken, string $expected = null) + private function unexpectedSyntaxError(array $unexpectedToken, string $expected = null) : void { $tokenPos = (isset($unexpectedToken['position'])) ? $unexpectedToken['position'] : '-1'; $message = \sprintf('line 0, col %d: Error: ', $tokenPos); @@ -263,7 +257,7 @@ private function unexpectedSyntaxError(array $unexpectedToken, string $expected * @param string $expected * @throws PatternException */ - private function unexpectedEndOfString(string $expected = null) + private function unexpectedEndOfString(string $expected = null) : void { $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); diff --git a/tests/Matcher/ArrayMatcherTest.php b/tests/Matcher/ArrayMatcherTest.php index ddeb9dc4..114b1e56 100644 --- a/tests/Matcher/ArrayMatcherTest.php +++ b/tests/Matcher/ArrayMatcherTest.php @@ -16,7 +16,7 @@ class ArrayMatcherTest extends TestCase */ private $matcher; - public function setUp() + public function setUp() : void { $parser = new Parser(new Lexer(), new Parser\ExpanderInitializer()); $this->matcher = new Matcher\ArrayMatcher( diff --git a/tests/Matcher/BooleanMatcherTest.php b/tests/Matcher/BooleanMatcherTest.php index bee2225e..7f685f22 100644 --- a/tests/Matcher/BooleanMatcherTest.php +++ b/tests/Matcher/BooleanMatcherTest.php @@ -16,7 +16,7 @@ class BooleanMatcherTest extends TestCase */ private $matcher; - public function setUp() + public function setUp() : void { $this->matcher = new BooleanMatcher(new Parser(new Lexer(), new Parser\ExpanderInitializer())); } diff --git a/tests/Matcher/ChainMatcherTest.php b/tests/Matcher/ChainMatcherTest.php index 0934c743..68924107 100644 --- a/tests/Matcher/ChainMatcherTest.php +++ b/tests/Matcher/ChainMatcherTest.php @@ -25,7 +25,7 @@ class ChainMatcherTest extends TestCase */ private $secondMatcher; - public function setUp() + public function setUp() : void { $this->firstMatcher = $this->createMock('Coduo\PHPMatcher\Matcher\ValueMatcher'); $this->secondMatcher = $this->createMock('Coduo\PHPMatcher\Matcher\ValueMatcher'); diff --git a/tests/Matcher/DoubleMatcherTest.php b/tests/Matcher/DoubleMatcherTest.php index e315ec7a..0c043818 100644 --- a/tests/Matcher/DoubleMatcherTest.php +++ b/tests/Matcher/DoubleMatcherTest.php @@ -16,7 +16,7 @@ class DoubleMatcherTest extends TestCase */ private $matcher; - public function setUp() + public function setUp() : void { $this->matcher = new DoubleMatcher(new Parser(new Lexer(), new Parser\ExpanderInitializer())); } diff --git a/tests/Matcher/IntegerMatcherTest.php b/tests/Matcher/IntegerMatcherTest.php index 390da7e1..5291bc14 100644 --- a/tests/Matcher/IntegerMatcherTest.php +++ b/tests/Matcher/IntegerMatcherTest.php @@ -16,7 +16,7 @@ class IntegerMatcherTest extends TestCase */ private $matcher; - public function setUp() + public function setUp() : void { $this->matcher = new IntegerMatcher(new Parser(new Lexer(), new Parser\ExpanderInitializer())); } diff --git a/tests/Matcher/JsonMatcherTest.php b/tests/Matcher/JsonMatcherTest.php index e4db2582..e5c10ba6 100644 --- a/tests/Matcher/JsonMatcherTest.php +++ b/tests/Matcher/JsonMatcherTest.php @@ -16,7 +16,7 @@ class JsonMatcherTest extends TestCase */ private $matcher; - public function setUp() + public function setUp() : void { $parser = new Parser(new Lexer(), new Parser\ExpanderInitializer()); $scalarMatchers = new Matcher\ChainMatcher([ diff --git a/tests/Matcher/NullMatcherTest.php b/tests/Matcher/NullMatcherTest.php index b876d1c3..5ca6bc1e 100644 --- a/tests/Matcher/NullMatcherTest.php +++ b/tests/Matcher/NullMatcherTest.php @@ -16,7 +16,7 @@ class NullMatcherTest extends TestCase */ private $matcher; - public function setUp() + public function setUp() : void { $this->matcher = new NullMatcher(new Parser(new Lexer(), new Parser\ExpanderInitializer())); } diff --git a/tests/Matcher/NumberMatcherTest.php b/tests/Matcher/NumberMatcherTest.php index 591d194b..80df0bfb 100644 --- a/tests/Matcher/NumberMatcherTest.php +++ b/tests/Matcher/NumberMatcherTest.php @@ -16,7 +16,7 @@ class NumberMatcherTest extends TestCase */ private $matcher; - public function setUp() + public function setUp() : void { $this->matcher = new NumberMatcher(new Parser(new Lexer(), new Parser\ExpanderInitializer())); } diff --git a/tests/Matcher/OrMatcherTest.php b/tests/Matcher/OrMatcherTest.php index f308d0e2..ec9b5964 100644 --- a/tests/Matcher/OrMatcherTest.php +++ b/tests/Matcher/OrMatcherTest.php @@ -15,7 +15,7 @@ class OrMatcherTest extends TestCase */ private $matcher; - public function setUp() + public function setUp() : void { $factory = new SimpleFactory(); $this->matcher = $factory->createMatcher(); diff --git a/tests/Matcher/Pattern/Expander/MatchRegexTest.php b/tests/Matcher/Pattern/Expander/MatchRegexTest.php index 58d36110..7fb5f123 100644 --- a/tests/Matcher/Pattern/Expander/MatchRegexTest.php +++ b/tests/Matcher/Pattern/Expander/MatchRegexTest.php @@ -28,21 +28,19 @@ public static function examplesProvider() ]; } - /** - * @expectedException \InvalidArgumentException - * @expectedExceptionMessage Regex pattern must be a string. - */ public function test_that_it_only_work_with_string() { + $this->expectException(\InvalidArgumentException::class); + $this->expectExceptionMessage('Regex pattern must be a string.'); + new MatchRegex(null); } - /** - * @expectedException \InvalidArgumentException - * @expectedExceptionMessage Regex pattern must be a valid one. - */ public function test_that_it_only_work_with_valid_pattern() { + $this->expectException(\InvalidArgumentException::class); + $this->expectExceptionMessage('Regex pattern must be a valid one.'); + new MatchRegex('///'); } } diff --git a/tests/Matcher/Pattern/Expander/OneOfTest.php b/tests/Matcher/Pattern/Expander/OneOfTest.php index a433015a..a27e087e 100644 --- a/tests/Matcher/Pattern/Expander/OneOfTest.php +++ b/tests/Matcher/Pattern/Expander/OneOfTest.php @@ -10,21 +10,19 @@ class OneOfTest extends TestCase { - /** - * @expectedException \InvalidArgumentException - * @expectedExceptionMessage OneOf expander require at least two expanders. - */ public function test_not_enough_arguments() { + $this->expectException(\InvalidArgumentException::class); + $this->expectExceptionMessage('OneOf expander require at least two expanders.'); + $expander = new OneOf(); } - /** - * @expectedException \InvalidArgumentException - * @expectedExceptionMessage OneOf expander require each argument to be a valid PatternExpander. - */ public function test_invalid_argument_types() { + $this->expectException(\InvalidArgumentException::class); + $this->expectExceptionMessage('OneOf expander require each argument to be a valid PatternExpander.'); + $expander = new OneOf('arg1', ['test']); } diff --git a/tests/Matcher/Pattern/PatternTest.php b/tests/Matcher/Pattern/PatternTest.php index 6f502775..34eb6de1 100644 --- a/tests/Matcher/Pattern/PatternTest.php +++ b/tests/Matcher/Pattern/PatternTest.php @@ -18,7 +18,7 @@ class PatternTest extends TestCase */ private $pattern; - public function setUp() + public function setUp() : void { $this->pattern = new TypePattern('dummy'); $this->pattern->addExpander(new isEmail()); diff --git a/tests/Matcher/Pattern/RegexConverterTest.php b/tests/Matcher/Pattern/RegexConverterTest.php index 7d695b10..8f1572db 100644 --- a/tests/Matcher/Pattern/RegexConverterTest.php +++ b/tests/Matcher/Pattern/RegexConverterTest.php @@ -15,16 +15,15 @@ class RegexConverterTest extends TestCase */ private $converter; - public function setUp() + public function setUp() : void { $this->converter = new RegexConverter(); } - /** - * @expectedException \Coduo\PHPMatcher\Exception\UnknownTypeException - */ public function test_convert_unknown_type() { + $this->expectException(\Coduo\PHPMatcher\Exception\UnknownTypeException::class); + $this->converter->toRegex(new TypePattern('not_a_type')); } } diff --git a/tests/Matcher/StringMatcherTest.php b/tests/Matcher/StringMatcherTest.php index f0a90ee4..c1da867a 100644 --- a/tests/Matcher/StringMatcherTest.php +++ b/tests/Matcher/StringMatcherTest.php @@ -16,7 +16,7 @@ class StringMatcherTest extends TestCase */ private $matcher; - public function setUp() + public function setUp() : void { $parser = new Parser(new Lexer(), new Parser\ExpanderInitializer()); $this->matcher = new StringMatcher($parser); diff --git a/tests/Matcher/TextMatcherTest.php b/tests/Matcher/TextMatcherTest.php index 3e2458ab..d013baaa 100644 --- a/tests/Matcher/TextMatcherTest.php +++ b/tests/Matcher/TextMatcherTest.php @@ -16,7 +16,7 @@ class TextMatcherTest extends TestCase */ private $matcher; - public function setUp() + public function setUp() : void { $parser = new Parser(new Lexer(), new Parser\ExpanderInitializer()); $scalarMatchers = new Matcher\ChainMatcher([ diff --git a/tests/Matcher/UuidMatcherTest.php b/tests/Matcher/UuidMatcherTest.php index 86fa2357..d07b2225 100644 --- a/tests/Matcher/UuidMatcherTest.php +++ b/tests/Matcher/UuidMatcherTest.php @@ -16,7 +16,7 @@ class UuidMatcherTest extends TestCase */ private $matcher; - public function setUp() + public function setUp() : void { $this->matcher = new UuidMatcher(new Parser(new Lexer(), new Parser\ExpanderInitializer())); } diff --git a/tests/Matcher/XmlMatcherTest.php b/tests/Matcher/XmlMatcherTest.php index 43d05568..bd62e7f2 100644 --- a/tests/Matcher/XmlMatcherTest.php +++ b/tests/Matcher/XmlMatcherTest.php @@ -16,7 +16,7 @@ class XmlMatcherTest extends TestCase */ private $matcher; - public function setUp() + public function setUp() : void { $parser = new Parser(new Lexer(), new Parser\ExpanderInitializer()); $scalarMatchers = new Matcher\ChainMatcher([ diff --git a/tests/MatcherTest.php b/tests/MatcherTest.php index f80e8b78..9d13367b 100644 --- a/tests/MatcherTest.php +++ b/tests/MatcherTest.php @@ -16,7 +16,7 @@ class MatcherTest extends TestCase */ protected $matcher; - public function setUp() + public function setUp() : void { $factory = new SimpleFactory(); $this->matcher = $factory->createMatcher(); diff --git a/tests/PHPUnit/PHPMatcherAssertionsTest.php b/tests/PHPUnit/PHPMatcherAssertionsTest.php index 3bd83789..0818bab2 100644 --- a/tests/PHPUnit/PHPMatcherAssertionsTest.php +++ b/tests/PHPUnit/PHPMatcherAssertionsTest.php @@ -16,21 +16,19 @@ public function test_it_asserts_if_a_value_matches_the_pattern() $this->assertMatchesPattern('@string@', 'foo'); } - /** - * @expectedException \PHPUnit\Framework\AssertionFailedError - * @expectedExceptionMessage Failed asserting that '{"foo":"bar"}' matches the pattern - */ public function test_it_throws_an_expectation_failed_exception_if_a_value_does_not_match_the_pattern() { + $this->expectException(\PHPUnit\Framework\AssertionFailedError::class); + $this->expectExceptionMessage("Failed asserting that '{\"foo\":\"bar\"}' matches the pattern"); + $this->assertMatchesPattern('{"foo": "@integer@"}', \json_encode(['foo' => 'bar'])); } - /** - * @expectedException \PHPUnit\Framework\AssertionFailedError - * @expectedExceptionMessage Failed asserting that 42 matches the pattern. - */ public function test_it_creates_a_constraint_for_stubs() { + $this->expectException(\PHPUnit\Framework\AssertionFailedError::class); + $this->expectExceptionMessage('Failed asserting that 42 matches the pattern.'); + $mock = $this->getMockBuilder('stdClass') ->setMethods(['getTitle']) ->getMock(); diff --git a/tests/PHPUnit/PHPMatcherConstraintTest.php b/tests/PHPUnit/PHPMatcherConstraintTest.php index 3916a49f..bdfbe648 100644 --- a/tests/PHPUnit/PHPMatcherConstraintTest.php +++ b/tests/PHPUnit/PHPMatcherConstraintTest.php @@ -28,23 +28,21 @@ public function test_it_returns_false_if_a_value_does_not_match_the_pattern() $this->assertFalse($constraint->evaluate(42, '', true)); } - /** - * @expectedException \PHPUnit\Framework\AssertionFailedError - * @expectedExceptionMessage Failed asserting that 42 matches the pattern - */ public function test_it_sets_a_failure_description_if_not_given() { + $this->expectException(\PHPUnit\Framework\AssertionFailedError::class); + $this->expectExceptionMessage('Failed asserting that 42 matches the pattern'); + $constraint = new PHPMatcherConstraint('@string@'); $this->assertFalse($constraint->evaluate(42)); } - /** - * @expectedException \PHPUnit\Framework\AssertionFailedError - * @expectedExceptionMessage integer "42" is not a valid string - */ public function test_it_sets_additional_failure_description() { + $this->expectException(\PHPUnit\Framework\AssertionFailedError::class); + $this->expectExceptionMessage('integer "42" is not a valid string'); + $constraint = new PHPMatcherConstraint('@string@'); $this->assertFalse($constraint->evaluate(42)); @@ -58,11 +56,12 @@ public function test_that_pattern_could_be_an_array() } /** - * @expectedException \LogicException * @dataProvider invalidPatterns */ public function test_that_pattern_could_be_only_a_string_or_an_array($pattern) { + $this->expectException(\LogicException::class); + new PHPMatcherConstraint($pattern); } diff --git a/tests/PHPUnit/PHPMatcherTestCaseTest.php b/tests/PHPUnit/PHPMatcherTestCaseTest.php index 96b7420c..89f08f2c 100644 --- a/tests/PHPUnit/PHPMatcherTestCaseTest.php +++ b/tests/PHPUnit/PHPMatcherTestCaseTest.php @@ -13,21 +13,19 @@ public function test_it_asserts_if_a_value_matches_the_pattern() $this->assertMatchesPattern('@string@', 'foo'); } - /** - * @expectedException \PHPUnit\Framework\AssertionFailedError - * @expectedExceptionMessage Failed asserting that '{"foo":"bar"}' matches the pattern - */ public function test_it_throws_an_expectation_failed_exception_if_a_value_does_not_match_the_pattern() { + $this->expectException(\PHPUnit\Framework\AssertionFailedError::class); + $this->expectExceptionMessage("Failed asserting that '{\"foo\":\"bar\"}' matches the pattern"); + $this->assertMatchesPattern('{"foo": "@integer@"}', \json_encode(['foo' => 'bar'])); } - /** - * @expectedException \PHPUnit\Framework\AssertionFailedError - * @expectedExceptionMessage Failed asserting that 42 matches the pattern. - */ public function test_it_creates_a_constraint_for_stubs() { + $this->expectException(\PHPUnit\Framework\AssertionFailedError::class); + $this->expectExceptionMessage('Failed asserting that 42 matches the pattern.'); + $mock = $this->getMockBuilder('stdClass') ->setMethods(['getTitle']) ->getMock(); diff --git a/tests/ParserSyntaxErrorTest.php b/tests/ParserSyntaxErrorTest.php index 7bcc8dbb..eac79b61 100644 --- a/tests/ParserSyntaxErrorTest.php +++ b/tests/ParserSyntaxErrorTest.php @@ -15,80 +15,72 @@ class ParserSyntaxErrorTest extends TestCase */ private $parser; - public function setUp() + public function setUp() : void { $this->parser = new Parser(new Lexer(), new Parser\ExpanderInitializer()); } - /** - * @expectedException \Coduo\PHPMatcher\Exception\PatternException - * @expectedExceptionMessage [Syntax Error] line 0, col 0: Error: Expected "@type@ pattern", got "not" - */ public function test_unexpected_statement_at_type_position() { + $this->expectException(\Coduo\PHPMatcher\Exception\PatternException::class); + $this->expectExceptionMessage('[Syntax Error] line 0, col 0: Error: Expected "@type@ pattern", got "not"'); + $this->parser->getAST('not_valid_type'); } - /** - * @expectedException \Coduo\PHPMatcher\Exception\PatternException - * @expectedExceptionMessage [Syntax Error] line 0, col 6: Error: Expected ".expanderName(args) definition", got "anything" - */ public function test_unexpected_statement_instead_of_expander() { + $this->expectException(\Coduo\PHPMatcher\Exception\PatternException::class); + $this->expectExceptionMessage('[Syntax Error] line 0, col 6: Error: Expected ".expanderName(args) definition", got "anything"'); + $this->parser->getAST('@type@anything'); } - /** - * @expectedException \Coduo\PHPMatcher\Exception\PatternException - * @expectedExceptionMessage [Syntax Error] line 0, col 14: Error: Expected ")", got end of string.end of string - */ public function test_end_of_string_after_opening_parenthesis() { + $this->expectException(\Coduo\PHPMatcher\Exception\PatternException::class); + $this->expectExceptionMessage('[Syntax Error] line 0, col 14: Error: Expected ")", got end of string.end of string'); + $this->parser->getAST('@type@.expander('); } - /** - * @expectedException \Coduo\PHPMatcher\Exception\PatternException - * @expectedExceptionMessage [Syntax Error] line 0, col 16: Error: Expected "string, number, boolean or null argument", got "not" - */ public function test_not_argument_after_opening_parenthesis() { + $this->expectException(\Coduo\PHPMatcher\Exception\PatternException::class); + $this->expectExceptionMessage('[Syntax Error] line 0, col 16: Error: Expected "string, number, boolean or null argument", got "not"'); + $this->parser->getAST('@type@.expander(not_argument'); } - /** - * @expectedException \Coduo\PHPMatcher\Exception\PatternException - * @expectedExceptionMessage [Syntax Error] line 0, col 22: Error: Expected ")", got end of string.end of string - */ public function test_missing_close_parenthesis_after_single_argument() { + $this->expectException(\Coduo\PHPMatcher\Exception\PatternException::class); + $this->expectExceptionMessage('[Syntax Error] line 0, col 22: Error: Expected ")", got end of string.end of string'); + $this->parser->getAST("@type@.expander('string'"); } - /** - * @expectedException \Coduo\PHPMatcher\Exception\PatternException - * @expectedExceptionMessage [Syntax Error] line 0, col 26: Error: Expected ")", got end of string.end of string - */ public function test_missing_close_parenthesis_after_multiple_arguments() { + $this->expectException(\Coduo\PHPMatcher\Exception\PatternException::class); + $this->expectExceptionMessage('[Syntax Error] line 0, col 26: Error: Expected ")", got end of string.end of string'); + $this->parser->getAST("@type@.expander('string',1"); } - /** - * @expectedException \Coduo\PHPMatcher\Exception\PatternException - * @expectedExceptionMessage [Syntax Error] line 0, col 25: Error: Expected "string, number, boolean or null argument", got ")" - */ public function test_missing_argument_after_comma() { + $this->expectException(\Coduo\PHPMatcher\Exception\PatternException::class); + $this->expectExceptionMessage('[Syntax Error] line 0, col 25: Error: Expected "string, number, boolean or null argument", got ")"'); + $this->parser->getAST("@type@.expander('string',)"); } - /** - * @expectedException \Coduo\PHPMatcher\Exception\PatternException - * @expectedExceptionMessage [Syntax Error] line 0, col 25: Error: Expected "string, number, boolean or null argument", got "not" - */ public function test_not_argument_after_comma() { + $this->expectException(\Coduo\PHPMatcher\Exception\PatternException::class); + $this->expectExceptionMessage('[Syntax Error] line 0, col 25: Error: Expected "string, number, boolean or null argument", got "not"'); + $this->parser->getAST("@type@.expander('string',not_argument"); } } diff --git a/tests/ParserTest.php b/tests/ParserTest.php index dc989eb2..0fdca7aa 100644 --- a/tests/ParserTest.php +++ b/tests/ParserTest.php @@ -16,7 +16,7 @@ class ParserTest extends TestCase */ private $parser; - public function setUp() + public function setUp() : void { $this->parser = new Parser(new Lexer(), new Parser\ExpanderInitializer()); }