CheckDefinitionValidityPassTest.php 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. <?php
  2. namespace Symfony\Tests\Component\DependencyInjection\Compiler;
  3. use Symfony\Component\DependencyInjection\Compiler\CheckDefinitionValidityPass;
  4. use Symfony\Component\DependencyInjection\ContainerInterface;
  5. use Symfony\Component\DependencyInjection\Reference;
  6. use Symfony\Component\DependencyInjection\ContainerBuilder;
  7. class CheckDefinitionValidityPassTest extends \PHPUnit_Framework_TestCase
  8. {
  9. /**
  10. * @expectedException \RuntimeException
  11. */
  12. public function testProcessDetectsSyntheticNonPublicDefinitions()
  13. {
  14. $container = new ContainerBuilder();
  15. $container->register('a')->setSynthetic(true)->setPublic(false);
  16. $this->process($container);
  17. }
  18. /**
  19. * @expectedException \RuntimeException
  20. */
  21. public function testProcessDetectsSyntheticPrototypeDefinitions()
  22. {
  23. $container = new ContainerBuilder();
  24. $container->register('a')->setSynthetic(true)->setScope(ContainerInterface::SCOPE_PROTOTYPE);
  25. $this->process($container);
  26. }
  27. /**
  28. * @expectedException \RuntimeException
  29. */
  30. public function testProcessDetectsNonSyntheticNonAbstractDefinitionWithoutClass()
  31. {
  32. $container = new ContainerBuilder();
  33. $container->register('a')->setSynthetic(false)->setAbstract(false);
  34. $this->process($container);
  35. }
  36. public function testProcess()
  37. {
  38. $container = new ContainerBuilder();
  39. $container->register('a', 'class');
  40. $container->register('b', 'class')->setSynthetic(true)->setPublic(true);
  41. $container->register('c', 'class')->setAbstract(true);
  42. $container->register('d', 'class')->setSynthetic(true);
  43. $this->process($container);
  44. }
  45. protected function process(ContainerBuilder $container)
  46. {
  47. $pass = new CheckDefinitionValidityPass();
  48. $pass->process($container);
  49. }
  50. }