diff --git a/.gitattributes b/.gitattributes index 0925d33..1c2642c 100644 --- a/.gitattributes +++ b/.gitattributes @@ -2,5 +2,6 @@ /.gitignore export-ignore /.travis.yml export-ignore /examples/ export-ignore -/phpunit.xml.dist export-ignore +/phpunit.xml export-ignore +/phpunit-legacy.xml export-ignore /tests/ export-ignore diff --git a/.travis.yml b/.travis.yml index d0dc010..b905be4 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,7 +3,7 @@ language: php # lock distro so new future defaults will not break the build dist: trusty -matrix: +jobs: include: - php: 5.3 dist: precise @@ -16,15 +16,12 @@ matrix: - php: 7.3 - php: 7.4 - php: hhvm-3.18 - install: - - composer require phpunit/phpunit:^5 --dev --no-interaction # requires legacy phpunit allow_failures: - php: hhvm-3.18 -sudo: false - install: - - composer install --no-interaction + - composer install script: - - vendor/bin/phpunit --coverage-text + - if [[ "$TRAVIS_PHP_VERSION" > "7.2" ]]; then vendor/bin/phpunit --coverage-text; fi + - if [[ "$TRAVIS_PHP_VERSION" < "7.3" ]]; then vendor/bin/phpunit --coverage-text -c phpunit-legacy.xml; fi diff --git a/composer.json b/composer.json index 877eb02..051be5f 100644 --- a/composer.json +++ b/composer.json @@ -25,6 +25,6 @@ "require-dev": { "clue/buzz-react": "^2.4", "clue/ndjson-react": "^1.0", - "phpunit/phpunit": "^7.0 || ^6.4 || ^5.7 || ^4.8.35" + "phpunit/phpunit": "^9.3 || ^5.7 || ^4.8.35" } } diff --git a/phpunit.xml.dist b/phpunit-legacy.xml similarity index 51% rename from phpunit.xml.dist rename to phpunit-legacy.xml index 59cfa84..6b429dd 100644 --- a/phpunit.xml.dist +++ b/phpunit-legacy.xml @@ -1,6 +1,10 @@ - + + ./tests/ diff --git a/phpunit.xml b/phpunit.xml new file mode 100644 index 0000000..fe1143b --- /dev/null +++ b/phpunit.xml @@ -0,0 +1,19 @@ + + + + + + + ./tests/ + + + + + ./src/ + + + diff --git a/tests/TestCase.php b/tests/TestCase.php new file mode 100644 index 0000000..d595a51 --- /dev/null +++ b/tests/TestCase.php @@ -0,0 +1,60 @@ +createCallableMock(); + $mock->expects($this->once())->method('__invoke'); + + return $mock; + } + + protected function expectCallableOnceWith($param) + { + $mock = $this->createCallableMock(); + $mock->expects($this->once()) ->method('__invoke')->with($param); + + return $mock; + } + + protected function expectCallableNever() + { + $mock = $this->createCallableMock(); + $mock->expects($this->never())->method('__invoke'); + + return $mock; + } + + protected function createCallableMock() + { + if (method_exists('PHPUnit\Framework\MockObject\MockBuilder', 'addMethods')) { + // PHPUnit 9+ + return $this->getMockBuilder('stdClass')->addMethods(array('__invoke'))->getMock(); + } else { + // legacy PHPUnit 4 - PHPUnit 8 + return $this->getMockBuilder('stdClass')->setMethods(array('__invoke'))->getMock(); + } + } + + public function setExpectedException($exception, $exceptionMessage = '', $exceptionCode = null) + { + if (method_exists($this, 'expectException')) { + // PHPUnit 6+ + $this->expectException($exception); + if ($exceptionMessage !== '') { + $this->expectExceptionMessage($exceptionMessage); + } + if ($exceptionCode !== null) { + $this->expectExceptionCode($exceptionCode); + } + } else { + // legacy PHPUnit 4 - PHPUnit 5 + parent::setExpectedException($exception, $exceptionMessage, $exceptionCode); + } + } +} diff --git a/tests/TransformerAllTest.php b/tests/TransformerAllTest.php index c09a388..6bba8cc 100644 --- a/tests/TransformerAllTest.php +++ b/tests/TransformerAllTest.php @@ -3,7 +3,6 @@ namespace Clue\Tests\React\Flux; use Clue\React\Flux\Transformer; -use PHPUnit\Framework\TestCase; use React\Promise\Deferred; use React\Promise\Promise; use React\Stream\ThroughStream; @@ -203,42 +202,4 @@ public function testPendingOperationWillBeCancelledIfOneOperationRejects() $promise->then(null, $this->expectCallableOnce()); } - - protected function expectCallableOnce() - { - $mock = $this->createCallableMock(); - - $mock - ->expects($this->once()) - ->method('__invoke'); - - return $mock; - } - - protected function expectCallableOnceWith($param) - { - $mock = $this->createCallableMock(); - - $mock - ->expects($this->once()) - ->method('__invoke') - ->with($param); - - return $mock; - } - - protected function expectCallableNever() - { - $mock = $this->createCallableMock(); - $mock - ->expects($this->never()) - ->method('__invoke'); - - return $mock; - } - - protected function createCallableMock() - { - return $this->getMockBuilder('stdClass')->setMethods(array('__invoke'))->getMock(); - } } diff --git a/tests/TransformerAnyTest.php b/tests/TransformerAnyTest.php index 0ef5483..2a95f1d 100644 --- a/tests/TransformerAnyTest.php +++ b/tests/TransformerAnyTest.php @@ -3,7 +3,6 @@ namespace Clue\Tests\React\Flux; use Clue\React\Flux\Transformer; -use PHPUnit\Framework\TestCase; use React\Promise\Deferred; use React\Promise\Promise; use React\Stream\ThroughStream; @@ -211,42 +210,4 @@ public function testPendingOperationWillBeCancelledIfOneOperationResolves() $promise->then($this->expectCallableOnceWith('hello')); } - - protected function expectCallableOnce() - { - $mock = $this->createCallableMock(); - - $mock - ->expects($this->once()) - ->method('__invoke'); - - return $mock; - } - - protected function expectCallableOnceWith($param) - { - $mock = $this->createCallableMock(); - - $mock - ->expects($this->once()) - ->method('__invoke') - ->with($param); - - return $mock; - } - - protected function expectCallableNever() - { - $mock = $this->createCallableMock(); - $mock - ->expects($this->never()) - ->method('__invoke'); - - return $mock; - } - - protected function createCallableMock() - { - return $this->getMockBuilder('stdClass')->setMethods(array('__invoke'))->getMock(); - } } diff --git a/tests/TransformerTest.php b/tests/TransformerTest.php index 8bf8272..50a6836 100644 --- a/tests/TransformerTest.php +++ b/tests/TransformerTest.php @@ -3,25 +3,20 @@ namespace Clue\Tests\React\Flux; use Clue\React\Flux\Transformer; -use PHPUnit\Framework\TestCase; use React\Promise; use React\Promise\Deferred; class TransformerTest extends TestCase { - /** - * @expectedException InvalidArgumentException - */ public function testConstructorThrowsIfConcurrencyIsBelowOne() { + $this->setExpectedException('InvalidArgumentException'); new Transformer(0, function () { }); } - /** - * @expectedException InvalidArgumentException - */ public function testConstructorThrowsIfHandlerIsNotCallable() { + $this->setExpectedException('InvalidArgumentException'); new Transformer(1, 'foo'); } @@ -404,42 +399,4 @@ public function testPipeReturnsDestinationStream() $this->assertSame($ret, $dest); } - - protected function expectCallableOnce() - { - $mock = $this->createCallableMock(); - - $mock - ->expects($this->once()) - ->method('__invoke'); - - return $mock; - } - - protected function expectCallableOnceWith($param) - { - $mock = $this->createCallableMock(); - - $mock - ->expects($this->once()) - ->method('__invoke') - ->with($param); - - return $mock; - } - - protected function expectCallableNever() - { - $mock = $this->createCallableMock(); - $mock - ->expects($this->never()) - ->method('__invoke'); - - return $mock; - } - - protected function createCallableMock() - { - return $this->getMockBuilder('stdClass')->setMethods(array('__invoke'))->getMock(); - } }