Skip to content

Commit f0d3273

Browse files
committed
Update test suite to use new reactphp/async package instead of clue/reactphp-block
See https://github.com/reactphp/async Refs reactphp/socket#296
1 parent 41fefa4 commit f0d3273

File tree

8 files changed

+102
-103
lines changed

8 files changed

+102
-103
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
"wyrihaximus/react-child-process-promise-closure": "^1.0"
2222
},
2323
"require-dev": {
24-
"clue/block-react": "^1.4",
24+
"react/async": "^4 || ^3",
2525
"phpunit/phpunit": "^9.5"
2626
},
2727
"autoload": {

composer.lock

Lines changed: 77 additions & 70 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/AbstractFilesystemTestCase.php

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@
1111
use React\EventLoop\LoopInterface;
1212
use React\Filesystem\Factory;
1313
use React\Filesystem\AdapterInterface;
14-
use React\Promise\PromiseInterface;
15-
use function Clue\React\Block\await;
1614

1715
abstract class AbstractFilesystemTestCase extends TestCase
1816
{
@@ -35,9 +33,4 @@ final public function provideFilesystems(): iterable
3533

3634
yield 'factory' => [Factory::create()];
3735
}
38-
39-
public function await(PromiseInterface $promise)
40-
{
41-
return await($promise, EventLoop\Loop::get(), 30);
42-
}
4336
}

tests/DirectoryTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
use React\Filesystem\Node\FileInterface;
99
use React\Filesystem\Stat;
1010
use React\Promise\PromiseInterface;
11-
use function Clue\React\Block\await;
11+
use function React\Async\await;
1212

