コード例 #1
0
 /**
  * @dataProvider getTestedImplementations
  *
  * Verifies that generated code is valid and implements expected interfaces
  */
 public function testGeneratesValidCode($className)
 {
     $generator = $this->getProxyGenerator();
     $generatedClassName = UniqueIdentifierGenerator::getIdentifier('AbstractProxyGeneratorTest');
     $generatedClass = new ClassGenerator($generatedClassName);
     $originalClass = new ReflectionClass($className);
     $generatorStrategy = new EvaluatingGeneratorStrategy();
     $generator->generate($originalClass, $generatedClass);
     $generatorStrategy->generate($generatedClass);
     $generatedReflection = new ReflectionClass($generatedClassName);
     if ($originalClass->isInterface()) {
         $this->assertTrue($generatedReflection->implementsInterface($className));
     } else {
         $this->assertEmpty(array_diff($originalClass->getInterfaceNames(), $generatedReflection->getInterfaceNames()));
     }
     $this->assertSame($generatedClassName, $generatedReflection->getName());
     foreach ($this->getExpectedImplementedInterfaces() as $interface) {
         $this->assertTrue($generatedReflection->implementsInterface($interface));
     }
     $proxyGenerated = new $generatedClassName();
     foreach ($generatedReflection->getProperties(ReflectionProperty::IS_PUBLIC) as $property) {
         $this->assertNull($proxyGenerated->{$property});
     }
     /** @var \ReflectionMethod $method */
     foreach ($generatedReflection->getMethods(ReflectionProperty::IS_PUBLIC) as $method) {
         if ($method->getNumberOfParameters() == 0) {
             $this->assertNull(call_user_func(array($proxyGenerated, $method->getName())));
         }
     }
 }
コード例 #2
0
 /**
  * @covers \ProxyManager\GeneratorStrategy\EvaluatingGeneratorStrategy::generate
  * @covers \ProxyManager\GeneratorStrategy\EvaluatingGeneratorStrategy::__construct
  */
 public function testGenerateWithDisabledEval()
 {
     if (!ini_get('suhosin.executor.disable_eval')) {
         $this->markTestSkipped('Ini setting "suhosin.executor.disable_eval" is needed to run this test');
     }
     $strategy = new EvaluatingGeneratorStrategy();
     $className = 'Foo' . uniqid();
     $classGenerator = new ClassGenerator($className);
     $generated = $strategy->generate($classGenerator);
     $this->assertGreaterThan(0, strpos($generated, $className));
     $this->assertTrue(class_exists($className, false));
 }
コード例 #3
0
 /**
  * @dataProvider getTestedImplementations
  *
  * Verifies that generated code is valid and implements expected interfaces
  */
 public function testGeneratesValidCode($className)
 {
     $generator = $this->getProxyGenerator();
     $generatedClassName = UniqueIdentifierGenerator::getIdentifier('AbstractProxyGeneratorTest');
     $generatedClass = new ClassGenerator($generatedClassName);
     $originalClass = new ReflectionClass($className);
     $generatorStrategy = new EvaluatingGeneratorStrategy();
     $generator->generate($originalClass, $generatedClass);
     $generatorStrategy->generate($generatedClass);
     $generatedReflection = new ReflectionClass($generatedClassName);
     if ($originalClass->isInterface()) {
         $this->assertTrue($generatedReflection->implementsInterface($className));
     } else {
         $this->assertEmpty(array_diff($originalClass->getInterfaceNames(), $generatedReflection->getInterfaceNames()));
     }
     $this->assertSame($generatedClassName, $generatedReflection->getName());
     foreach ($this->getExpectedImplementedInterfaces() as $interface) {
         $this->assertTrue($generatedReflection->implementsInterface($interface));
     }
 }
コード例 #4
0
 /**
  * Generates a proxy for the given class name, and retrieves its class name
  *
  * @param string $parentClassName
  *
  * @return string
  */
 private function generateProxy($parentClassName)
 {
     $generatedClassName = __NAMESPACE__ . '\\' . UniqueIdentifierGenerator::getIdentifier('Foo');
     $generator = new LazyLoadingGhostGenerator();
     $generatedClass = new ClassGenerator($generatedClassName);
     $strategy = new EvaluatingGeneratorStrategy();
     $generator->generate(new ReflectionClass($parentClassName), $generatedClass);
     $strategy->generate($generatedClass);
     return $generatedClassName;
 }