8000 [FrameworkBundle] Bundle commands are not available via find() by julienfalque · Pull Request #20442 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[FrameworkBundle] Bundle commands are not available via find() #20442

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 10, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Fix bundle commands are not available via find()
  • Loading branch information
julienfalque committed Nov 7, 2016
commit dd69b8875dc2477a12edc18f1baaf0113c8331b3
10 changes: 10 additions & 0 deletions src/Symfony/Bundle/FrameworkBundle/Console/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,16 @@ public function doRun(InputInterface $input, OutputInterface $output)
return parent::doRun($input, $output);
}

/**
* {@inheritdoc}
*/
public function find($name)
{
$this->registerCommands();

return parent::find($name);
}

/**
* {@inheritdoc}
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@ public function testBundleInterfaceImplementation()

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

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

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

public function testBundleCommandsAreRetrievable()
{
$bundle = $this->getMock('Symfony\Component\HttpKernel\Bundle\Bundle');
$bundle->expects($this->once())->method('registerCommands');
$bundle = $this->createBundleMock(array());

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

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

public function testBundleSingleCommandIsRetrievable()
{
$bundle = $this->getMock('Symfony\Component\HttpKernel\Bundle\Bundle');
$bundle->expects($this->once())->method('registerCommands');
$command = new Command('example');

$bundle = $this->createBundleMock(array($command));

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

$application = new Application($kernel);

$command = new Command('example');
$application->add($command);

$this->assertSame($command, $application->get('example'));
}

public function testBundleCommandCanBeFound()
{
$bundle = $this->getMock('Symfony\Component\HttpKernel\Bundle\Bundle');
$bundle->expects($this->once())->method('registerCommands');
$command = new Command('example');

$bundle = $this->createBundleMock(array($command));

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

$application = new Application($kernel);

$command = new Command('example');
$application->add($command);

$this->assertSame($command, $application->find('example'));
}

public function testBundleCommandCanBeFoundByAlias()
{
$bundle = $this->getMock('Symfony\Component\HttpKernel\Bundle\Bundle');
$bundle->expects($this->once())->method('registerCommands');
$command = new Command('example');
$command->setAliases(array('alias'));

$bundle = $this->createBundleMock(array($command));

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

$application = new Application($kernel);

$command = new Command('example');
$command->setAliases(array('alias'));
$application->add($command);

$this->assertSame($command, $application->find('alias'));
}


return $kernel;
}

private function createBundleMock(array $commands)
{
$bundle = $this->getMock('Symfony\Component\HttpKernel\Bundle\Bundle');
$bundle
->expects($this->once())
->method('registerCommands')
->will($this->returnCallback(function (Application $application) use ($commands) {
$application->addCommands($commands);
}))
;

return $bundle;
}
}
0