public function convertMethodAnnotations(\ReflectionMethod $method, array $annotations)
 {
     $parameters = array();
     foreach ($method->getParameters() as $index => $parameter) {
         $parameters[$parameter->getName()] = $index;
     }
     $methodMetadata = new MethodMetadata($method);
     foreach ($annotations as $annotation) {
         if ($annotation instanceof Secure) {
             $methodMetadata->setRoles($annotation->getRoles());
         } else {
             if ($annotation instanceof SecureParam) {
                 if (!isset($parameters[$annotation->getName()])) {
                     throw new \InvalidArgumentException(sprintf('The parameter "%s" does not exist for method "%s".', $annotation->getName(), $method->getName()));
                 }
                 $methodMetadata->addParamPermissions($parameters[$annotation->getName()], $annotation->getPermissions());
             } else {
                 if ($annotation instanceof SecureReturn) {
                     $methodMetadata->addReturnPermissions($annotation->getPermissions());
                 } else {
                     if ($annotation instanceof SatisfiesParentSecurityPolicy) {
                         $methodMetadata->setSatisfiesParentSecurityPolicy();
                     } else {
                         if ($annotation instanceof RunAs) {
                             $methodMetadata->setRunAsRoles($annotation->getRoles());
                         }
                     }
                 }
             }
         }
     }
     return $methodMetadata;
 }
 /**
  * @dataProvider getTestData
  */
 public function testGenerate($class, $method, array $arguments)
 {
     $generator = new ProxyClassGenerator();
     $metadata = new ServiceMetadata();
     $reflection = new \ReflectionClass($class);
     $methodMetadata = new MethodMetadata($reflection->getMethod($method));
     $methodMetadata->setRoles(array('ROLE_FOO'));
     $methodMetadata->setReturnPermissions(array('PERMISSION_RETURN'));
     $metadata->addMethod($method, $methodMetadata);
     $definition = new Definition();
     $definition->setClass($reflection->getName());
     list($className, $proxy) = $generator->generate($definition, $metadata);
     $tmpFile = tempnam(sys_get_temp_dir(), 'proxy');
     file_put_contents($tmpFile, $proxy);
     require_once $tmpFile;
     unlink($tmpFile);
     $className = 'SecurityProxies\\' . $className;
     $proxyClass = new $className();
     $mock = $this->getMockBuilder('JMS\\SecurityExtraBundle\\Security\\Authorization\\Interception\\MethodSecurityInterceptor')->disableOriginalConstructor()->getMock();
     $mock->expects($this->once())->method('invoke')->will($this->returnValue($return = new \stdClass()));
     $proxyClass->jmsSecurityExtraBundle__setMethodSecurityInterceptor($mock);
     $this->assertSame($return, call_user_func_array(array($proxyClass, $method), $arguments));
 }