diff --git a/composer.json b/composer.json index 52f0de90..2eacda19 100644 --- a/composer.json +++ b/composer.json @@ -21,7 +21,7 @@ "wyrihaximus/react-child-process-promise-closure": "^1.0" }, "require-dev": { - "clue/block-react": "^1.4", + "react/async": "^4 || ^3", "phpunit/phpunit": "^9.5" }, "autoload": { diff --git a/composer.lock b/composer.lock index b912387b..e060d182 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "f5ce03ce451f08ea50b1130047d65bfa", + "content-hash": "a4ee446ea766560303dbd6d63184a24b", "packages": [ { "name": "cakephp/core", @@ -1885,74 +1885,6 @@ } ], "packages-dev": [ - { - "name": "clue/block-react", - "version": "v1.5.0", - "source": { - "type": "git", - "url": "https://github.com/clue/reactphp-block.git", - "reference": "718b0571a94aa693c6fffc72182e87257ac900f3" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/clue/reactphp-block/zipball/718b0571a94aa693c6fffc72182e87257ac900f3", - "reference": "718b0571a94aa693c6fffc72182e87257ac900f3", - "shasum": "" - }, - "require": { - "php": ">=5.3", - "react/event-loop": "^1.2", - "react/promise": "^3.0 || ^2.7 || ^1.2.1", - "react/promise-timer": "^1.5" - }, - "require-dev": { - "phpunit/phpunit": "^9.3 || ^5.7 || ^4.8.35", - "react/http": "^1.4" - }, - "type": "library", - "autoload": { - "files": [ - "src/functions_include.php" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Christian Lück", - "email": "christian@clue.engineering" - } - ], - "description": "Lightweight library that eases integrating async components built for ReactPHP in a traditional, blocking environment.", - "homepage": "https://github.com/clue/reactphp-block", - "keywords": [ - "async", - "await", - "blocking", - "event loop", - "promise", - "reactphp", - "sleep", - "synchronous" - ], - "support": { - "issues": "https://github.com/clue/reactphp-block/issues", - "source": "https://github.com/clue/reactphp-block/tree/v1.5.0" - }, - "funding": [ - { - "url": "https://clue.engineering/support", - "type": "custom" - }, - { - "url": "https://github.com/clue", - "type": "github" - } - ], - "time": "2021-10-20T14:07:33+00:00" - }, { "name": "myclabs/deep-copy", "version": "1.10.2", @@ -2823,6 +2755,81 @@ ], "time": "2022-01-24T07:33:35+00:00" }, + { + "name": "react/async", + "version": "v3.0.0", + "source": { + "type": "git", + "url": "https://github.com/reactphp/async.git", + "reference": "3c3b812be77aec14bf8300b052ba589c9a5bc95b" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/reactphp/async/zipball/3c3b812be77aec14bf8300b052ba589c9a5bc95b", + "reference": "3c3b812be77aec14bf8300b052ba589c9a5bc95b", + "shasum": "" + }, + "require": { + "php": ">=7.1", + "react/event-loop": "^1.2", + "react/promise": "^3.0 || ^2.8 || ^1.2.1" + }, + "require-dev": { + "phpunit/phpunit": "^9.3 || ^7.5" + }, + "type": "library", + "autoload": { + "files": [ + "src/functions_include.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Christian Lück", + "email": "christian@clue.engineering", + "homepage": "https://clue.engineering/" + }, + { + "name": "Cees-Jan Kiewiet", + "email": "reactphp@ceesjankiewiet.nl", + "homepage": "https://wyrihaximus.net/" + }, + { + "name": "Jan Sorgalla", + "email": "jsorgalla@gmail.com", + "homepage": "https://sorgalla.com/" + }, + { + "name": "Chris Boden", + "email": "cboden@gmail.com", + "homepage": "https://cboden.dev/" + } + ], + "description": "Async utilities for ReactPHP", + "keywords": [ + "async", + "reactphp" + ], + "support": { + "issues": "https://github.com/reactphp/async/issues", + "source": "https://github.com/reactphp/async/tree/v3.0.0" + }, + "funding": [ + { + "url": "https://github.com/WyriHaximus", + "type": "github" + }, + { + "url": "https://github.com/clue", + "type": "github" + } + ], + "time": "2022-07-11T14:17:23+00:00" + }, { "name": "sebastian/cli-parser", "version": "1.0.1", @@ -3990,5 +3997,5 @@ "platform-overrides": { "php": "7.4.7" }, - "plugin-api-version": "2.2.0" + "plugin-api-version": "2.3.0" } diff --git a/tests/AbstractFilesystemTestCase.php b/tests/AbstractFilesystemTestCase.php index 0e46e14b..87a27e0a 100644 --- a/tests/AbstractFilesystemTestCase.php +++ b/tests/AbstractFilesystemTestCase.php @@ -11,8 +11,6 @@ use React\EventLoop\LoopInterface; use React\Filesystem\Factory; use React\Filesystem\AdapterInterface; -use React\Promise\PromiseInterface; -use function Clue\React\Block\await; abstract class AbstractFilesystemTestCase extends TestCase { @@ -35,9 +33,4 @@ final public function provideFilesystems(): iterable yield 'factory' => [Factory::create()]; } - - public function await(PromiseInterface $promise) - { - return await($promise, EventLoop\Loop::get(), 30); - } } diff --git a/tests/DirectoryTest.php b/tests/DirectoryTest.php index d8f2f54d..575fd2c8 100644 --- a/tests/DirectoryTest.php +++ b/tests/DirectoryTest.php @@ -8,7 +8,7 @@ use React\Filesystem\Node\FileInterface; use React\Filesystem\Stat; use React\Promise\PromiseInterface; -use function Clue\React\Block\await; +use function React\Async\await; final class DirectoryTest extends AbstractFilesystemTestCase { @@ -19,7 +19,7 @@ final class DirectoryTest extends AbstractFilesystemTestCase */ public function stat(AdapterInterface $filesystem): void { - $stat = $this->await($filesystem->detect(__DIR__)->then(static function (DirectoryInterface $directory): PromiseInterface { + $stat = await($filesystem->detect(__DIR__)->then(static function (DirectoryInterface $directory): PromiseInterface { return $directory->stat(); })); @@ -48,7 +48,7 @@ public function ls(AdapterInterface $filesystem): void ksort($expectedListing); - $directoryListing = $this->await($filesystem->detect(__DIR__)->then(static function (DirectoryInterface $directory): PromiseInterface { + $directoryListing = await($filesystem->detect(__DIR__)->then(static function (DirectoryInterface $directory): PromiseInterface { return $directory->ls(); })); diff --git a/tests/FactoryTest.php b/tests/FactoryTest.php index a87fd0e0..50d20765 100644 --- a/tests/FactoryTest.php +++ b/tests/FactoryTest.php @@ -8,7 +8,7 @@ use React\Filesystem\AdapterInterface; use React\Filesystem\Node\DirectoryInterface; use React\Filesystem\Node\FileInterface; -use function Clue\React\Block\await; +use function React\Async\await; final class FactoryTest extends AbstractFilesystemTestCase { @@ -17,7 +17,7 @@ final class FactoryTest extends AbstractFilesystemTestCase */ public function factory(): void { - $node = $this->await(Factory::create()->detect(__FILE__)); + $node = await(Factory::create()->detect(__FILE__)); self::assertInstanceOf(FileInterface::class, $node); } diff --git a/tests/FileTest.php b/tests/FileTest.php index 438b62fa..e443a062 100644 --- a/tests/FileTest.php +++ b/tests/FileTest.php @@ -2,14 +2,13 @@ namespace React\Tests\Filesystem; -use React\EventLoop\LoopInterface; use React\Filesystem\AdapterInterface; use React\Filesystem\Node\FileInterface; use React\Filesystem\Node\NotExistInterface; use React\Filesystem\Stat; use React\Promise\Promise; use React\Promise\PromiseInterface; -use function Clue\React\Block\await; +use function React\Async\await; use function React\Promise\all; final class FileTest extends AbstractFilesystemTestCase @@ -21,7 +20,7 @@ final class FileTest extends AbstractFilesystemTestCase */ public function stat(AdapterInterface $filesystem): void { - $stat = $this->await($filesystem->detect(__FILE__)->then(static function (FileInterface $file): PromiseInterface { + $stat = await($filesystem->detect(__FILE__)->then(static function (FileInterface $file): PromiseInterface { return $file->stat(); })); @@ -36,7 +35,7 @@ public function stat(AdapterInterface $filesystem): void */ public function getContents(AdapterInterface $filesystem): void { - $fileContents = $this->await($filesystem->detect(__FILE__)->then(static function (FileInterface $file): PromiseInterface { + $fileContents = await($filesystem->detect(__FILE__)->then(static function (FileInterface $file): PromiseInterface { return $file->getContents(); })); @@ -54,7 +53,7 @@ public function getContents34and5thCharacterFromFile(AdapterInterface $filesyste $fileName = $directoryName . bin2hex(random_bytes(13)); mkdir($directoryName); \file_put_contents($fileName, 'abcdefghijklmnopqrstuvwxyz'); - $fileContents = $this->await($filesystem->detect($fileName)->then(static function (FileInterface $file): PromiseInterface { + $fileContents = await($filesystem->detect($fileName)->then(static function (FileInterface $file): PromiseInterface { return $file->getContents(3, 3); })); @@ -71,7 +70,7 @@ public function putContents(AdapterInterface $filesystem): void $fileName = sys_get_temp_dir() . DIRECTORY_SEPARATOR . bin2hex(random_bytes(13)) . DIRECTORY_SEPARATOR . bin2hex(random_bytes(9)); $fileContents = bin2hex(random_bytes(128)); - $writtenLength = $this->await($filesystem->detect($fileName)->then(static fn (NotExistInterface $notExist): PromiseInterface => $notExist->createFile())->then(function (FileInterface $file) use ($fileContents): PromiseInterface { + $writtenLength = await($filesystem->detect($fileName)->then(static fn (NotExistInterface $notExist): PromiseInterface => $notExist->createFile())->then(function (FileInterface $file) use ($fileContents): PromiseInterface { return $file->putContents($fileContents); })); @@ -89,7 +88,7 @@ public function putContents(AdapterInterface $filesystem): void public function putContentsMultipleBigFiles(AdapterInterface $filesystem): void { $directoryName = sys_get_temp_dir() . DIRECTORY_SEPARATOR . bin2hex(random_bytes(13)) . DIRECTORY_SEPARATOR; - $this->await($filesystem->detect($directoryName)->then(static fn(NotExistInterface $notExist): PromiseInterface => $notExist->createDirectory())); + await($filesystem->detect($directoryName)->then(static fn(NotExistInterface $notExist): PromiseInterface => $notExist->createDirectory())); $fileNames = []; $fileContents = []; for ($i = 0; $i < 25; $i++) { @@ -107,7 +106,7 @@ public function putContentsMultipleBigFiles(AdapterInterface $filesystem): void }); } - $writtenLengths = $this->await(all($promises)); + $writtenLengths = await(all($promises)); foreach ($writtenLengths as $fileName => $writtenLength) { self::assertSame($writtenLength, strlen(file_get_contents($fileName))); @@ -126,14 +125,14 @@ public function putContentsAppend(AdapterInterface $filesystem): void $fileName = sys_get_temp_dir() . DIRECTORY_SEPARATOR . bin2hex(random_bytes(13)) . DIRECTORY_SEPARATOR . bin2hex(random_bytes(9)); $fileContentsFirst = bin2hex(random_bytes(128)); $fileContentsSecond = bin2hex(random_bytes(128)); - $writtenLengthFirst = $this->await($filesystem->detect($fileName)->then(static fn (NotExistInterface $notExist): PromiseInterface => $notExist->createFile())->then(static function (FileInterface $file) use ($fileContentsFirst): PromiseInterface { + $writtenLengthFirst = await($filesystem->detect($fileName)->then(static fn (NotExistInterface $notExist): PromiseInterface => $notExist->createFile())->then(static function (FileInterface $file) use ($fileContentsFirst): PromiseInterface { return $file->putContents($fileContentsFirst); })); self::assertSame($writtenLengthFirst, strlen(file_get_contents($fileName))); self::assertSame($fileContentsFirst, file_get_contents($fileName)); - $writtenLengthSecond = $this->await($filesystem->detect($fileName)->then(static function (FileInterface $file) use ($fileContentsSecond): PromiseInterface { + $writtenLengthSecond = await($filesystem->detect($fileName)->then(static function (FileInterface $file) use ($fileContentsSecond): PromiseInterface { return $file->putContents($fileContentsSecond, \FILE_APPEND); })); @@ -151,7 +150,7 @@ public function putContentsAppend(AdapterInterface $filesystem): void public function putContentsAppendBigFile(AdapterInterface $filesystem): void { $fileName = sys_get_temp_dir() . DIRECTORY_SEPARATOR . bin2hex(random_bytes(13)) . DIRECTORY_SEPARATOR . bin2hex(random_bytes(9)); - $this->await($filesystem->detect($fileName)->then(static fn(NotExistInterface $notExist): PromiseInterface => $notExist->createFile())); + await($filesystem->detect($fileName)->then(static fn(NotExistInterface $notExist): PromiseInterface => $notExist->createFile())); $fileContents = []; $writtenLength = 0; @@ -160,7 +159,7 @@ public function putContentsAppendBigFile(AdapterInterface $filesystem): void } foreach ($fileContents as $fileContent) { - $writtenLength += $this->await($filesystem->detect($fileName)->then(static function (FileInterface $file) use ($fileContent): PromiseInterface { + $writtenLength += await($filesystem->detect($fileName)->then(static function (FileInterface $file) use ($fileContent): PromiseInterface { return $file->putContents($fileContent, \FILE_APPEND); })); } @@ -246,7 +245,7 @@ public function runMultipleFilesTests(AdapterInterface $filesystem, int $fileCou }); } - $writtenLengths = $this->await(all($promises)); + $writtenLengths = await(all($promises)); foreach ($writtenLengths as $fileName => $writtenLength) { self::assertSame($writtenLength, strlen(file_get_contents($fileName))); @@ -266,7 +265,7 @@ public function unlink(AdapterInterface $filesystem): void $fileContents = bin2hex(random_bytes(2048)); file_put_contents($fileName, $fileContents); self::assertFileExists($fileName); - $this->await($filesystem->detect($fileName)->then(static function (FileInterface $file): PromiseInterface { + await($filesystem->detect($fileName)->then(static function (FileInterface $file): PromiseInterface { return $file->unlink(); })); diff --git a/tests/FilesystemTest.php b/tests/FilesystemTest.php index fb91c620..71d094dd 100644 --- a/tests/FilesystemTest.php +++ b/tests/FilesystemTest.php @@ -2,12 +2,11 @@ namespace React\Tests\Filesystem; -use React\EventLoop\LoopInterface; use React\Filesystem\AdapterInterface; use React\Filesystem\Node\DirectoryInterface; use React\Filesystem\Node\FileInterface; use React\Filesystem\Node\NotExistInterface; -use function Clue\React\Block\await; +use function React\Async\await; final class FilesystemTest extends AbstractFilesystemTestCase { @@ -18,7 +17,7 @@ final class FilesystemTest extends AbstractFilesystemTestCase */ public function file(AdapterInterface $filesystem): void { - $node = $this->await($filesystem->detect(__FILE__)); + $node = await($filesystem->detect(__FILE__)); self::assertInstanceOf(FileInterface::class, $node); } @@ -30,7 +29,7 @@ public function file(AdapterInterface $filesystem): void */ public function directory(AdapterInterface $filesystem): void { - $node = $this->await($filesystem->detect(__DIR__)); + $node = await($filesystem->detect(__DIR__)); self::assertInstanceOf(DirectoryInterface::class, $node); } @@ -42,7 +41,7 @@ public function directory(AdapterInterface $filesystem): void */ public function notExists(AdapterInterface $filesystem): void { - $node = $this->await($filesystem->detect(bin2hex(random_bytes(13)))); + $node = await($filesystem->detect(bin2hex(random_bytes(13)))); self::assertInstanceOf(NotExistInterface::class, $node); } diff --git a/tests/NotExistTest.php b/tests/NotExistTest.php index ada8fc75..eb1512c8 100644 --- a/tests/NotExistTest.php +++ b/tests/NotExistTest.php @@ -5,6 +5,7 @@ use React\Filesystem\AdapterInterface; use React\Filesystem\Node\NotExistInterface; use React\Promise\PromiseInterface; +use function React\Async\await; final class NotExistTest extends AbstractFilesystemTestCase { @@ -16,7 +17,7 @@ final class NotExistTest extends AbstractFilesystemTestCase public function createDirectory(AdapterInterface $filesystem): void { $dirName = sys_get_temp_dir() . DIRECTORY_SEPARATOR . 'reactphp-filesystem-' . bin2hex(random_bytes(13)) . DIRECTORY_SEPARATOR; - $this->await($filesystem->detect($dirName)->then(static function (NotExistInterface $notExist): PromiseInterface { + await($filesystem->detect($dirName)->then(static function (NotExistInterface $notExist): PromiseInterface { return $notExist->createDirectory(); }));