Skip to content
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
3 changes: 2 additions & 1 deletion .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -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
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.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
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"
}
}
6 changes: 5 additions & 1 deletion phpunit.xml.dist → phpunit-legacy.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>

<phpunit bootstrap="vendor/autoload.php" colors="true">
<!-- 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="Flux test suite">
<directory>./tests/</directory>
Expand Down
19 changes: 19 additions & 0 deletions phpunit.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?xml version="1.0" encoding="UTF-8"?>

<!-- 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 name="Flux test suite">
<directory>./tests/</directory>
</testsuite>
</testsuites>
<coverage>
<include>
<directory>./src/</directory>
</include>
</coverage>
</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();
}
}