BundleTest.php 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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. /**
  26. * @expectedException \LogicException
  27. * @expectedExceptionMessage must implement Symfony\Component\DependencyInjection\Extension\ExtensionInterface
  28. */
  29. public function testGetContainerExtensionWithInvalidClass()
  30. {
  31. $bundle = new ExtensionNotValidBundle();
  32. $bundle->getContainerExtension();
  33. }
  34. public function testBundleNameIsGuessedFromClass()
  35. {
  36. $bundle = new GuessedNameBundle();
  37. $this->assertSame('Symfony\Component\HttpKernel\Tests\Bundle', $bundle->getNamespace());
  38. $this->assertSame('GuessedNameBundle', $bundle->getName());
  39. }
  40. public function testBundleNameCanBeExplicitlyProvided()
  41. {
  42. $bundle = new NamedBundle();
  43. $this->assertSame('ExplicitlyNamedBundle', $bundle->getName());
  44. $this->assertSame('Symfony\Component\HttpKernel\Tests\Bundle', $bundle->getNamespace());
  45. $this->assertSame('ExplicitlyNamedBundle', $bundle->getName());
  46. }
  47. }
  48. class NamedBundle extends Bundle
  49. {
  50. public function __construct()
  51. {
  52. $this->name = 'ExplicitlyNamedBundle';
  53. }
  54. }
  55. class GuessedNameBundle extends Bundle
  56. {
  57. }