|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Spatie\PhpUnitWatcher; |
|
4
|
|
|
|
|
5
|
|
|
use Clue\React\Stdio\Stdio; |
|
6
|
|
|
use React\EventLoop\Factory; |
|
7
|
|
|
use React\Stream\ThroughStream; |
|
8
|
|
|
use Symfony\Component\Finder\Finder; |
|
9
|
|
|
use Spatie\PhpUnitWatcher\Screens\Phpunit; |
|
10
|
|
|
use Yosymfony\ResourceWatcher\ResourceWatcher; |
|
11
|
|
|
use Yosymfony\ResourceWatcher\ResourceCacheMemory; |
|
12
|
|
|
|
|
13
|
|
|
class Watcher |
|
14
|
|
|
{ |
|
15
|
|
|
/** @var \Symfony\Component\Finder\Finder */ |
|
16
|
|
|
protected $finder; |
|
17
|
|
|
|
|
18
|
|
|
/** @var \React\EventLoop\LibEventLoop */ |
|
19
|
|
|
protected $loop; |
|
20
|
|
|
|
|
21
|
|
|
/** @var \Spatie\PhpUnitWatcher\Terminal */ |
|
22
|
|
|
protected $terminal; |
|
23
|
|
|
|
|
24
|
|
|
/** @var array */ |
|
25
|
|
|
protected $options; |
|
26
|
|
|
|
|
27
|
|
|
public function __construct(Finder $finder, array $options) |
|
28
|
|
|
{ |
|
29
|
|
|
$this->finder = $finder; |
|
30
|
|
|
|
|
31
|
|
|
$this->loop = Factory::create(); |
|
|
|
|
|
|
32
|
|
|
|
|
33
|
|
|
$this->terminal = new Terminal($this->buildStdio()); |
|
34
|
|
|
|
|
35
|
|
|
$this->options = $options; |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
public function startWatching() |
|
39
|
|
|
{ |
|
40
|
|
|
$this->terminal->displayScreen(new Phpunit($this->options), false); |
|
41
|
|
|
|
|
42
|
|
|
$watcher = new ResourceWatcher(new ResourceCacheMemory()); |
|
43
|
|
|
|
|
44
|
|
|
$watcher->setFinder($this->finder); |
|
45
|
|
|
|
|
46
|
|
|
$this->loop->addPeriodicTimer(1 / 4, function () use ($watcher) { |
|
47
|
|
|
if (! $this->terminal->isDisplayingScreen(Phpunit::class)) { |
|
48
|
|
|
return; |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
$watcher->findChanges(); |
|
52
|
|
|
|
|
53
|
|
|
if ($watcher->hasChanges()) { |
|
54
|
|
|
$this->terminal->refreshScreen(); |
|
55
|
|
|
} |
|
56
|
|
|
}); |
|
57
|
|
|
|
|
58
|
|
|
$this->loop->run(); |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
protected function buildStdio() |
|
62
|
|
|
{ |
|
63
|
|
|
$output = null; |
|
64
|
|
|
|
|
65
|
|
|
if (OS::isOnWindows()) { |
|
66
|
|
|
// Interaction on windows is currently not supported |
|
67
|
|
|
fclose(STDIN); |
|
68
|
|
|
|
|
69
|
|
|
// Simple fix for windows compatibility since we don't write a lot of data at once |
|
70
|
|
|
// https://github.com/clue/reactphp-stdio/issues/83#issuecomment-546678609 |
|
71
|
|
|
$output = new ThroughStream(static function ($data) { |
|
72
|
|
|
echo $data; |
|
73
|
|
|
}); |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
return new Stdio($this->loop, null, $output); |
|
77
|
|
|
} |
|
78
|
|
|
} |
|
79
|
|
|
|
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..