AddExpressionLanguageProvidersPassTest.php 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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\Bundle\FrameworkBundle\Tests\DependencyInjection\Compiler;
  11. use PHPUnit\Framework\TestCase;
  12. use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\AddExpressionLanguageProvidersPass;
  13. use Symfony\Component\DependencyInjection\ContainerBuilder;
  14. use Symfony\Component\DependencyInjection\Definition;
  15. use Symfony\Component\DependencyInjection\Reference;
  16. class AddExpressionLanguageProvidersPassTest extends TestCase
  17. {
  18. public function testProcessForRouter()
  19. {
  20. $container = new ContainerBuilder();
  21. $container->addCompilerPass(new AddExpressionLanguageProvidersPass());
  22. $definition = new Definition('Symfony\Bundle\FrameworkBundle\Tests\DependencyInjection\Compiler\TestProvider');
  23. $definition->addTag('routing.expression_language_provider');
  24. $container->setDefinition('some_routing_provider', $definition);
  25. $container->register('router', '\stdClass');
  26. $container->compile();
  27. $router = $container->getDefinition('router');
  28. $calls = $router->getMethodCalls();
  29. $this->assertCount(1, $calls);
  30. $this->assertEquals('addExpressionLanguageProvider', $calls[0][0]);
  31. $this->assertEquals(new Reference('some_routing_provider'), $calls[0][1][0]);
  32. }
  33. public function testProcessForRouterAlias()
  34. {
  35. $container = new ContainerBuilder();
  36. $container->addCompilerPass(new AddExpressionLanguageProvidersPass());
  37. $definition = new Definition('Symfony\Bundle\FrameworkBundle\Tests\DependencyInjection\Compiler\TestProvider');
  38. $definition->addTag('routing.expression_language_provider');
  39. $container->setDefinition('some_routing_provider', $definition);
  40. $container->register('my_router', '\stdClass');
  41. $container->setAlias('router', 'my_router');
  42. $container->compile();
  43. $router = $container->getDefinition('my_router');
  44. $calls = $router->getMethodCalls();
  45. $this->assertCount(1, $calls);
  46. $this->assertEquals('addExpressionLanguageProvider', $calls[0][0]);
  47. $this->assertEquals(new Reference('some_routing_provider'), $calls[0][1][0]);
  48. }
  49. public function testProcessForSecurity()
  50. {
  51. $container = new ContainerBuilder();
  52. $container->addCompilerPass(new AddExpressionLanguageProvidersPass());
  53. $definition = new Definition('Symfony\Bundle\FrameworkBundle\Tests\DependencyInjection\Compiler\TestProvider');
  54. $definition->addTag('security.expression_language_provider');
  55. $container->setDefinition('some_security_provider', $definition);
  56. $container->register('security.access.expression_voter', '\stdClass');
  57. $container->compile();
  58. $router = $container->getDefinition('security.access.expression_voter');
  59. $calls = $router->getMethodCalls();
  60. $this->assertCount(1, $calls);
  61. $this->assertEquals('addExpressionLanguageProvider', $calls[0][0]);
  62. $this->assertEquals(new Reference('some_security_provider'), $calls[0][1][0]);
  63. }
  64. public function testProcessForSecurityAlias()
  65. {
  66. $container = new ContainerBuilder();
  67. $container->addCompilerPass(new AddExpressionLanguageProvidersPass());
  68. $definition = new Definition('Symfony\Bundle\FrameworkBundle\Tests\DependencyInjection\Compiler\TestProvider');
  69. $definition->addTag('security.expression_language_provider');
  70. $container->setDefinition('some_security_provider', $definition);
  71. $container->register('my_security.access.expression_voter', '\stdClass');
  72. $container->setAlias('security.access.expression_voter', 'my_security.access.expression_voter');
  73. $container->compile();
  74. $router = $container->getDefinition('my_security.access.expression_voter');
  75. $calls = $router->getMethodCalls();
  76. $this->assertCount(1, $calls);
  77. $this->assertEquals('addExpressionLanguageProvider', $calls[0][0]);
  78. $this->assertEquals(new Reference('some_security_provider'), $calls[0][1][0]);
  79. }
  80. }
  81. class TestProvider
  82. {
  83. }