public function testGeneratedParametersFromReflection()
 {
     $method = MethodGenerator::fromReflection(new MethodReflection('ProxyManagerTestAsset\\BaseClass', 'publicTypeHintedMethod'));
     $this->assertSame('publicTypeHintedMethod', $method->getName());
     $parameters = $method->getParameters();
     $this->assertCount(1, $parameters);
     $param = $parameters['param'];
     $this->assertSame('stdClass', $param->getType());
 }
 /**
  * Verify that building from reflection works
  */
 public function testGenerateFromReflection()
 {
     $method = MethodGenerator::fromReflection(new MethodReflection(__CLASS__, __FUNCTION__));
     $this->assertSame(__FUNCTION__, $method->getName());
     $this->assertSame(MethodGenerator::VISIBILITY_PUBLIC, $method->getVisibility());
     $this->assertFalse($method->isStatic());
     $this->assertSame('Verify that building from reflection works', $method->getDocBlock()->getShortDescription());
     $method = MethodGenerator::fromReflection(new MethodReflection('ProxyManagerTestAsset\\BaseClass', 'protectedMethod'));
     $this->assertSame(MethodGenerator::VISIBILITY_PROTECTED, $method->getVisibility());
     $method = MethodGenerator::fromReflection(new MethodReflection('ProxyManagerTestAsset\\BaseClass', 'privateMethod'));
     $this->assertSame(MethodGenerator::VISIBILITY_PRIVATE, $method->getVisibility());
 }
 /**
  * Retrieves all abstract methods to be proxied
  *
  * @param ReflectionClass $originalClass
  *
  * @return MethodGenerator[]
  */
 private function getAbstractProxiedMethods(ReflectionClass $originalClass)
 {
     return array_map(function (ReflectionMethod $method) {
         return ProxyManagerMethodGenerator::fromReflection(new MethodReflection($method->getDeclaringClass()->getName(), $method->getName()))->setAbstract(false);
     }, ProxiedMethodsFilter::getAbstractProxiedMethods($originalClass));
 }
Exemple #4
0
 /**
  * @override Enforces generation of \ProxyManager\Generator\MethodGenerator.
  *
  * {@inheritDoc}
  * @throws \Zend\Code\Generator\Exception\InvalidArgumentException
  */
 public static function fromReflection(MethodReflection $reflectionMethod) : MethodGenerator
 {
     $method = parent::fromReflection($reflectionMethod);
     /*
      * When overwriting methods PHP 7 enforces the same method parameters to be defined as in the base class. Since
      * the {@link \bitExpert\Disco\AnnotationBeanFactory} calls the generated methods without any parameters we
      * simply set a default value of null for each of the method parameters.
      */
     $method->setParameters([]);
     foreach ($reflectionMethod->getParameters() as $reflectionParameter) {
         $parameter = ParameterGenerator::fromReflection($reflectionParameter);
         $parameter->setDefaultValue(null);
         $method->setParameter($parameter);
     }
     return $method;
 }