Skip to content

Commit c89153a

Browse files
authored
Merge pull request #5 from clue-labs/phpunit
Support upcoming PHP 8.1 and update test suite for PHPUnit 9
2 parents c6f717e + 3dccf8c commit c89153a

10 files changed

+118
-65
lines changed

.gitattributes

+1
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@
22
/.github/ export-ignore
33
/.gitignore export-ignore
44
/phpunit.xml.dist export-ignore
5+
/phpunit.xml.legacy export-ignore
56
/tests/ export-ignore

.github/workflows/ci.yml

+5
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ jobs:
1111
strategy:
1212
matrix:
1313
php:
14+
- 8.1
15+
- 8.0
1416
- 7.4
1517
- 7.3
1618
- 7.2
@@ -27,3 +29,6 @@ jobs:
2729
coverage: xdebug
2830
- run: composer install
2931
- run: vendor/bin/phpunit --coverage-text
32+
if: ${{ matrix.php >= 7.3 }}
33+
- run: vendor/bin/phpunit --coverage-text -c phpunit.xml.legacy
34+
if: ${{ matrix.php < 7.3 }}

README.md

+27-14
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@ It is heavily influenced by [async.js](https://github.com/caolan/async).
88

99
[![CI status](https://github.com/reactphp/async/workflows/CI/badge.svg)](https://github.com/reactphp/async/actions)
1010

11-
## About
12-
1311
This library allows you to manage async control flow. It provides a number of
1412
combinators for continuation-passing style (aka callbacks). Instead of nesting
1513
those callbacks, you can declare them as a list, which is resolved
@@ -24,20 +22,17 @@ loop, it can be used with this library.
2422
*You must be running inside an event loop for react/async to make any sense
2523
whatsoever!*
2624

27-
## Install
25+
**Table of Contents**
2826

29-
The recommended way to install react/async is [through
30-
composer](http://getcomposer.org).
27+
* [Usage](#usage)
28+
* [Parallel](#parallel)
29+
* [Waterfall](#waterfall)
30+
* [Todo](#todo)
31+
* [Install](#install)
32+
* [Tests](#tests)
33+
* [License](#license)
3134

32-
```JSON
33-
{
34-
"require": {
35-
"react/async": "~1.0"
36-
}
37-
}
38-
```
39-
40-
## Example
35+
## Usage
4136

4237
### Parallel
4338

@@ -110,6 +105,24 @@ Async::waterfall(array(
110105

111106
* Implement queue()
112107

108+
## Install
109+
110+
The recommended way to install this library is [through Composer](https://getcomposer.org/).
111+
[New to Composer?](https://getcomposer.org/doc/00-intro.md)
112+
113+
Once released, this project will follow [SemVer](https://semver.org/).
114+
At the moment, this will install the latest development version:
115+
116+
```bash
117+
$ composer require react/async:dev-main
118+
```
119+
120+
See also the [CHANGELOG](CHANGELOG.md) for details about version upgrades.
121+
122+
This project aims to run on any platform and thus does not require any PHP
123+
extensions and supports running on legacy PHP 5.3 through current PHP 8+.
124+
It's *highly recommended to use the latest supported PHP version* for this project.
125+
113126
## Tests
114127

115128
To run the test suite, you first need to clone this repo and then install all

composer.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
"php": ">=5.3.2"
3030
},
3131
"require-dev": {
32-
"phpunit/phpunit": "^5.7 || ^4.8.35",
32+
"phpunit/phpunit": "^9.3 || ^5.7 || ^4.8.35",
3333
"react/event-loop": "^1.2"
3434
},
3535
"suggest": {

phpunit.xml.dist

+10-16
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,19 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22

3-
<phpunit backupGlobals="false"
4-
backupStaticAttributes="false"
5-
colors="true"
6-
convertErrorsToExceptions="true"
7-
convertNoticesToExceptions="true"
8-
convertWarningsToExceptions="true"
9-
processIsolation="false"
10-
stopOnFailure="false"
11-
syntaxCheck="false"
3+
<!-- PHPUnit configuration file with new format for PHPUnit 9.3+ -->
4+
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
5+
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd"
126
bootstrap="vendor/autoload.php"
13-
>
7+
colors="true"
8+
cacheResult="false">
149
<testsuites>
15-
<testsuite name="React-Async Test Suite">
10+
<testsuite name="React Test Suite">
1611
<directory>./tests/</directory>
1712
</testsuite>
1813
</testsuites>
19-
20-
<filter>
21-
<whitelist>
14+
<coverage>
15+
<include>
2216
<directory>./src/</directory>
23-
</whitelist>
24-
</filter>
17+
</include>
18+
</coverage>
2519
</phpunit>

phpunit.xml.legacy

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
3+
<!-- PHPUnit configuration file with old format for PHPUnit 9.2 or older -->
4+
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
5+
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/4.8/phpunit.xsd"
6+
bootstrap="vendor/autoload.php"
7+
colors="true">
8+
<testsuites>
9+
<testsuite name="React Test Suite">
10+
<directory>./tests/</directory>
11+
</testsuite>
12+
</testsuites>
13+
<filter>
14+
<whitelist>
15+
<directory>./src/</directory>
16+
</whitelist>
17+
</filter>
18+
</phpunit>

tests/TestCase.php

+36-14
Original file line numberDiff line numberDiff line change
@@ -2,27 +2,49 @@
22

33
namespace React\Tests\Async;
44

5-
class TestCase extends \PHPUnit_Framework_TestCase
5+
use PHPUnit\Framework\TestCase as BaseTestCase;
6+
7+
class TestCase extends BaseTestCase
68
{
7-
protected function createCallableMock($expects, $with = null)
9+
protected function expectCallableOnce()
810
{
9-
$callable = $this->getMockBuilder('React\Tests\Async\CallableStub')->getMock();
10-
11-
$method = $callable
12-
->expects($expects)
11+
$mock = $this->createCallableMock();
12+
$mock
13+
->expects($this->once())
1314
->method('__invoke');
1415

15-
if ($with) {
16-
$method->with($with);
17-
}
16+
return $mock;
17+
}
1818

19-
return $callable;
19+
protected function expectCallableOnceWith($value)
20+
{
21+
$mock = $this->createCallableMock();
22+
$mock
23+
->expects($this->once())
24+
->method('__invoke')
25+
->with($value);
26+
27+
return $mock;
2028
}
21-
}
2229

23-
class CallableStub
24-
{
25-
public function __invoke()
30+
protected function expectCallableNever()
2631
{
32+
$mock = $this->createCallableMock();
33+
$mock
34+
->expects($this->never())
35+
->method('__invoke');
36+
37+
return $mock;
38+
}
39+
40+
protected function createCallableMock()
41+
{
42+
if (method_exists('PHPUnit\Framework\MockObject\MockBuilder', 'addMethods')) {
43+
// PHPUnit 9+
44+
return $this->getMockBuilder('stdClass')->addMethods(array('__invoke'))->getMock();
45+
} else {
46+
// legacy PHPUnit 4 - PHPUnit 8
47+
return $this->getMockBuilder('stdClass')->setMethods(array('__invoke'))->getMock();
48+
}
2749
}
2850
}

tests/UtilParallelTest.php

+8-8
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ public function testParallelWithoutTasks()
1111
{
1212
$tasks = array();
1313

14-
$callback = $this->createCallableMock($this->once(), array());
15-
$errback = $this->createCallableMock($this->never());
14+
$callback = $this->expectCallableOnceWith(array());
15+
$errback = $this->expectCallableNever();
1616

1717
Util::parallel($tasks, $callback, $errback);
1818
}
@@ -32,8 +32,8 @@ function ($callback, $errback) {
3232
},
3333
);
3434

35-
$callback = $this->createCallableMock($this->once(), array('foo', 'bar'));
36-
$errback = $this->createCallableMock($this->never());
35+
$callback = $this->expectCallableOnceWith(array('foo', 'bar'));
36+
$errback = $this->expectCallableNever();
3737

3838
Util::parallel($tasks, $callback, $errback);
3939

@@ -65,8 +65,8 @@ function ($callback, $errback) use (&$called) {
6565
},
6666
);
6767

68-
$callback = $this->createCallableMock($this->never());
69-
$errback = $this->createCallableMock($this->once());
68+
$callback = $this->expectCallableNever();
69+
$errback = $this->expectCallableOnce();
7070

7171
Util::parallel($tasks, $callback, $errback);
7272

@@ -94,8 +94,8 @@ function ($callback, $errback) use (&$called) {
9494
},
9595
);
9696

97-
$callback = $this->createCallableMock($this->never());
98-
$errback = $this->createCallableMock($this->once());
97+
$callback = $this->expectCallableNever();
98+
$errback = $this->expectCallableOnce();
9999

100100
Util::parallel($tasks, $callback, $errback);
101101

tests/UtilSeriesTest.php

+6-6
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ public function testSeriesWithoutTasks()
1111
{
1212
$tasks = array();
1313

14-
$callback = $this->createCallableMock($this->once(), array());
15-
$errback = $this->createCallableMock($this->never());
14+
$callback = $this->expectCallableOnceWith(array());
15+
$errback = $this->expectCallableNever();
1616

1717
Util::series($tasks, $callback, $errback);
1818
}
@@ -32,8 +32,8 @@ function ($callback, $errback) {
3232
},
3333
);
3434

35-
$callback = $this->createCallableMock($this->once(), array('foo', 'bar'));
36-
$errback = $this->createCallableMock($this->never());
35+
$callback = $this->expectCallableOnceWith(array('foo', 'bar'));
36+
$errback = $this->expectCallableNever();
3737

3838
Util::series($tasks, $callback, $errback);
3939

@@ -65,8 +65,8 @@ function ($callback, $errback) use (&$called) {
6565
},
6666
);
6767

68-
$callback = $this->createCallableMock($this->never());
69-
$errback = $this->createCallableMock($this->once());
68+
$callback = $this->expectCallableNever();
69+
$errback = $this->expectCallableOnce();
7070

7171
Util::series($tasks, $callback, $errback);
7272

tests/UtilWaterfallTest.php

+6-6
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ public function testWaterfallWithoutTasks()
1111
{
1212
$tasks = array();
1313

14-
$callback = $this->createCallableMock($this->once(), array());
15-
$errback = $this->createCallableMock($this->never());
14+
$callback = $this->expectCallableOnce();
15+
$errback = $this->expectCallableNever();
1616

1717
Util::waterfall($tasks, $callback, $errback);
1818
}
@@ -37,8 +37,8 @@ function ($bar, $callback, $errback) {
3737
},
3838
);
3939

40-
$callback = $this->createCallableMock($this->once(), 'foobarbaz');
41-
$errback = $this->createCallableMock($this->never());
40+
$callback = $this->expectCallableOnceWith('foobarbaz');
41+
$errback = $this->expectCallableNever();
4242

4343
Util::waterfall($tasks, $callback, $errback);
4444

@@ -70,8 +70,8 @@ function ($callback, $errback) use (&$called) {
7070
},
7171
);
7272

73-
$callback = $this->createCallableMock($this->never());
74-
$errback = $this->createCallableMock($this->once());
73+
$callback = $this->expectCallableNever();
74+
$errback = $this->expectCallableOnce();
7575

7676
Util::waterfall($tasks, $callback, $errback);
7777

0 commit comments

Comments
 (0)