-
-
Notifications
You must be signed in to change notification settings - Fork 38
Expand file tree
/
Copy pathDirectoryTest.php
More file actions
62 lines (51 loc) · 1.8 KB
/
DirectoryTest.php
File metadata and controls
62 lines (51 loc) · 1.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
<?php
namespace React\Tests\Filesystem;
use React\Filesystem\AdapterInterface;
use React\Filesystem\Node\DirectoryInterface;
use React\Filesystem\Node\FileInterface;
use React\Filesystem\Stat;
use React\Promise\PromiseInterface;
use function React\Async\await;
final class DirectoryTest extends AbstractFilesystemTestCase
{
/**
* @test
*
* @dataProvider provideFilesystems
*/
public function stat(AdapterInterface $filesystem): void
{
$stat = await($filesystem->detect(__DIR__)->then(static function (DirectoryInterface $directory): PromiseInterface {
return $directory->stat();
}));
self::assertInstanceOf(Stat::class, $stat);
self::assertSame(stat(__DIR__)['size'], $stat->size());
}
/**
* @test
*
* @dataProvider provideFilesystems
*/
public function ls(AdapterInterface $filesystem): void
{
$expectedListing = [];
$d = dir(__DIR__);
while (false !== ($entry = $d->read())) {
if ($entry === '.' || $entry === '..') {
continue;
}
$expectedListing[__DIR__ . DIRECTORY_SEPARATOR . $entry] = is_file(__DIR__ . DIRECTORY_SEPARATOR . $entry) ? FileInterface::class : DirectoryInterface::class;
}
$d->close();
ksort($expectedListing);
$directoryListing = await($filesystem->detect(__DIR__)->then(static function (DirectoryInterface $directory): PromiseInterface {
return $directory->ls();
}));
$listing = [];
foreach ($directoryListing as $node) {
$listing[$node->path() . $node->name()] = $node instanceof FileInterface ? FileInterface::class : DirectoryInterface::class;
}
ksort($listing);
self::assertSame($expectedListing, $listing);
}
}