Skip to content

Commit 63e02b8

Browse files
committed
bug symfony#15223 [Finder] Command::addAtIndex() fails with Command instance argument (thunderer)
This PR was squashed before being merged into the 2.3 branch (closes symfony#15223). Discussion ---------- [Finder] Command::addAtIndex() fails with Command instance argument | Q | A | ------------- | --- | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | symfony#14384 | License | MIT | Doc PR | - Fixed reported bug symfony#14384 and added test case for it. This is a second PR as previous symfony#14385 went bad after I failed to rebase 2.3 branch properly. Commits ------- 2aff566 [Finder] Command::addAtIndex() fails with Command instance argument
2 parents e67249e + 2aff566 commit 63e02b8

File tree

2 files changed

+163
-1
lines changed

2 files changed

+163
-1
lines changed

src/Symfony/Component/Finder/Shell/Command.php

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

294294
return $this;
295295
}
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)