-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathFallbackWatcherTest.php
More file actions
96 lines (76 loc) · 2.76 KB
/
Copy pathFallbackWatcherTest.php
File metadata and controls
96 lines (76 loc) · 2.76 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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
<?php
namespace Phpactor\AmpFsWatcher\Tests\Watcher\Fallback;
use Amp\PHPUnit\AsyncTestCase;
use Amp\Success;
use Generator;
use Phpactor\AmpFsWatch\Watcher;
use Phpactor\AmpFsWatch\Watcher\Fallback\FallbackWatcher;
use Phpactor\AmpFsWatch\Watcher\Null\NullWatcher;
use Prophecy\Argument;
use Prophecy\Prophecy\ObjectProphecy;
use Psr\Log\LoggerInterface;
class FallbackWatcherTest extends AsyncTestCase
{
use \Prophecy\PhpUnit\ProphecyTrait;
private ObjectProphecy|LoggerInterface $logger;
private ObjectProphecy $watcher1;
private ObjectProphecy $watcher2;
protected function setUp(): void
{
parent::setUp();
$this->logger = $this->prophesize(LoggerInterface::class);
$this->watcher1 = $this->prophesize(Watcher::class);
$this->watcher1->describe()->willReturn('watcher1');
$this->watcher2 = $this->prophesize(Watcher::class);
$this->watcher2->describe()->willReturn('watcher2');
}
public function testNameIsUnknownWhenCalledBeforeInitialization(): void
{
$watcher = $this->createWatcher([
$this->watcher1->reveal(),
$this->watcher2->reveal(),
]);
self::assertEquals('unknown (pending invocation)', $watcher->describe());
}
public function testUsesFirstSupportedWatcher()
{
$this->watcher1->isSupported()->willReturn(new Success(false));
$callback = function (): void {
};
$paths = ['path1'];
$nullWatcher = new NullWatcher();
$watcher = $this->createWatcher([
$this->watcher1->reveal(),
$nullWatcher
]);
$process = yield $watcher->watch($paths, $callback);
self::assertSame($nullWatcher, $process);
self::assertEquals('null', $watcher->describe());
}
public function testReturnsNullWatcherAndLogsWarningIfNoSupportedWatchers()
{
$this->watcher1->isSupported()->willReturn(new Success(false));
$this->watcher2->isSupported()->willReturn(new Success(false));
$callback = function (): void {
};
$paths = ['path1'];
$process = yield $this->createWatcher([
$this->watcher1->reveal(),
$this->watcher2->reveal(),
])->watch($paths, $callback);
$this->logger->warning(Argument::containingString('No supported watchers'))->shouldHaveBeenCalled();
self::assertInstanceOf(NullWatcher::class, $process);
}
public function testIsAlwaysSupported(): Generator
{
$watcher = $this->createWatcher([]);
self::assertTrue(yield $watcher->isSupported());
}
private function createWatcher(array $watchers): Watcher
{
return new FallbackWatcher(
$watchers,
$this->logger->reveal()
);
}
}