Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Run tests on PHP 8, PHP 7.4 and PHPUnit 9 and update PHPUnit configuration schema for PHPUnit 9.3 #28

Merged
merged 4 commits into from
Dec 7, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -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
6 changes: 6 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ jobs:
strategy:
matrix:
php:
- 8.0
- 7.4
- 7.3
- 7.2
- 7.1
- 7.0
Expand All @@ -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)
Expand Down
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 4 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
17 changes: 11 additions & 6 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
<?xml version="1.0" encoding="UTF-8"?>

<phpunit bootstrap="vendor/autoload.php" colors="true">
<!-- PHPUnit configuration file with new format for PHPUnit 9.3+ -->
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd"
bootstrap="vendor/autoload.php"
colors="true"
cacheResult="false">
<testsuites>
<testsuite>
<testsuite name="Commander test suite">
<directory>./tests/</directory>
</testsuite>
</testsuites>
<filter>
<whitelist>
<coverage>
<include>
<directory>./src/</directory>
</whitelist>
</filter>
</include>
</coverage>
</phpunit>
16 changes: 16 additions & 0 deletions phpunit.xml.legacy
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<!-- PHPUnit configuration file with old format for PHPUnit 9.2 or older -->
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/4.8/phpunit.xsd"
bootstrap="vendor/autoload.php"
colors="true">
<testsuites>
<testsuite name="Commander test suite">
<directory>./tests/</directory>
</testsuite>
</testsuites>
<filter>
<whitelist>
<directory>./src/</directory>
</whitelist>
</filter>
</phpunit>
4 changes: 3 additions & 1 deletion tests/RouteTest.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
<?php

namespace Clue\Tests\Commander;

use Clue\Commander\Route;

class RouteTest extends PHPUnit_Framework_TestCase
class RouteTest extends TestCase
{
public function testToStringWillReturnStringFromToken()
{
Expand Down
19 changes: 8 additions & 11 deletions tests/RouterTest.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
<?php

namespace Clue\Tests\Commander;

use Clue\Commander\Router;
use Clue\Commander\Tokens\Tokenizer;

class RouterTest extends PHPUnit_Framework_TestCase
class RouterTest extends TestCase
{
public function testEmptyRouterHasNoRoutes()
{
Expand Down Expand Up @@ -443,7 +445,6 @@ public function provideNonMatchingRoutes()

/**
* @dataProvider provideNonMatchingRoutes
* @expectedException Clue\Commander\NoRouteFoundException
* @param string $route
* @param array $args
*/
Expand All @@ -452,6 +453,7 @@ public function testHandleRouteDoesNotMatch($route, $args)
$router = new Router();
$router->add($route, 'var_dump');

$this->setExpectedException('Clue\Commander\NoRouteFoundException');
$router->handleArgs($args);
}

Expand Down Expand Up @@ -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');
}

Expand Down Expand Up @@ -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());
}
}
25 changes: 25 additions & 0 deletions tests/TestCase.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

namespace Clue\Tests\Commander;

use PHPUnit\Framework\TestCase as BaseTestCase;

class TestCase extends BaseTestCase
{
public function setExpectedException($exception, $exceptionMessage = '', $exceptionCode = null)
{
if (method_exists($this, 'expectException')) {
// PHPUnit 5.2+
$this->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);
}
}
}
16 changes: 9 additions & 7 deletions tests/Tokens/AlternativeTokenTest.php
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
<?php

namespace Clue\Tests\Commander\Tokens;

use Clue\Commander\Tokens\AlternativeToken;
use Clue\Commander\Tokens\OptionalToken;
use Clue\Commander\Tokens\WordToken;
use Clue\Tests\Commander\TestCase;

