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 diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index aaa48d2..620e245 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -10,6 +10,9 @@ jobs: strategy: matrix: php: + - 8.0 + - 7.4 + - 7.3 - 7.2 - 7.1 - 7.0 @@ -25,6 +28,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/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 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/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/ + + + 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); }