TYPO3  7.6
finder/Tests/Shell/CommandTest.php
Go to the documentation of this file.
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 
13 
15 
16 class CommandTest extends \PHPUnit_Framework_TestCase
17 {
18  public function testCreate()
19  {
20  $this->assertInstanceOf('Symfony\Component\Finder\Shell\Command', Command::create());
21  }
22 
23  public function testAdd()
24  {
25  $cmd = Command::create()->add('--force');
26  $this->assertSame('--force', $cmd->join());
27  }
28 
29  public function testAddAsFirst()
30  {
31  $cmd = Command::create()->add('--force');
32 
33  $cmd->addAtIndex(Command::create()->add('-F'), 0);
34  $this->assertSame('-F --force', $cmd->join());
35  }
36 
37  public function testAddAsLast()
38  {
39  $cmd = Command::create()->add('--force');
40 
41  $cmd->addAtIndex(Command::create()->add('-F'), 1);
42  $this->assertSame('--force -F', $cmd->join());
43  }
44 
45  public function testAddInBetween()
46  {
47  $cmd = Command::create()->add('--force');
48  $cmd->addAtIndex(Command::create()->add('-F'), 0);
49 
50  $cmd->addAtIndex(Command::create()->add('-X'), 1);
51  $this->assertSame('-F -X --force', $cmd->join());
52  }
53 
54  public function testCount()
55  {
56  $cmd = Command::create();
57  $this->assertSame(0, $cmd->length());
58 
59  $cmd->add('--force');
60  $this->assertSame(1, $cmd->length());
61 
62  $cmd->add('--run');
63  $this->assertSame(2, $cmd->length());
64  }
65 
66  public function testTop()
67  {
68  $cmd = Command::create()->add('--force');
69 
70  $cmd->top('--run');
71  $this->assertSame('--run --force', $cmd->join());
72  }
73 
74  public function testTopLabeled()
75  {
76  $cmd = Command::create()->add('--force');
77 
78  $cmd->top('--run');
79  $cmd->ins('--something');
80  $cmd->top('--something');
81  $this->assertSame('--something --run --force ', $cmd->join());
82  }
83 
84  public function testArg()
85  {
86  $cmd = Command::create()->add('--force');
87 
88  $cmd->arg('--run');
89  $this->assertSame('--force '.escapeshellarg('--run'), $cmd->join());
90  }
91 
92  public function testCmd()
93  {
94  $cmd = Command::create()->add('--force');
95 
96  $cmd->cmd('run');
97  $this->assertSame('--force run', $cmd->join());
98  }
99 
101  {
102  $cmd = Command::create()->add('--force');
103 
104  $cmd->ins('label');
105  $this->setExpectedException('RuntimeException');
106  $cmd->ins('label');
107  }
108 
109  public function testEnd()
110  {
111  $parent = Command::create();
112  $cmd = Command::create($parent);
113 
114  $this->assertSame($parent, $cmd->end());
115  }
116 
117  public function testEndNoParentException()
118  {
119  $cmd = Command::create();
120 
121  $this->setExpectedException('RuntimeException');
122  $cmd->end();
123  }
124 
126  {
127  $cmd = Command::create();
128 
129  $this->setExpectedException('RuntimeException');
130  $cmd->get('invalid');
131  }
132 
133  public function testErrorHandler()
134  {
135  $cmd = Command::create();
136  $handler = function () { return 'error-handler'; };
137  $cmd->setErrorHandler($handler);
138 
139  $this->assertSame($handler, $cmd->getErrorHandler());
140  }
141 
142  public function testExecute()
143  {
144  $cmd = Command::create();
145  $cmd->add('php');
146  $cmd->add('--version');
147  $result = $cmd->execute();
148 
149  $this->assertTrue(is_array($result));
150  $this->assertNotEmpty($result);
151  $this->assertRegexp('/PHP|HipHop/', $result[0]);
152  }
153 
154  public function testCastToString()
155  {
156  $cmd = Command::create();
157  $cmd->add('--force');
158  $cmd->add('--run');
159 
160  $this->assertSame('--force --run', (string) $cmd);
161  }
162 }