SecureMethodInvocationsPass.php 1.4KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. <?php
  2. namespace JMS\SecurityExtraBundle\Tests\DependencyInjection\Compiler;
  3. use Symfony\Component\DependencyInjection\Definition;
  4. use JMS\SecurityExtraBundle\DependencyInjection\Compiler\SecureMethodInvocationsPass;
  5. use Symfony\Component\DependencyInjection\ContainerBuilder;
  6. class SecureMethodInvocationsTest extends \PHPUnit_Framework_TestCase
  7. {
  8. public function testProcessThrowsNoExceptionForUndefinedClassIfSecureAll()
  9. {
  10. $container = new ContainerBuilder();
  11. $container->setDefinition('security.access.method_interceptor', new Definition());
  12. $container->setParameter('security.secured_services', array());
  13. $container->setDefinition('nonexistent.class', new Definition('FooBar'));
  14. $this->process($container);
  15. }
  16. /**
  17. * @expectedException \RuntimeException
  18. */
  19. public function testProcessThrowsExceptionForUndefinedClassIfNotSecureAll()
  20. {
  21. $container = new ContainerBuilder();
  22. $container->setDefinition('security.access.method_interceptor', new Definition());
  23. $container->setParameter('security.secured_services', array('nonexistent.class'));
  24. $container->setDefinition('nonexistent.class', new Definition('FooBar'));
  25. $this->process($container);
  26. }
  27. protected function process(ContainerBuilder $container)
  28. {
  29. $pass = new SecureMethodInvocationsPass(sys_get_temp_dir());
  30. $pass->process($container);
  31. }
  32. }