minor #20273 [FrameworkBundle][HttpKernel] move test to the HttpKernel component (xabbuh)

This PR was merged into the 2.7 branch.

Discussion
----------

[FrameworkBundle][HttpKernel] move test to the HttpKernel component

| Q             | A
| ------------- | ---
| Branch?       | 2.7
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | https://github.com/symfony/symfony/pull/19443#discussion_r83414612
| License       | MIT
| Doc PR        |

The moved test case does not test the `AddConsoleCommandPass` class, but ensures certain behavior in the `registerCommands()` method of the `Bundle` class from the HttpKernel component.

Commits
-------

c9ca322 move test to the HttpKernel component
This commit is contained in:
Fabien Potencier 2016-10-22 07:38:20 -07:00
commit 0c551b5236
2 changed files with 15 additions and 20 deletions

View File

@ -88,26 +88,6 @@ class AddConsoleCommandPassTest extends \PHPUnit_Framework_TestCase
$container->compile();
}
public function testHttpKernelRegisterCommandsIngoreCommandAsAService()
{
$container = new ContainerBuilder();
$container->addCompilerPass(new AddConsoleCommandPass());
$definition = new Definition('Symfony\Bundle\FrameworkBundle\Tests\DependencyInjection\Compiler\MyCommand');
$definition->addTag('console.command');
$container->setDefinition('my-command', $definition);
$container->compile();
$application = $this->getMock('Symfony\Component\Console\Application');
// Never called, because it's the
// Symfony\Bundle\FrameworkBundle\Console\Application that register
// commands as a service
$application->expects($this->never())->method('add');
$bundle = new ExtensionPresentBundle();
$bundle->setContainer($container);
$bundle->registerCommands($application);
}
}
class MyCommand extends Command

View File

@ -11,6 +11,7 @@
namespace Symfony\Component\HttpKernel\Tests\Bundle;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\HttpKernel\Tests\Fixtures\ExtensionNotValidBundle\ExtensionNotValidBundle;
use Symfony\Component\HttpKernel\Tests\Fixtures\ExtensionPresentBundle\ExtensionPresentBundle;
use Symfony\Component\HttpKernel\Tests\Fixtures\ExtensionAbsentBundle\ExtensionAbsentBundle;
@ -41,4 +42,18 @@ class BundleTest extends \PHPUnit_Framework_TestCase
$bundle = new ExtensionNotValidBundle();
$bundle->getContainerExtension();
}
public function testHttpKernelRegisterCommandsIgnoresCommandsThatAreRegisteredAsServices()
{
$container = new ContainerBuilder();
$container->register('console.command.Symfony_Component_HttpKernel_Tests_Fixtures_ExtensionPresentBundle_Command_FooCommand', 'Symfony\Component\HttpKernel\Tests\Fixtures\ExtensionPresentBundle\Command\FooCommand');
$application = $this->getMock('Symfony\Component\Console\Application');
// add() is never called when the found command classes are already registered as services
$application->expects($this->never())->method('add');
$bundle = new ExtensionPresentBundle();
$bundle->setContainer($container);
$bundle->registerCommands($application);
}
}