1313
final class DirectoryTest extends AbstractFilesystemTestCase
1414
{
@@ -19,7 +19,7 @@ final class DirectoryTest extends AbstractFilesystemTestCase
1919
*/
2020
public function stat(AdapterInterface $filesystem): void
2121
{
22-
$stat = $this->await($filesystem->detect(__DIR__)->then(static function (DirectoryInterface $directory): PromiseInterface {
22+
$stat = await($filesystem->detect(__DIR__)->then(static function (DirectoryInterface $directory): PromiseInterface {
2323
return $directory->stat();
2424
}));
2525

@@ -48,7 +48,7 @@ public function ls(AdapterInterface $filesystem): void
4848

4949
ksort($expectedListing);
5050

51-
$directoryListing = $this->await($filesystem->detect(__DIR__)->then(static function (DirectoryInterface $directory): PromiseInterface {
51+
$directoryListing = await($filesystem->detect(__DIR__)->then(static function (DirectoryInterface $directory): PromiseInterface {
5252
return $directory->ls();
5353
}));
5454

tests/FactoryTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
use React\Filesystem\AdapterInterface;
99
use React\Filesystem\Node\DirectoryInterface;
1010
use React\Filesystem\Node\FileInterface;
11-
use function Clue\React\Block\await;
11+
use function React\Async\await;
1212

1313
final class FactoryTest extends AbstractFilesystemTestCase
1414
{
@@ -17,7 +17,7 @@ final class FactoryTest extends AbstractFilesystemTestCase
1717
*/
1818
public function factory(): void
1919
{
20-
$node = $this->await(Factory::create()->detect(__FILE__));
20+
$node = await(Factory::create()->detect(__FILE__));
2121

2222
self::assertInstanceOf(FileInterface::class, $node);
2323
}

tests/FileTest.php

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,13 @@
22

33
namespace React\Tests\Filesystem;
44

5-
use React\EventLoop\LoopInterface;
65
use React\Filesystem\AdapterInterface;
76
use React\Filesystem\Node\FileInterface;
87
use React\Filesystem\Node\NotExistInterface;
98
use React\Filesystem\Stat;
109
use React\Promise\Promise;
1110
use React\Promise\PromiseInterface;
12-
use function Clue\React\Block\await;
11+
use function React\Async\await;
1312
use function React\Promise\all;
1413

1514
final class FileTest extends AbstractFilesystemTestCase
@@ -21,7 +20,7 @@ final class FileTest extends AbstractFilesystemTestCase
2120
*/
2221
public function stat(AdapterInterface $filesystem): void
2322
{
24-
$stat = $this->await($filesystem->detect(__FILE__)->then(static function (FileInterface $file): PromiseInterface {
23+
$stat = await($filesystem->detect(__FILE__)->then(static function (FileInterface $file): PromiseInterface {
2524
return $file->stat();
2625
}));
2726

@@ -36,7 +35,7 @@ public function stat(AdapterInterface $filesystem): void
3635
*/
3736
public function getContents(AdapterInterface $filesystem): void
3837
{
39-
$fileContents = $this->await($filesystem->detect(__FILE__)->then(static function (FileInterface $file): PromiseInterface {
38+
$fileContents = await($filesystem->detect(__FILE__)->then(static function (FileInterface $file): PromiseInterface {
4039
return $file->getContents();
4140
}));
4241

@@ -54,7 +53,7 @@ public function getContents34and5thCharacterFromFile(AdapterInterface $filesyste
5453
$fileName = $directoryName . bin2hex(random_bytes(13));
5554
mkdir($directoryName);
5655
\file_put_contents($fileName, 'abcdefghijklmnopqrstuvwxyz');
57-
$fileContents = $this->await($filesystem->detect($fileName)->then(static function (FileInterface $file): PromiseInterface {
56+
$fileContents = await($filesystem->detect($fileName)->then(static function (FileInterface $file): PromiseInterface {
5857
return $file->getContents(3, 3);
5958
}));
6059

@@ -71,7 +70,7 @@ public function putContents(AdapterInterface $filesystem): void
7170
$fileName = sys_get_temp_dir() . DIRECTORY_SEPARATOR . bin2hex(random_bytes(13)) . DIRECTORY_SEPARATOR . bin2hex(random_bytes(9));
7271
$fileContents = bin2hex(random_bytes(128));
7372

74-
$writtenLength = $this->await($filesystem->detect($fileName)->then(static fn (NotExistInterface $notExist): PromiseInterface => $notExist->createFile())->then(function (FileInterface $file) use ($fileContents): PromiseInterface {
73+
$writtenLength = await($filesystem->detect($fileName)->then(static fn (NotExistInterface $notExist): PromiseInterface => $notExist->createFile())->then(function (FileInterface $file) use ($fileContents): PromiseInterface {
7574
return $file->putContents($fileContents);
7675
}));
7776

@@ -89,7 +88,7 @@ public function putContents(AdapterInterface $filesystem): void
8988
public function putContentsMultipleBigFiles(AdapterInterface $filesystem): void
9089
{
9190
$directoryName = sys_get_temp_dir() . DIRECTORY_SEPARATOR . bin2hex(random_bytes(13)) . DIRECTORY_SEPARATOR;
92-
$this->await($filesystem->detect($directoryName)->then(static fn(NotExistInterface $notExist): PromiseInterface => $notExist->createDirectory()));
91+
await($filesystem->detect($directoryName)->then(static fn(NotExistInterface $notExist): PromiseInterface => $notExist->createDirectory()));
9392
$fileNames = [];
9493
$fileContents = [];
9594
for ($i = 0; $i < 25; $i++) {
@@ -107,7 +106,7 @@ public function putContentsMultipleBigFiles(AdapterInterface $filesystem): void
107106
});
108107
}
109108

110-
$writtenLengths = $this->await(all($promises));
109+
$writtenLengths = await(all($promises));
111110

112111
foreach ($writtenLengths as $fileName => $writtenLength) {
113112
self::assertSame($writtenLength, strlen(file_get_contents($fileName)));
@@ -126,14 +125,14 @@ public function putContentsAppend(AdapterInterface $filesystem): void
126125
$fileName = sys_get_temp_dir() . DIRECTORY_SEPARATOR . bin2hex(random_bytes(13)) . DIRECTORY_SEPARATOR . bin2hex(random_bytes(9));
127126
$fileContentsFirst = bin2hex(random_bytes(128));
128127
$fileContentsSecond = bin2hex(random_bytes(128));
129-
$writtenLengthFirst = $this->await($filesystem->detect($fileName)->then(static fn (NotExistInterface $notExist): PromiseInterface => $notExist->createFile())->then(static function (FileInterface $file) use ($fileContentsFirst): PromiseInterface {
128+
$writtenLengthFirst = await($filesystem->detect($fileName)->then(static fn (NotExistInterface $notExist): PromiseInterface => $notExist->createFile())->then(static function (FileInterface $file) use ($fileContentsFirst): PromiseInterface {
130129
return $file->putContents($fileContentsFirst);
131130
}));
132131

133132
self::assertSame($writtenLengthFirst, strlen(file_get_contents($fileName)));
134133
self::assertSame($fileContentsFirst, file_get_contents($fileName));
135134

136-
$writtenLengthSecond = $this->await($filesystem->detect($fileName)->then(static function (FileInterface $file) use ($fileContentsSecond): PromiseInterface {
135+
$writtenLengthSecond = await($filesystem->detect($fileName)->then(static function (FileInterface $file) use ($fileContentsSecond): PromiseInterface {
137136
return $file->putContents($fileContentsSecond, \FILE_APPEND);
138137
}));
139138

@@ -151,7 +150,7 @@ public function putContentsAppend(AdapterInterface $filesystem): void
151150
public function putContentsAppendBigFile(AdapterInterface $filesystem): void
152151
{
153152
$fileName = sys_get_temp_dir() . DIRECTORY_SEPARATOR . bin2hex(random_bytes(13)) . DIRECTORY_SEPARATOR . bin2hex(random_bytes(9));
154-
$this->await($filesystem->detect($fileName)->then(static fn(NotExistInterface $notExist): PromiseInterface => $notExist->createFile()));
153+
await($filesystem->detect($fileName)->then(static fn(NotExistInterface $notExist): PromiseInterface => $notExist->createFile()));
155154

156155
$fileContents = [];
157156
$writtenLength = 0;
@@ -160,7 +159,7 @@ public function putContentsAppendBigFile(AdapterInterface $filesystem): void
160159
}
161160

162161
foreach ($fileContents as $fileContent) {
163-
$writtenLength += $this->await($filesystem->detect($fileName)->then(static function (FileInterface $file) use ($fileContent): PromiseInterface {
162+
$writtenLength += await($filesystem->detect($fileName)->then(static function (FileInterface $file) use ($fileContent): PromiseInterface {
164163
return $file->putContents($fileContent, \FILE_APPEND);
165164
}));
166165
}
@@ -246,7 +245,7 @@ public function runMultipleFilesTests(AdapterInterface $filesystem, int $fileCou
246245
});
247246
}
248247

249-
$writtenLengths = $this->await(all($promises));
248+
$writtenLengths = await(all($promises));
250249

251250
foreach ($writtenLengths as $fileName => $writtenLength) {
252251
self::assertSame($writtenLength, strlen(file_get_contents($fileName)));
@@ -266,7 +265,7 @@ public function unlink(AdapterInterface $filesystem): void
266265
$fileContents = bin2hex(random_bytes(2048));
267266
file_put_contents($fileName, $fileContents);
268267
self::assertFileExists($fileName);
269-
$this->await($filesystem->detect($fileName)->then(static function (FileInterface $file): PromiseInterface {
268+
await($filesystem->detect($fileName)->then(static function (FileInterface $file): PromiseInterface {
270269
return $file->unlink();
271270
}));
272271

0 commit comments

Comments
 (0)