Chris@5
|
1 <?php
|
Chris@5
|
2
|
Chris@5
|
3 namespace Consolidation\SiteProcess;
|
Chris@5
|
4
|
Chris@5
|
5 use Consolidation\SiteProcess\Util\Escape;
|
Chris@5
|
6 use PHPUnit\Framework\TestCase;
|
Chris@5
|
7 use Consolidation\SiteProcess\Util\ArgumentProcessor;
|
Chris@5
|
8 use Consolidation\SiteAlias\SiteAlias;
|
Chris@5
|
9 use Symfony\Component\Console\Output\BufferedOutput;
|
Chris@5
|
10 use Symfony\Component\Console\Style\SymfonyStyle;
|
Chris@5
|
11 use Symfony\Component\Console\Input\ArrayInput;
|
Chris@5
|
12
|
Chris@5
|
13 class RealtimeOutputHandlerTest extends TestCase
|
Chris@5
|
14 {
|
Chris@5
|
15 /**
|
Chris@5
|
16 * Data provider for testRealtimeOutputHandler.
|
Chris@5
|
17 */
|
Chris@5
|
18 public function realtimeOutputHandlerTestValues()
|
Chris@5
|
19 {
|
Chris@5
|
20 return [
|
Chris@5
|
21 [
|
Chris@5
|
22 'hello, world',
|
Chris@5
|
23 '',
|
Chris@5
|
24 ['echo', 'hello, world'],
|
Chris@5
|
25 'LINUX',
|
Chris@5
|
26 ],
|
Chris@5
|
27
|
Chris@5
|
28 [
|
Chris@5
|
29 '"hello, world"',
|
Chris@5
|
30 '',
|
Chris@5
|
31 ['echo', 'hello, world'],
|
Chris@5
|
32 'WIN'
|
Chris@5
|
33 ],
|
Chris@5
|
34
|
Chris@5
|
35 [
|
Chris@5
|
36 'README.md',
|
Chris@5
|
37 '',
|
Chris@5
|
38 ['ls', 'README.md'],
|
Chris@5
|
39 'LINUX',
|
Chris@5
|
40 ],
|
Chris@5
|
41
|
Chris@5
|
42 [
|
Chris@5
|
43 '',
|
Chris@5
|
44 'no/such/file: No such file or directory',
|
Chris@5
|
45 ['ls', 'no/such/file'],
|
Chris@5
|
46 'LINUX',
|
Chris@5
|
47 ],
|
Chris@5
|
48 ];
|
Chris@5
|
49 }
|
Chris@5
|
50
|
Chris@5
|
51 /**
|
Chris@5
|
52 * Test the RealtimeOutputHandler class.
|
Chris@5
|
53 *
|
Chris@5
|
54 * @dataProvider realtimeOutputHandlerTestValues
|
Chris@5
|
55 */
|
Chris@5
|
56 public function testRealtimeOutputHandler($expectedStdout, $expectedStderr, $args, $os)
|
Chris@5
|
57 {
|
Chris@5
|
58 if (Escape::isWindows() != Escape::isWindows($os)) {
|
Chris@5
|
59 $this->markTestSkipped("OS isn't supported");
|
Chris@5
|
60 }
|
Chris@5
|
61 $stdin = new ArrayInput([]);
|
Chris@5
|
62 $stdout = new BufferedOutput();
|
Chris@5
|
63 $stderr = new BufferedOutput();
|
Chris@5
|
64 $symfonyStyle = new SymfonyStyle($stdin, $stdout);
|
Chris@5
|
65
|
Chris@5
|
66 $process = new ProcessBase($args);
|
Chris@5
|
67 $process->setRealtimeOutput($symfonyStyle, $stderr);
|
Chris@5
|
68 $process->run($process->showRealtime());
|
Chris@5
|
69
|
Chris@5
|
70 $this->assertEquals($expectedStdout, trim($stdout->fetch()));
|
Chris@5
|
71 if (empty($expectedStderr)) {
|
Chris@5
|
72 $this->assertEquals('', trim($stderr->fetch()));
|
Chris@5
|
73 }
|
Chris@5
|
74 else {
|
Chris@5
|
75 $this->assertContains($expectedStderr, trim($stderr->fetch()));
|
Chris@5
|
76 }
|
Chris@5
|
77 }
|
Chris@5
|
78 }
|