class AlternativeTokenTest extends PHPUnit_Framework_TestCase
class AlternativeTokenTest extends TestCase
{
/**
* @doesNotPerformAssertions
*/
public function testSupportsAnyTwoTokens()
{
new AlternativeToken(array(
Expand All @@ -14,19 +20,15 @@ public function testSupportsAnyTwoTokens()
));
}

/**
* @expectedException InvalidArgumentException
*/
public function testRequiresTokens()
{
$this->setExpectedException('InvalidArgumentException');
new AlternativeToken(array());
}

/**
* @expectedException InvalidArgumentException
*/
public function testRequiresValidTokens()
{
$this->setExpectedException('InvalidArgumentException');
new AlternativeToken(array(
true,
false,
Expand Down
17 changes: 7 additions & 10 deletions tests/Tokens/ArgumentTokenTest.php
Original file line number Diff line number Diff line change
@@ -1,30 +1,27 @@
<?php

namespace Clue\Tests\Commander\Tokens;

use Clue\Commander\Tokens\ArgumentToken;
use Clue\Tests\Commander\TestCase;

class ArgumentTokenTest extends PHPUnit_Framework_TestCase
class ArgumentTokenTest extends TestCase
{
/**
* @expectedException InvalidArgumentException
*/
public function testCtorThrowsWithUnknownFilter()
{
$this->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 () { });
}

Expand Down
8 changes: 7 additions & 1 deletion tests/Tokens/EllipseTokenTest.php
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
<?php

namespace Clue\Tests\Commander\Tokens;

use Clue\Commander\Tokens\EllipseToken;
use Clue\Commander\Tokens\WordToken;
use Clue\Tests\Commander\TestCase;

class EllipseTokenTest extends PHPUnit_Framework_TestCase
class EllipseTokenTest extends TestCase
{
/**
* @doesNotPerformAssertions
*/
public function testSupportsWordToken()
{
new EllipseToken(new WordToken('test'));
Expand Down
9 changes: 5 additions & 4 deletions tests/Tokens/OptionTokenTest.php
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
<?php

namespace Clue\Tests\Commander\Tokens;

use Clue\Commander\Tokens\OptionToken;
use Clue\Commander\Tokens\WordToken;
use Clue\Tests\Commander\TestCase;

class OptionTokenTest extends PHPUnit_Framework_TestCase
class OptionTokenTest extends TestCase
{
/**
* @expectedException InvalidArgumentException
*/
public function testUnableToCreateOptionWithRequiredValueButNoPlaceholder()
{
$this->setExpectedException('InvalidArgumentException');
new OptionToken('--name', null, true);
}
}
12 changes: 8 additions & 4 deletions tests/Tokens/SentenceTokenTest.php
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
<?php

namespace Clue\Tests\Commander\Tokens;

use Clue\Commander\Tokens\SentenceToken;
use Clue\Commander\Tokens\WordToken;
use Clue\Tests\Commander\TestCase;

class SentenceTokenTest extends PHPUnit_Framework_TestCase
class SentenceTokenTest extends TestCase
{
/**
* @doesNotPerformAssertions
*/
public function testSupportsAnyTwoTokens()
{
new SentenceToken(array(
Expand All @@ -13,11 +19,9 @@ public function testSupportsAnyTwoTokens()
));
}

/**
* @expectedException InvalidArgumentException
*/
public function testRequiresValidTokens()
{
$this->setExpectedException('InvalidArgumentException');
new SentenceToken(array(
true,
false,
Expand Down
12 changes: 9 additions & 3 deletions tests/Tokens/TokenizerTest.php
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
<?php

namespace Clue\Tests\Commander\Tokens;

use Clue\Commander\Tokens\Tokenizer;
use Clue\Tests\Commander\TestCase;

class TokenizerTest extends PHPUnit_Framework_TestCase
class TokenizerTest extends TestCase
{
private $tokenizer;

public function setUp()
/**
* @before
*/
public function setUpTokenizer()
{
$this->tokenizer = new Tokenizer();
$this->tokenizer->addFilter('ip', function ($ip) {
Expand Down Expand Up @@ -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);
}

Expand Down