BundleTest.php 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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\HttpKernel\Bundle\Bundle;
  13. use Symfony\Component\HttpKernel\Tests\Fixtures\ExtensionNotValidBundle\ExtensionNotValidBundle;
  14. use Symfony\Component\HttpKernel\Tests\Fixtures\ExtensionPresentBundle\ExtensionPresentBundle;
  15. class BundleTest extends TestCase
  16. {
  17. public function testGetContainerExtension()
  18. {
  19. $bundle = new ExtensionPresentBundle();
  20. $this->assertInstanceOf(
  21. 'Symfony\Component\HttpKernel\Tests\Fixtures\ExtensionPresentBundle\DependencyInjection\ExtensionPresentExtension',
  22. $bundle->getContainerExtension()
  23. );
  24. }
  25. public function testGetContainerExtensionWithInvalidClass()
  26. {
  27. $this->expectException(\LogicException::class);
  28. $this->expectExceptionMessage('must implement Symfony\Component\DependencyInjection\Extension\ExtensionInterface');
  29. $bundle = new ExtensionNotValidBundle();
  30. $bundle->getContainerExtension();
  31. }
  32. public function testBundleNameIsGuessedFromClass()
  33. {
  34. $bundle = new GuessedNameBundle();
  35. $this->assertSame('Symfony\Component\HttpKernel\Tests\Bundle', $bundle->getNamespace());
  36. $this->assertSame('GuessedNameBundle', $bundle->getName());
  37. }
  38. public function testBundleNameCanBeExplicitlyProvided()
  39. {
  40. $bundle = new NamedBundle();
  41. $this->assertSame('ExplicitlyNamedBundle', $bundle->getName());
  42. $this->assertSame('Symfony\Component\HttpKernel\Tests\Bundle', $bundle->getNamespace());
  43. $this->assertSame('ExplicitlyNamedBundle', $bundle->getName());
  44. }
  45. }
  46. class NamedBundle extends Bundle
  47. {
  48. public function __construct()
  49. {
  50. $this->name = 'ExplicitlyNamedBundle';
  51. }
  52. }
  53. class GuessedNameBundle extends Bundle
  54. {
  55. }