Skip to content

Commit 8712d5e

Browse files
committed
Merge branch '2.7' into 2.8
* 2.7: Added 'default' color [HttpFoundation] Reload the session after regenerating its id [HttpFoundation] Add a test case to confirm a bug in session migration [Serializer] Fix ClassMetadata::sleep() [2.6] Static Code Analysis for Components and Bundles [Finder] Command::addAtIndex() fails with Command instance argument [DependencyInjection] Freeze also FrozenParameterBag::remove [Twig][Bridge] replaced `extends` with `use` in bootstrap_3_horizontal_layout.html.twig fix CS fixed CS Add a way to reset the singleton [Security] allow to use `method` in XML configs [Serializer] Fix Groups tests. Remove duplicate example Remove var not used due to returning early (introduced in 8982c32) [Serializer] Fix Groups PHPDoc Enhance hhvm test skip message fix for legacy asset() with EmptyVersionStrategy [Form] Added upgrade notes for #15061
2 parents 9ecb7ee + ae0f363 commit 8712d5e

File tree

2 files changed

+163
-1
lines changed

2 files changed

+163
-1
lines changed

Shell/Command.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@ function ($bit) { return null !== $bit; }
287287
*/
288288
public function addAtIndex($bit, $index)
289289
{
290-
array_splice($this->bits, $index, 0, $bit);
290+
array_splice($this->bits, $index, 0, $bit instanceof self ? array($bit) : $bit);
291291

292292
return $this;
293293
}

Tests/Shell/CommandTest.php

Lines changed: 162 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,162 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <[email protected]>
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 Symfony\Component\Finder\Shell\Command;
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 \'--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+
100+
public function testInsDuplicateLabelException()
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+
125+
public function testGetMissingLabelException()
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+
}

0 commit comments

Comments
 (0)