/**
  * @covers \ProxyManager\ProxyGenerator\NullObject\MethodGenerator\NullObjectMethodInterceptor
  */
 public function testBodyStructureWithoutByRefReturn()
 {
     $reflectionMethod = new MethodReflection('ProxyManagerTestAsset\\BaseClass', 'publicByReferenceMethod');
     $method = NullObjectMethodInterceptor::generateMethod($reflectionMethod);
     $this->assertSame('publicByReferenceMethod', $method->getName());
     $this->assertCount(0, $method->getParameters());
     $this->assertStringMatchesFormat("\$ref%s = null;\nreturn \$ref%s;", $method->getBody());
 }
 /**
  * {@inheritDoc}
  */
 public function generate(ReflectionClass $originalClass, ClassGenerator $classGenerator)
 {
     CanProxyAssertion::assertClassCanBeProxied($originalClass);
     $interfaces = array('ProxyManager\\Proxy\\NullObjectInterface');
     if ($originalClass->isInterface()) {
         $interfaces[] = $originalClass->getName();
     }
     $classGenerator->setImplementedInterfaces($interfaces);
     foreach (ProxiedMethodsFilter::getProxiedMethods($originalClass) as $method) {
         $classGenerator->addMethodFromGenerator(NullObjectMethodInterceptor::generateMethod(new MethodReflection($method->getDeclaringClass()->getName(), $method->getName())));
     }
     ClassGeneratorUtils::addMethodIfNotFinal($originalClass, $classGenerator, new Constructor($originalClass));
 }
Пример #3
0
 /**
  * {@inheritDoc}
  */
 public function generate(ReflectionClass $originalClass, ClassGenerator $classGenerator)
 {
     $interfaces = array('ProxyManager\\Proxy\\NullObjectInterface');
     if ($originalClass->isInterface()) {
         $interfaces[] = $originalClass->getName();
     } else {
         foreach ($originalClass->getInterfaceNames() as $name) {
             $interfaces[] = $name;
         }
     }
     $classGenerator->setImplementedInterfaces($interfaces);
     foreach (ProxiedMethodsFilter::getProxiedMethods($originalClass) as $method) {
         $classGenerator->addMethodFromGenerator(NullObjectMethodInterceptor::generateMethod(new MethodReflection($method->getDeclaringClass()->getName(), $method->getName())));
     }
     $classGenerator->addMethodFromGenerator(new Constructor($originalClass));
 }