diff --git a/.gitattributes b/.gitattributes index aa6c312..21be40c 100644 --- a/.gitattributes +++ b/.gitattributes @@ -2,4 +2,5 @@ /.github/ export-ignore /.gitignore export-ignore /phpunit.xml.dist export-ignore +/phpunit.xml.legacy export-ignore /tests/ export-ignore diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 559f37d..13eaf46 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -11,6 +11,8 @@ jobs: strategy: matrix: php: + - 8.1 + - 8.0 - 7.4 - 7.3 - 7.2 @@ -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 }} diff --git a/README.md b/README.md index 3355aab..77a0774 100644 --- a/README.md +++ b/README.md @@ -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 @@ -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 @@ -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 diff --git a/composer.json b/composer.json index fc685f7..d864160 100644 --- a/composer.json +++ b/composer.json @@ -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": { diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 49eb132..fa88e7e 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -1,25 +1,19 @@ - + + colors="true" + cacheResult="false"> - + ./tests/ - - - + + ./src/ - - + + diff --git a/phpunit.xml.legacy b/phpunit.xml.legacy new file mode 100644 index 0000000..fbb43e8 --- /dev/null +++ b/phpunit.xml.legacy @@ -0,0 +1,18 @@ + + + + + + + ./tests/ + + + + + ./src/ + + + diff --git a/tests/TestCase.php b/tests/TestCase.php index 43a68e4..48f2879 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -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(); + } } } diff --git a/tests/UtilParallelTest.php b/tests/UtilParallelTest.php index 022f78c..62c59b7 100644 --- a/tests/UtilParallelTest.php +++ b/tests/UtilParallelTest.php @@ -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); } @@ -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); @@ -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); @@ -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); diff --git a/tests/UtilSeriesTest.php b/tests/UtilSeriesTest.php index ff4ce53..95fa182 100644 --- a/tests/UtilSeriesTest.php +++ b/tests/UtilSeriesTest.php @@ -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); } @@ -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); @@ -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); diff --git a/tests/UtilWaterfallTest.php b/tests/UtilWaterfallTest.php index e3b6052..b8d384b 100644 --- a/tests/UtilWaterfallTest.php +++ b/tests/UtilWaterfallTest.php @@ -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); } @@ -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); @@ -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); pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy