Skip to content

Commit 57cd859

Browse files
committed
Merge branch '3.1' into 3.2
* 3.1: Skip test when iconv extension is missing Fix bundle commands are not available via find()
2 parents 2309ec5 + cb603ae commit 57cd859

File tree

2 files changed

+36
-20
lines changed

2 files changed

+36
-20
lines changed

Console/Application.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,16 @@ public function doRun(InputInterface $input, OutputInterface $output)
8080
return parent::doRun($input, $output);
8181
}
8282

83+
/**
84+
* {@inheritdoc}
85+
*/
86+
public function find($name)
87+
{
88+
$this->registerCommands();
89+
90+
return parent::find($name);
91+
}
92+
8393
/**
8494
* {@inheritdoc}
8595
*/

Tests/Console/ApplicationTest.php

Lines changed: 26 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,7 @@ public function testBundleInterfaceImplementation()
3232

3333
public function testBundleCommandsAreRegistered()
3434
{
35-
$bundle = $this->getMock('Symfony\Component\HttpKernel\Bundle\Bundle');
36-
$bundle->expects($this->once())->method('registerCommands');
35+
$bundle = $this->createBundleMock(array());
3736

3837
$kernel = $this->getKernel(array($bundle), true);
3938

@@ -46,8 +45,7 @@ public function testBundleCommandsAreRegistered()
4645

4746
public function testBundleCommandsAreRetrievable()
4847
{
49-
$bundle = $this->getMock('Symfony\Component\HttpKernel\Bundle\Bundle');
50-
$bundle->expects($this->once())->method('registerCommands');
48+
$bundle = $this->createBundleMock(array());
5149

5250
$kernel = $this->getKernel(array($bundle));
5351

@@ -60,47 +58,41 @@ public function testBundleCommandsAreRetrievable()
6058

6159
public function testBundleSingleCommandIsRetrievable()
6260
{
63-
$bundle = $this->getMock('Symfony\Component\HttpKernel\Bundle\Bundle');
64-
$bundle->expects($this->once())->method('registerCommands');
61+
$command = new Command('example');
62+
63+
$bundle = $this->createBundleMock(array($command));
6564

6665
$kernel = $this->getKernel(array($bundle));
6766

6867
$application = new Application($kernel);
6968

70-
$command = new Command('example');
71-
$application->add($command);
72-
7369
$this->assertSame($command, $application->get('example'));
7470
}
7571

7672
public function testBundleCommandCanBeFound()
7773
{
78-
$bundle = $this->getMock('Symfony\Component\HttpKernel\Bundle\Bundle');
79-
$bundle->expects($this->once())->method('registerCommands');
74+
$command = new Command('example');
75+
76+
$bundle = $this->createBundleMock(array($command));
8077

8178
$kernel = $this->getKernel(array($bundle));
8279

8380
$application = new Application($kernel);
8481

85-
$command = new Command('example');
86-
$application->add($command);
87-
8882
$this->assertSame($command, $application->find('example'));
8983
}
9084

9185
public function testBundleCommandCanBeFoundByAlias()
9286
{
93-
$bundle = $this->getMock('Symfony\Component\HttpKernel\Bundle\Bundle');
94-
$bundle->expects($this->once())->method('registerCommands');
87+
$command = new Command('example');
88+
$command->setAliases(array('alias'));
89+
90+
$bundle = $this->createBundleMock(array($command));
9591

9692
$kernel = $this->getKernel(array($bundle));
9793

9894
$application = new Application($kernel);
9995

100-
$command = new Command('example');
101-
$command->setAliases(array('alias'));
102-
$application->add($command);
103-
10496
$this->assertSame($command, $application->find('alias'));
10597
}
10698

@@ -167,4 +159,18 @@ private function getKernel(array $bundles, $useDispatcher = false)
167159

168160
return $kernel;
169161
}
162+
163+
private function createBundleMock(array $commands)
164+
{
165+
$bundle = $this->getMock('Symfony\Component\HttpKernel\Bundle\Bundle');
166+
$bundle
167+
->expects($this->once())
168+
->method('registerCommands')
169+
->will($this->returnCallback(function (Application $application) use ($commands) {
170+
$application->addCommands($commands);
171+
}))
172+
;
173+
174+
return $bundle;
175+
}
170176
}

0 commit comments

Comments
 (0)