Skip to content

Commit

Permalink
Run tests on PHPUnit 9
Browse files Browse the repository at this point in the history
  • Loading branch information
SimonFrings committed Aug 12, 2020
1 parent 57908af commit 30238ff
Show file tree
Hide file tree
Showing 8 changed files with 94 additions and 142 deletions.
11 changes: 4 additions & 7 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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.3" ]]; then vendor/bin/phpunit --coverage-text -c phpunit-legacy.xml.dist; fi
- if [[ "$TRAVIS_PHP_VERSION" > "7.2" ]]; then vendor/bin/phpunit --coverage-text; fi
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
15 changes: 15 additions & 0 deletions phpunit-legacy.xml.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="UTF-8"?>

<!-- phpunit.xml configuration file for PHPUnit Versions older than 9.3 -->
<phpunit bootstrap="vendor/autoload.php" colors="true">
<testsuites>
<testsuite name="Flux test suite">
<directory>./tests/</directory>
</testsuite>
</testsuites>
<filter>
<whitelist>
<directory>./src/</directory>
</whitelist>
</filter>
</phpunit>
23 changes: 12 additions & 11 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
<?xml version="1.0" encoding="UTF-8"?>

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

namespace Clue\Tests\React\Flux;

use PHPUnit\Framework\TestCase as BaseTestCase;

class TestCase extends BaseTestCase
{
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()
{
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);
}
}
}
39 changes: 0 additions & 39 deletions tests/TransformerAllTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
}
}
39 changes: 0 additions & 39 deletions tests/TransformerAnyTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
}
}
47 changes: 2 additions & 45 deletions tests/TransformerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}

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

0 comments on commit 30238ff

Please sign in to comment.