From d282c1e7a2b936f7ea6d39ff20037ad07bc07d1b Mon Sep 17 00:00:00 2001 From: Simon Frings Date: Mon, 7 Dec 2020 14:06:25 +0100 Subject: [PATCH 1/4] Run tests on PHPUnit 9 and PHP 7.4 --- .github/workflows/ci.yml | 2 ++ composer.json | 5 ++++- tests/RouteTest.php | 4 +++- tests/RouterTest.php | 19 ++++++++----------- tests/TestCase.php | 25 +++++++++++++++++++++++++ tests/Tokens/AlternativeTokenTest.php | 16 +++++++++------- tests/Tokens/ArgumentTokenTest.php | 17 +++++++---------- tests/Tokens/EllipseTokenTest.php | 8 +++++++- tests/Tokens/OptionTokenTest.php | 9 +++++---- tests/Tokens/SentenceTokenTest.php | 12 ++++++++---- tests/Tokens/TokenizerTest.php | 12 +++++++++--- 11 files changed, 87 insertions(+), 42 deletions(-) create mode 100644 tests/TestCase.php diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index aaa48d2..8944fce 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -10,6 +10,8 @@ jobs: strategy: matrix: php: + - 7.4 + - 7.3 - 7.2 - 7.1 - 7.0 diff --git a/composer.json b/composer.json index ef360f2..f598f5a 100644 --- a/composer.json +++ b/composer.json @@ -13,11 +13,14 @@ "autoload": { "psr-4": { "Clue\\Commander\\": "src/" } }, + "autoload-dev": { + "psr-4": { "Clue\\Tests\\Commander\\": "tests/" } + }, "require": { "php": ">=5.3" }, "require-dev": { "clue/arguments": "^1.0", - "phpunit/phpunit": "^5.0 || ^4.8" + "phpunit/phpunit": "^9.3 || ^5.7 || ^4.8.35" } } diff --git a/tests/RouteTest.php b/tests/RouteTest.php index ac1bba9..bb47aa4 100644 --- a/tests/RouteTest.php +++ b/tests/RouteTest.php @@ -1,8 +1,10 @@ add($route, 'var_dump'); + $this->setExpectedException('Clue\Commander\NoRouteFoundException'); $router->handleArgs($args); } @@ -485,25 +487,22 @@ public function testAddRouteCanBeRemoved() $this->assertEquals(array(), $router->getRoutes()); } - /** - * @expectedException UnderflowException - */ public function testCanNotRemoveRouteWhichHasNotBeenAdded() { $router = new Router(); $route = $router->add('hello', function () { }); $router2 = new Router(); + + $this->setExpectedException('UnderflowException'); $router2->remove($route); } - /** - * @expectedException InvalidArgumentException - */ public function testAddRouteThrowsForInvalidHandler() { $router = new Router(); + $this->setExpectedException('InvalidArgumentException'); $router->add('hello', 'invalid'); } @@ -579,13 +578,11 @@ public function testExecArgvWithoutArgvActsLikeEmptyArgv() $_SERVER = $old; } - /** - * @expectedException Clue\Commander\NoRouteFoundException - */ public function testHandleEmptyRouterThrowsUnderflowException() { $router = new Router(); + $this->setExpectedException('Clue\Commander\NoRouteFoundException'); $router->handleArgs(array()); } } diff --git a/tests/TestCase.php b/tests/TestCase.php new file mode 100644 index 0000000..cc05d2f --- /dev/null +++ b/tests/TestCase.php @@ -0,0 +1,25 @@ +expectException($exception); + if ($exceptionMessage !== '') { + $this->expectExceptionMessage($exceptionMessage); + } + if ($exceptionCode !== null) { + $this->expectExceptionCode($exceptionCode); + } + } else { + // legacy PHPUnit 4 - PHPUnit 5.1 + parent::setExpectedException($exception, $exceptionMessage, $exceptionCode); + } + } +} diff --git a/tests/Tokens/AlternativeTokenTest.php b/tests/Tokens/AlternativeTokenTest.php index ab6b17b..87909e5 100644 --- a/tests/Tokens/AlternativeTokenTest.php +++ b/tests/Tokens/AlternativeTokenTest.php @@ -1,11 +1,17 @@ setExpectedException('InvalidArgumentException'); new AlternativeToken(array()); } - /** - * @expectedException InvalidArgumentException - */ public function testRequiresValidTokens() { + $this->setExpectedException('InvalidArgumentException'); new AlternativeToken(array( true, false, diff --git a/tests/Tokens/ArgumentTokenTest.php b/tests/Tokens/ArgumentTokenTest.php index 47a63ef..41432cb 100644 --- a/tests/Tokens/ArgumentTokenTest.php +++ b/tests/Tokens/ArgumentTokenTest.php @@ -1,30 +1,27 @@ setExpectedException('InvalidArgumentException'); new ArgumentToken('name', 'unknown'); } - /** - * @expectedException InvalidArgumentException - */ public function testCtorThrowsWithInvalidCallable() { + $this->setExpectedException('InvalidArgumentException'); new ArgumentToken('name', 'filter', 'nope'); } - /** - * @expectedException InvalidArgumentException - */ public function testCtorThrowsWithoutFilterButWithCallable() { + $this->setExpectedException('InvalidArgumentException'); new ArgumentToken('name', null, function () { }); } diff --git a/tests/Tokens/EllipseTokenTest.php b/tests/Tokens/EllipseTokenTest.php index b7b336c..8b34ca5 100644 --- a/tests/Tokens/EllipseTokenTest.php +++ b/tests/Tokens/EllipseTokenTest.php @@ -1,10 +1,16 @@ setExpectedException('InvalidArgumentException'); new OptionToken('--name', null, true); } } diff --git a/tests/Tokens/SentenceTokenTest.php b/tests/Tokens/SentenceTokenTest.php index d552bc1..54e0cfb 100644 --- a/tests/Tokens/SentenceTokenTest.php +++ b/tests/Tokens/SentenceTokenTest.php @@ -1,10 +1,16 @@ setExpectedException('InvalidArgumentException'); new SentenceToken(array( true, false, diff --git a/tests/Tokens/TokenizerTest.php b/tests/Tokens/TokenizerTest.php index 861b5f9..86181f6 100644 --- a/tests/Tokens/TokenizerTest.php +++ b/tests/Tokens/TokenizerTest.php @@ -1,12 +1,18 @@ tokenizer = new Tokenizer(); $this->tokenizer->addFilter('ip', function ($ip) { @@ -245,11 +251,11 @@ public function provideInvalidTokens() /** * @dataProvider provideInvalidTokens - * @expectedException InvalidArgumentException * @param string $expression */ public function testInvalidTokens($expression) { + $this->setExpectedException('InvalidArgumentException'); $this->tokenizer->createToken($expression); } From 7992b9f7ba34cde89e3bc20e4a9b050edb606032 Mon Sep 17 00:00:00 2001 From: Simon Frings Date: Mon, 7 Dec 2020 14:51:29 +0100 Subject: [PATCH 2/4] Update PHPUnit configuration schema for PHPUnit 9.3 --- .github/workflows/ci.yml | 3 +++ phpunit.xml.dist | 17 +++++++++++------ phpunit.xml.legacy | 16 ++++++++++++++++ 3 files changed, 30 insertions(+), 6 deletions(-) create mode 100644 phpunit.xml.legacy diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 8944fce..dc9c1de 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -27,6 +27,9 @@ jobs: php-version: ${{ matrix.php }} - run: composer install - run: vendor/bin/phpunit --coverage-text + if: ${{ matrix.php >= 7.3 }} + - run: vendor/bin/phpunit --coverage-text -c phpunit.xml.legacy + if: ${{ matrix.php < 7.3 }} PHPUnit-hhvm: name: PHPUnit (HHVM) diff --git a/phpunit.xml.dist b/phpunit.xml.dist index a6e2430..6537b5d 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -1,14 +1,19 @@ - + + - + ./tests/ - - + + ./src/ - - + + diff --git a/phpunit.xml.legacy b/phpunit.xml.legacy new file mode 100644 index 0000000..57fd153 --- /dev/null +++ b/phpunit.xml.legacy @@ -0,0 +1,16 @@ + + + + + ./tests/ + + + + + ./src/ + + + From 22fdefe80d2951a558062dc7e53cdfd938d2e1da Mon Sep 17 00:00:00 2001 From: Simon Frings Date: Mon, 7 Dec 2020 14:53:36 +0100 Subject: [PATCH 3/4] Add .gitattributes to exclude dev files from exports --- .gitattributes | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 .gitattributes diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..da20d18 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,7 @@ +/.gitattributes export-ignore +/.github/workflows/ export-ignore +/.gitignore export-ignore +/examples/ export-ignore +/phpunit.xml.dist export-ignore +/phpunit.xml.legacy export-ignore +/tests/ export-ignore From 39fe379d671f66351fec2ba3e2061fcc7e9a74ad Mon Sep 17 00:00:00 2001 From: Simon Frings Date: Mon, 7 Dec 2020 14:58:13 +0100 Subject: [PATCH 4/4] Support PHP 8 --- .github/workflows/ci.yml | 1 + README.md | 5 +++++ 2 files changed, 6 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index dc9c1de..620e245 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -10,6 +10,7 @@ jobs: strategy: matrix: php: + - 8.0 - 7.4 - 7.3 - 7.2 diff --git a/README.md b/README.md index e622641..bdf802d 100644 --- a/README.md +++ b/README.md @@ -607,6 +607,11 @@ $ composer require clue/commander:^1.3 See also the [CHANGELOG](CHANGELOG.md) for details about version upgrades. +This project aims to run on any platform and thus does not require any PHP +extensions and supports running on legacy PHP 5.3 through current PHP 8+ and +HHVM. +It's *highly recommended to use PHP 7+* for this project. + ## Tests To run the test suite, you first need to clone this repo and then install all