CheckDefinitionValidityPassTest.php 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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\Reference;
  14. use Symfony\Component\DependencyInjection\ContainerBuilder;
  15. class CheckDefinitionValidityPassTest extends \PHPUnit_Framework_TestCase
  16. {
  17. /**
  18. * @expectedException \RuntimeException
  19. */
  20. public function testProcessDetectsSyntheticNonPublicDefinitions()
  21. {
  22. $container = new ContainerBuilder();
  23. $container->register('a')->setSynthetic(true)->setPublic(false);
  24. $this->process($container);
  25. }
  26. /**
  27. * @expectedException \RuntimeException
  28. */
  29. public function testProcessDetectsSyntheticPrototypeDefinitions()
  30. {
  31. $container = new ContainerBuilder();
  32. $container->register('a')->setSynthetic(true)->setScope(ContainerInterface::SCOPE_PROTOTYPE);
  33. $this->process($container);
  34. }
  35. /**
  36. * @expectedException \RuntimeException
  37. */
  38. public function testProcessDetectsNonSyntheticNonAbstractDefinitionWithoutClass()
  39. {
  40. $container = new ContainerBuilder();
  41. $container->register('a')->setSynthetic(false)->setAbstract(false);
  42. $this->process($container);
  43. }
  44. public function testProcess()
  45. {
  46. $container = new ContainerBuilder();
  47. $container->register('a', 'class');
  48. $container->register('b', 'class')->setSynthetic(true)->setPublic(true);
  49. $container->register('c', 'class')->setAbstract(true);
  50. $container->register('d', 'class')->setSynthetic(true);
  51. $this->process($container);
  52. }
  53. protected function process(ContainerBuilder $container)
  54. {
  55. $pass = new CheckDefinitionValidityPass();
  56. $pass->process($container);
  57. }
  58. }