Skip to content

Commit

Permalink
Update test suite to use new reactphp/async package instead of clue/r…
Browse files Browse the repository at this point in the history
  • Loading branch information
WyriHaximus committed Aug 24, 2022
1 parent 41fefa4 commit f0d3273
Show file tree
Hide file tree
Showing 8 changed files with 102 additions and 103 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
147 changes: 77 additions & 70 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 0 additions & 7 deletions tests/AbstractFilesystemTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -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);
}
}
6 changes: 3 additions & 3 deletions tests/DirectoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -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();
}));

Expand Down Expand Up @@ -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();
}));

Expand Down
4 changes: 2 additions & 2 deletions tests/FactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -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);
}
Expand Down
27 changes: 13 additions & 14 deletions tests/FileTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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();
}));

Expand All @@ -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();
}));

Expand All @@ -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);
}));

Expand All @@ -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);
}));

Expand All @@ -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++) {
Expand All @@ -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)));
Expand All @@ -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);
}));

Expand All @@ -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;
Expand All @@ -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);
}));
}
Expand Down Expand Up @@ -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)));
Expand All @@ -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();
}));

Expand Down
Loading

0 comments on commit f0d3273

Please sign in to comment.