CheckDefinitionValidityPassTest.php 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. <?php
  2. /*
  3. * This file is part of the Symfony framework.
  4. *
  5. * (c) Fabien Potencier <fabien@symfony.com>
  6. *
  7. * This source file is subject to the MIT license that is bundled
  8. * with this source code in the file LICENSE.
  9. */
  10. namespace Symfony\Tests\Component\DependencyInjection\Compiler;
  11. use Symfony\Component\DependencyInjection\Compiler\CheckDefinitionValidityPass;
  12. use Symfony\Component\DependencyInjection\ContainerInterface;
  13. use Symfony\Component\DependencyInjection\ContainerBuilder;
  14. class CheckDefinitionValidityPassTest extends \PHPUnit_Framework_TestCase
  15. {
  16. /**
  17. * @expectedException \RuntimeException
  18. */
  19. public function testProcessDetectsSyntheticNonPublicDefinitions()
  20. {
  21. $container = new ContainerBuilder();
  22. $container->register('a')->setSynthetic(true)->setPublic(false);
  23. $this->process($container);
  24. }
  25. /**
  26. * @expectedException \RuntimeException
  27. */
  28. public function testProcessDetectsSyntheticPrototypeDefinitions()
  29. {
  30. $container = new ContainerBuilder();
  31. $container->register('a')->setSynthetic(true)->setScope(ContainerInterface::SCOPE_PROTOTYPE);
  32. $this->process($container);
  33. }
  34. /**
  35. * @expectedException \RuntimeException
  36. */
  37. public function testProcessDetectsNonSyntheticNonAbstractDefinitionWithoutClass()
  38. {
  39. $container = new ContainerBuilder();
  40. $container->register('a')->setSynthetic(false)->setAbstract(false);
  41. $this->process($container);
  42. }
  43. public function testProcess()
  44. {
  45. $container = new ContainerBuilder();
  46. $container->register('a', 'class');
  47. $container->register('b', 'class')->setSynthetic(true)->setPublic(true);
  48. $container->register('c', 'class')->setAbstract(true);
  49. $container->register('d', 'class')->setSynthetic(true);
  50. $this->process($container);
  51. }
  52. protected function process(ContainerBuilder $container)
  53. {
  54. $pass = new CheckDefinitionValidityPass();
  55. $pass->process($container);
  56. }
  57. }