Yaffs site version 1.1
[yaffs-website] / vendor / symfony / finder / Tests / Shell / CommandTest.php
1 <?php
2
3 /*
4  * This file is part of the Symfony package.
5  *
6  * (c) Fabien Potencier <fabien@symfony.com>
7  *
8  * For the full copyright and license information, please view the LICENSE
9  * file that was distributed with this source code.
10  */
11
12 namespace Symfony\Component\Finder\Tests\Shell;
13
14 use PHPUnit\Framework\TestCase;
15 use Symfony\Component\Finder\Shell\Command;
16
17 /**
18  * @group legacy
19  */
20 class CommandTest extends TestCase
21 {
22     public function testCreate()
23     {
24         $this->assertInstanceOf('Symfony\Component\Finder\Shell\Command', Command::create());
25     }
26
27     public function testAdd()
28     {
29         $cmd = Command::create()->add('--force');
30         $this->assertSame('--force', $cmd->join());
31     }
32
33     public function testAddAsFirst()
34     {
35         $cmd = Command::create()->add('--force');
36
37         $cmd->addAtIndex(Command::create()->add('-F'), 0);
38         $this->assertSame('-F --force', $cmd->join());
39     }
40
41     public function testAddAsLast()
42     {
43         $cmd = Command::create()->add('--force');
44
45         $cmd->addAtIndex(Command::create()->add('-F'), 1);
46         $this->assertSame('--force -F', $cmd->join());
47     }
48
49     public function testAddInBetween()
50     {
51         $cmd = Command::create()->add('--force');
52         $cmd->addAtIndex(Command::create()->add('-F'), 0);
53
54         $cmd->addAtIndex(Command::create()->add('-X'), 1);
55         $this->assertSame('-F -X --force', $cmd->join());
56     }
57
58     public function testCount()
59     {
60         $cmd = Command::create();
61         $this->assertSame(0, $cmd->length());
62
63         $cmd->add('--force');
64         $this->assertSame(1, $cmd->length());
65
66         $cmd->add('--run');
67         $this->assertSame(2, $cmd->length());
68     }
69
70     public function testTop()
71     {
72         $cmd = Command::create()->add('--force');
73
74         $cmd->top('--run');
75         $this->assertSame('--run --force', $cmd->join());
76     }
77
78     public function testTopLabeled()
79     {
80         $cmd = Command::create()->add('--force');
81
82         $cmd->top('--run');
83         $cmd->ins('--something');
84         $cmd->top('--something');
85         $this->assertSame('--something --run --force ', $cmd->join());
86     }
87
88     public function testArg()
89     {
90         $cmd = Command::create()->add('--force');
91
92         $cmd->arg('--run');
93         $this->assertSame('--force '.escapeshellarg('--run'), $cmd->join());
94     }
95
96     public function testCmd()
97     {
98         $cmd = Command::create()->add('--force');
99
100         $cmd->cmd('run');
101         $this->assertSame('--force run', $cmd->join());
102     }
103
104     public function testInsDuplicateLabelException()
105     {
106         $cmd = Command::create()->add('--force');
107
108         $cmd->ins('label');
109         $this->{method_exists($this, $_ = 'expectException') ? $_ : 'setExpectedException'}('RuntimeException');
110         $cmd->ins('label');
111     }
112
113     public function testEnd()
114     {
115         $parent = Command::create();
116         $cmd = Command::create($parent);
117
118         $this->assertSame($parent, $cmd->end());
119     }
120
121     public function testEndNoParentException()
122     {
123         $cmd = Command::create();
124
125         $this->{method_exists($this, $_ = 'expectException') ? $_ : 'setExpectedException'}('RuntimeException');
126         $cmd->end();
127     }
128
129     public function testGetMissingLabelException()
130     {
131         $cmd = Command::create();
132
133         $this->{method_exists($this, $_ = 'expectException') ? $_ : 'setExpectedException'}('RuntimeException');
134         $cmd->get('invalid');
135     }
136
137     public function testErrorHandler()
138     {
139         $cmd = Command::create();
140         $handler = function () { return 'error-handler'; };
141         $cmd->setErrorHandler($handler);
142
143         $this->assertSame($handler, $cmd->getErrorHandler());
144     }
145
146     public function testExecute()
147     {
148         $cmd = Command::create();
149         $cmd->add('php');
150         $cmd->add('--version');
151         $result = $cmd->execute();
152
153         $this->assertInternalType('array', $result);
154         $this->assertNotEmpty($result);
155         $this->assertRegExp('/PHP|HipHop/', $result[0]);
156     }
157
158     public function testCastToString()
159     {
160         $cmd = Command::create();
161         $cmd->add('--force');
162         $cmd->add('--run');
163
164         $this->assertSame('--force --run', (string) $cmd);
165     }
166 }