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 13, 2020
1 parent 57908af commit 86eac25
Show file tree
Hide file tree
Showing 7 changed files with 66 additions and 131 deletions.
8 changes: 2 additions & 6 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,11 @@ 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
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"
}
}
2 changes: 1 addition & 1 deletion phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>

<phpunit bootstrap="vendor/autoload.php" colors="true">
<phpunit bootstrap="vendor/autoload.php" colors="true" cacheResult="false">
<testsuites>
<testsuite name="Flux test suite">
<directory>./tests/</directory>
Expand Down
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 86eac25

Please sign in to comment.