BundleTest.php 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. <?php
  2. /*
  3. * This file is part of the Symfony package.
  4. *
  5. * (c) Fabien Potencier <fabien@symfony.com>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Symfony\Component\HttpKernel\Tests\Bundle;
  11. use PHPUnit\Framework\TestCase;
  12. use Symfony\Component\DependencyInjection\ContainerBuilder;
  13. use Symfony\Component\HttpKernel\Tests\Fixtures\ExtensionAbsentBundle\ExtensionAbsentBundle;
  14. use Symfony\Component\HttpKernel\Tests\Fixtures\ExtensionNotValidBundle\ExtensionNotValidBundle;
  15. use Symfony\Component\HttpKernel\Tests\Fixtures\ExtensionPresentBundle\Command\FooCommand;
  16. use Symfony\Component\HttpKernel\Tests\Fixtures\ExtensionPresentBundle\ExtensionPresentBundle;
  17. class BundleTest extends TestCase
  18. {
  19. public function testGetContainerExtension()
  20. {
  21. $bundle = new ExtensionPresentBundle();
  22. $this->assertInstanceOf(
  23. 'Symfony\Component\HttpKernel\Tests\Fixtures\ExtensionPresentBundle\DependencyInjection\ExtensionPresentExtension',
  24. $bundle->getContainerExtension()
  25. );
  26. }
  27. public function testRegisterCommands()
  28. {
  29. $cmd = new FooCommand();
  30. $app = $this->getMockBuilder('Symfony\Component\Console\Application')->getMock();
  31. $app->expects($this->once())->method('add')->with($this->equalTo($cmd));
  32. $bundle = new ExtensionPresentBundle();
  33. $bundle->registerCommands($app);
  34. $bundle2 = new ExtensionAbsentBundle();
  35. $this->assertNull($bundle2->registerCommands($app));
  36. }
  37. /**
  38. * @expectedException \LogicException
  39. * @expectedExceptionMessage must implement Symfony\Component\DependencyInjection\Extension\ExtensionInterface
  40. */
  41. public function testGetContainerExtensionWithInvalidClass()
  42. {
  43. $bundle = new ExtensionNotValidBundle();
  44. $bundle->getContainerExtension();
  45. }
  46. public function testHttpKernelRegisterCommandsIgnoresCommandsThatAreRegisteredAsServices()
  47. {
  48. $container = new ContainerBuilder();
  49. $container->register('console.command.symfony_component_httpkernel_tests_fixtures_extensionpresentbundle_command_foocommand', 'Symfony\Component\HttpKernel\Tests\Fixtures\ExtensionPresentBundle\Command\FooCommand');
  50. $application = $this->getMockBuilder('Symfony\Component\Console\Application')->getMock();
  51. // add() is never called when the found command classes are already registered as services
  52. $application->expects($this->never())->method('add');
  53. $bundle = new ExtensionPresentBundle();
  54. $bundle->setContainer($container);
  55. $bundle->registerCommands($application);
  56. }
  57. }