Skip to content

Support upcoming PHP 8.1 and update test suite for PHPUnit 9 #5

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 19, 2021
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
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@
/.github/ export-ignore
/.gitignore export-ignore
/phpunit.xml.dist export-ignore
/phpunit.xml.legacy export-ignore
/tests/ export-ignore
5 changes: 5 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ jobs:
strategy:
matrix:
php:
- 8.1
- 8.0
- 7.4
- 7.3
- 7.2
Expand All @@ -27,3 +29,6 @@ jobs:
coverage: xdebug
- run: composer install
- run: vendor/bin/phpunit --coverage-text
if: ${{ matrix.php >= 7.3 }}
- run: vendor/bin/phpunit --coverage-text -c phpunit.xml.legacy
if: ${{ matrix.php < 7.3 }}
41 changes: 27 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ It is heavily influenced by [async.js](https://github.com/caolan/async).

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

## About

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

## Install
**Table of Contents**

The recommended way to install react/async is [through
composer](http://getcomposer.org).
* [Usage](#usage)
* [Parallel](#parallel)
* [Waterfall](#waterfall)
* [Todo](#todo)
* [Install](#install)
* [Tests](#tests)
* [License](#license)

```JSON
{
"require": {
"react/async": "~1.0"
}
}
```

## Example
## Usage

### Parallel

Expand Down Expand Up @@ -110,6 +105,24 @@ Async::waterfall(array(

* Implement queue()

## Install

The recommended way to install this library is [through Composer](https://getcomposer.org/).
[New to Composer?](https://getcomposer.org/doc/00-intro.md)

Once released, this project will follow [SemVer](https://semver.org/).
At the moment, this will install the latest development version:

```bash
$ composer require react/async:dev-main
```

See also the [CHANGELOG](CHANGELOG.md) for details about version upgrades.

This project aims to run on any platform and thus does not require any PHP
extensions and supports running on legacy PHP 5.3 through current PHP 8+.
It's *highly recommended to use the latest supported PHP version* for this project.

## Tests

To run the test suite, you first need to clone this repo and then install all
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
"php": ">=5.3.2"
},
"require-dev": {
"phpunit/phpunit": "^5.7 || ^4.8.35",
"phpunit/phpunit": "^9.3 || ^5.7 || ^4.8.35",
"react/event-loop": "^1.2"
},
"suggest": {
Expand Down
26 changes: 10 additions & 16 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,25 +1,19 @@
<?xml version="1.0" encoding="UTF-8"?>

<phpunit backupGlobals="false"
backupStaticAttributes="false"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false"
syntaxCheck="false"
<!-- 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="React-Async Test Suite">
<testsuite name="React Test Suite">
<directory>./tests/</directory>
</testsuite>
</testsuites>

<filter>
<whitelist>
<coverage>
<include>
<directory>./src/</directory>
</whitelist>
</filter>
</include>
</coverage>
</phpunit>
18 changes: 18 additions & 0 deletions phpunit.xml.legacy
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="UTF-8"?>

<!-- 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="React Test Suite">
<directory>./tests/</directory>
</testsuite>
</testsuites>
<filter>
<whitelist>
<directory>./src/</directory>
</whitelist>
</filter>
</phpunit>
50 changes: 36 additions & 14 deletions tests/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,49 @@

namespace React\Tests\Async;

class TestCase extends \PHPUnit_Framework_TestCase
use PHPUnit\Framework\TestCase as BaseTestCase;

class TestCase extends BaseTestCase
{
protected function createCallableMock($expects, $with = null)
protected function expectCallableOnce()
{
$callable = $this->getMockBuilder('React\Tests\Async\CallableStub')->getMock();

$method = $callable
->expects($expects)
$mock = $this->createCallableMock();
$mock
->expects($this->once())
->method('__invoke');

if ($with) {
$method->with($with);
}
return $mock;
}

return $callable;
protected function expectCallableOnceWith($value)
{
$mock = $this->createCallableMock();
$mock
->expects($this->once())
->method('__invoke')
->with($value);

return $mock;
}
}

class CallableStub
{
public function __invoke()
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();
}
}
}
16 changes: 8 additions & 8 deletions tests/UtilParallelTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ public function testParallelWithoutTasks()
{
$tasks = array();

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

Util::parallel($tasks, $callback, $errback);
}
Expand All @@ -32,8 +32,8 @@ function ($callback, $errback) {
},
);

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

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

Expand Down Expand Up @@ -65,8 +65,8 @@ function ($callback, $errback) use (&$called) {
},
);

$callback = $this->createCallableMock($this->never());
$errback = $this->createCallableMock($this->once());
$callback = $this->expectCallableNever();
$errback = $this->expectCallableOnce();

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

Expand Down Expand Up @@ -94,8 +94,8 @@ function ($callback, $errback) use (&$called) {
},
);

$callback = $this->createCallableMock($this->never());
$errback = $this->createCallableMock($this->once());
$callback = $this->expectCallableNever();
$errback = $this->expectCallableOnce();

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

Expand Down
12 changes: 6 additions & 6 deletions tests/UtilSeriesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ public function testSeriesWithoutTasks()
{
$tasks = array();

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

Util::series($tasks, $callback, $errback);
}
Expand All @@ -32,8 +32,8 @@ function ($callback, $errback) {
},
);

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

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

Expand Down Expand Up @@ -65,8 +65,8 @@ function ($callback, $errback) use (&$called) {
},
);

$callback = $this->createCallableMock($this->never());
$errback = $this->createCallableMock($this->once());
$callback = $this->expectCallableNever();
$errback = $this->expectCallableOnce();

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

Expand Down
12 changes: 6 additions & 6 deletions tests/UtilWaterfallTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ public function testWaterfallWithoutTasks()
{
$tasks = array();

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

Util::waterfall($tasks, $callback, $errback);
}
Expand All @@ -37,8 +37,8 @@ function ($bar, $callback, $errback) {
},
);

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

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

Expand Down Expand Up @@ -70,8 +70,8 @@ function ($callback, $errback) use (&$called) {
},
);

$callback = $this->createCallableMock($this->never());
$errback = $this->createCallableMock($this->once());
$callback = $this->expectCallableNever();
$errback = $this->expectCallableOnce();

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

Expand Down