AddAfterInvocationProvidersPassTest.php 2.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. <?php
  2. namespace JMS\SecurityExtraBundle\Tests\DependencyInjection\Compiler;
  3. use Symfony\Component\DependencyInjection\Definition;
  4. use JMS\SecurityExtraBundle\DependencyInjection\Compiler\AddAfterInvocationProvidersPass;
  5. use Symfony\Component\DependencyInjection\ContainerBuilder;
  6. class AddAfterInvocationProvidersPassTest extends \PHPUnit_Framework_TestCase
  7. {
  8. public function testProcessStopsWhenNoAfterInvocationManager()
  9. {
  10. $container = $this->getContainer();
  11. $container
  12. ->expects($this->once())
  13. ->method('hasDefinition')
  14. ->with($this->equalTo('security.access.after_invocation_manager'))
  15. ->will($this->returnValue(false))
  16. ;
  17. $container
  18. ->expects($this->never())
  19. ->method('findTaggedServiceIds')
  20. ;
  21. $this->process($container);
  22. }
  23. public function testProcessRemovesAclProviderIfAclIsNotActive()
  24. {
  25. $container = new ContainerBuilder();
  26. $container->setDefinition('security.access.after_invocation_manager', $manager = new Definition());
  27. $container
  28. ->register('security.access.after_invocation.acl_provider')
  29. ->addTag('security.after_invocation.provider')
  30. ;
  31. $this->assertEquals(array(), $manager->getArguments());
  32. $this->process($container);
  33. $this->assertEquals(array(array()), $manager->getArguments());
  34. }
  35. public function testProcess()
  36. {
  37. $container = new ContainerBuilder();
  38. $container->setDefinition('security.access.after_invocation_manager', $manager = new Definition());
  39. $provider1 = new Definition();
  40. $provider1->addTag('security.after_invocation.provider');
  41. $container->setDefinition('provider1', $provider1);
  42. $provider2 = new Definition();
  43. $provider2->addTag('security.after_invocation.provider');
  44. $container->setDefinition('provider2', $provider2);
  45. $this->process($container);
  46. $arguments = $manager->getArguments();
  47. $this->assertEquals(2, count($providers = $arguments[0]));
  48. $this->assertEquals('provider1', (string) $providers[0]);
  49. $this->assertEquals('provider2', (string) $providers[1]);
  50. }
  51. protected function process(ContainerBuilder $container)
  52. {
  53. $pass = new AddAfterInvocationProvidersPass();
  54. $pass->process($container);
  55. }
  56. protected function getContainer()
  57. {
  58. return $this->getMock('Symfony\Component\DependencyInjection\ContainerBuilder');
  59. }
  60. }