Beispiel #1
0
    /**
     * Constructor
     *
     * @param PropertyGenerator $initializerProperty
     * @param PropertyGenerator $initTracker
     * @param Properties        $properties
     */
    public function __construct(PropertyGenerator $initializerProperty, PropertyGenerator $initTracker, Properties $properties)
    {
        $docblock = <<<'DOCBLOCK'
Triggers initialization logic for this ghost object

@param string  $methodName
@param mixed[] $parameters

@return mixed
DOCBLOCK;
        parent::__construct(UniqueIdentifierGenerator::getIdentifier('callInitializer'), [new ParameterGenerator('methodName'), new ParameterGenerator('parameters', 'array')], static::VISIBILITY_PRIVATE, null, $docblock);
        $initializer = $initializerProperty->getName();
        $initialization = $initTracker->getName();
        $bodyTemplate = <<<'PHP'
if ($this->%s || ! $this->%s) {
    return;
}

$this->%s = true;

%s
%s

$result = $this->%s->__invoke($this, $methodName, $parameters, $this->%s, $properties);
$this->%s = false;

return $result;
PHP;
        $this->setBody(sprintf($bodyTemplate, $initialization, $initializer, $initialization, $this->propertiesInitializationCode($properties), $this->propertiesReferenceArrayCode($properties), $initializer, $initializer, $initialization));
    }
 /**
  * Constructor
  */
 public function __construct()
 {
     parent::__construct(UniqueIdentifierGenerator::getIdentifier('initializationTracker'));
     $this->setVisibility(self::VISIBILITY_PRIVATE);
     $this->setDocblock('@var bool tracks initialization status - true while the object is initializing');
     $this->setDefaultValue(false);
 }
 /**
  * @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())));
         }
     }
 }
 /**
  * Creates a new {@link \bitExpert\Disco\Proxy\Configuration\PropertyGenerator\ParameterValuesProperty}.
  *
  * @throws InvalidArgumentException
  */
 public function __construct()
 {
     parent::__construct(UniqueIdentifierGenerator::getIdentifier('parameterValues'));
     $this->setVisibility(self::VISIBILITY_PRIVATE);
     $this->setDefaultValue([]);
     $this->setDocBlock('@var array Collection of scalar values which can be injected into beans');
 }
Beispiel #5
0
 /**
  * Creates a new {@link \bitExpert\Disco\Proxy\Configuration\MethodGenerator\GetParameter}.
  *
  * @param ReflectionClass $originalClass
  * @param ParameterValuesProperty $parameterValueProperty
  * @throws InvalidArgumentException
  */
 public function __construct(ReflectionClass $originalClass, ParameterValuesProperty $parameterValueProperty)
 {
     parent::__construct(UniqueIdentifierGenerator::getIdentifier('getParameter'));
     $propertyNameParameter = new ParameterGenerator('propertyName');
     $requiredParameter = new ParameterGenerator('required');
     $requiredParameter->setDefaultValue(true);
     $defaultValueParameter = new ParameterGenerator('defaultValue');
     $defaultValueParameter->setDefaultValue(null);
     $body = '$steps = explode(\'.\', $' . $propertyNameParameter->getName() . ');' . PHP_EOL;
     $body .= '$value = $this->' . $parameterValueProperty->getName() . ';' . PHP_EOL;
     $body .= '$currentPath = [];' . PHP_EOL;
     $body .= 'foreach ($steps as $step) {' . PHP_EOL;
     $body .= '    $currentPath[] = $step;' . PHP_EOL;
     $body .= '    if (isset($value[$step])) {' . PHP_EOL;
     $body .= '        $value = $value[$step];' . PHP_EOL;
     $body .= '    } else {' . PHP_EOL;
     $body .= '        $value = $' . $defaultValueParameter->getName() . ';' . PHP_EOL;
     $body .= '        break;' . PHP_EOL;
     $body .= '    }' . PHP_EOL;
     $body .= '}' . PHP_EOL . PHP_EOL;
     $body .= 'if ($' . $requiredParameter->getName() . ' && (null === $value)) {' . PHP_EOL;
     $body .= '    if (null === $' . $defaultValueParameter->getName() . ') {' . PHP_EOL;
     $body .= '        throw new \\RuntimeException(\'Parameter "\' .$' . $propertyNameParameter->getName() . '. \'" is required but not defined and no default value provided!\');' . PHP_EOL;
     $body .= '    }' . PHP_EOL;
     $body .= '    throw new \\RuntimeException(\'Parameter "\' .$' . $propertyNameParameter->getName() . '. \'" not defined!\');' . PHP_EOL;
     $body .= '}' . PHP_EOL . PHP_EOL;
     $body .= 'return $value;' . PHP_EOL;
     $this->setParameter($propertyNameParameter);
     $this->setParameter($requiredParameter);
     $this->setParameter($defaultValueParameter);
     $this->setVisibility(self::VISIBILITY_PROTECTED);
     $this->setBody($body);
 }
 /**
  * Creates a new {@link \bitExpert\Disco\Proxy\Configuration\PropertyGenerator\BeanPostProcessorsProperty}.
  *
  * @throws InvalidArgumentException
  */
 public function __construct()
 {
     parent::__construct(UniqueIdentifierGenerator::getIdentifier('postProcessors'));
     $this->setDefaultValue([]);
     $this->setVisibility(self::VISIBILITY_PRIVATE);
     $this->setDocBlock('@var ' . \bitExpert\Disco\BeanFactoryPostProcessor::class . '[]');
 }
 /**
  * Constructor
  */
 public function __construct()
 {
     parent::__construct(UniqueIdentifierGenerator::getIdentifier('methodPrefixInterceptors'));
     $this->setDefaultValue(array());
     $this->setVisibility(self::VISIBILITY_PRIVATE);
     $this->setDocblock('@var \\Closure[] map of interceptors to be called per-method before execution');
 }
 /**
  * Constructor
  *
  * @param Properties $properties
  */
 public function __construct(Properties $properties)
 {
     parent::__construct(UniqueIdentifierGenerator::getIdentifier('protectedProperties'));
     $this->setVisibility(self::VISIBILITY_PRIVATE);
     $this->setStatic(true);
     $this->setDocblock('@var string[][] declaring class name of defined protected properties, indexed by property name');
     $this->setDefaultValue($this->getMap($properties));
 }
 /**
  * @covers \ProxyManager\GeneratorStrategy\BaseGeneratorStrategy::generate
  */
 public function testGenerate()
 {
     $strategy = new BaseGeneratorStrategy();
     $className = UniqueIdentifierGenerator::getIdentifier('Foo');
     $classGenerator = new ClassGenerator($className);
     $generated = $strategy->generate($classGenerator);
     $this->assertGreaterThan(0, strpos($generated, $className));
 }
 /**
  * Constructor
  *
  * @param Properties $properties
  */
 public function __construct(Properties $properties)
 {
     parent::__construct(UniqueIdentifierGenerator::getIdentifier('privateProperties'));
     $this->setVisibility(self::VISIBILITY_PRIVATE);
     $this->setStatic(true);
     $this->setDocBlock('@var array[][] visibility and default value of defined properties, indexed by property name and class name');
     $this->setDefaultValue($this->getMap($properties));
 }
 /**
  * @covers \ProxyManager\GeneratorStrategy\EvaluatingGeneratorStrategy::generate
  * @covers \ProxyManager\GeneratorStrategy\EvaluatingGeneratorStrategy::__construct
  */
 public function testGenerate()
 {
     $strategy = new EvaluatingGeneratorStrategy();
     $className = UniqueIdentifierGenerator::getIdentifier('Foo');
     $classGenerator = new ClassGenerator($className);
     $generated = $strategy->generate($classGenerator);
     $this->assertGreaterThan(0, strpos($generated, $className));
     $this->assertTrue(class_exists($className, false));
 }
 /**
  * Constructor
  */
 public function __construct(PropertyGenerator $initializerProperty, PropertyGenerator $publicPropertiesDefaults, PropertyGenerator $initializationTracker)
 {
     parent::__construct(UniqueIdentifierGenerator::getIdentifier('callInitializer'));
     $this->setDocblock("Triggers initialization logic for this ghost object");
     $this->setParameters(array(new ParameterGenerator('methodName'), new ParameterGenerator('parameters', 'array')));
     $this->setVisibility(static::VISIBILITY_PRIVATE);
     $initializer = $initializerProperty->getName();
     $initialization = $initializationTracker->getName();
     $this->setBody('if ($this->' . $initialization . ' || ! $this->' . $initializer . ') {' . "\n    return;\n}\n\n" . "\$this->" . $initialization . " = true;\n\n" . "foreach (self::\$" . $publicPropertiesDefaults->getName() . " as \$key => \$default) {\n" . "    \$this->\$key = \$default;\n" . "}\n\n" . '$this->' . $initializer . '->__invoke' . '($this, $methodName, $parameters, $this->' . $initializer . ');' . "\n\n" . "\$this->" . $initialization . " = false;");
 }
Beispiel #13
0
 /**
  * @param \ReflectionClass $originalClass
  */
 public function __construct(ReflectionClass $originalClass)
 {
     parent::__construct(UniqueIdentifierGenerator::getIdentifier('publicProperties'));
     foreach ($originalClass->getProperties(ReflectionProperty::IS_PUBLIC) as $publicProperty) {
         $this->publicProperties[$publicProperty->getName()] = true;
     }
     $this->setDefaultValue($this->publicProperties);
     $this->setVisibility(self::VISIBILITY_PRIVATE);
     $this->setStatic(true);
     $this->setDocblock('@var bool[] map of public properties of the parent class');
 }
 /**
  * @param \Zend\Code\Reflection\MethodReflection $originalMethod
  *
  * @return self|static
  */
 public static function generateMethod(MethodReflection $originalMethod) : self
 {
     /* @var $method self */
     $method = static::fromReflection($originalMethod);
     if ($originalMethod->returnsReference()) {
         $reference = UniqueIdentifierGenerator::getIdentifier('ref');
         $method->setBody("\${$reference} = null;\nreturn \${$reference};");
     } else {
         $method->setBody('');
     }
     return $method;
 }
Beispiel #15
0
 /**
  * @covers \ProxyManager\Autoloader\Autoloader::__invoke
  */
 public function testWillAutoloadExistingFile()
 {
     $namespace = 'Foo';
     $className = UniqueIdentifierGenerator::getIdentifier('Bar');
     $fqcn = $namespace . '\\' . $className;
     $fileName = sys_get_temp_dir() . '/foo_' . uniqid() . '.php';
     file_put_contents($fileName, '<?php namespace ' . $namespace . '; class ' . $className . '{}');
     $this->classNameInflector->expects($this->once())->method('isProxyClassName')->with($fqcn)->will($this->returnValue(true));
     $this->fileLocator->expects($this->once())->method('getProxyFileName')->will($this->returnValue($fileName));
     $this->assertTrue($this->autoloader->__invoke($fqcn));
     $this->assertTrue(class_exists($fqcn, false));
 }
 public function testGeneratesClass()
 {
     $generateProxy = new ReflectionMethod($this->factory, 'generateProxy');
     $generateProxy->setAccessible(true);
     $generatedClass = UniqueIdentifierGenerator::getIdentifier('fooBar');
     $this->classNameInflector->expects($this->any())->method('getProxyClassName')->with('stdClass')->will($this->returnValue($generatedClass));
     $this->generatorStrategy->expects($this->once())->method('generate')->with($this->isInstanceOf('Zend\\Code\\Generator\\ClassGenerator'));
     $this->proxyAutoloader->expects($this->once())->method('__invoke')->with($generatedClass)->will($this->returnCallback(function ($className) {
         eval('class ' . $className . ' {}');
     }));
     $this->assertSame($generatedClass, $generateProxy->invoke($this->factory, 'stdClass'));
     $this->assertTrue(class_exists($generatedClass, false));
     $this->assertSame($generatedClass, $generateProxy->invoke($this->factory, 'stdClass'));
 }
 /**
  * @covers \ProxyManager\GeneratorStrategy\FileWriterGeneratorStrategy::__construct
  * @covers \ProxyManager\GeneratorStrategy\FileWriterGeneratorStrategy::generate
  */
 public function testGenerate()
 {
     $locator = $this->getMock('ProxyManager\\FileLocator\\FileLocatorInterface');
     $generator = new FileWriterGeneratorStrategy($locator);
     $tmpFile = sys_get_temp_dir() . '/FileWriterGeneratorStrategyTest' . uniqid() . '.php';
     $namespace = 'Foo';
     $className = UniqueIdentifierGenerator::getIdentifier('Bar');
     $fqcn = $namespace . '\\' . $className;
     $locator->expects($this->any())->method('getProxyFileName')->with($fqcn)->will($this->returnValue($tmpFile));
     $body = $generator->generate(new ClassGenerator($fqcn));
     $this->assertGreaterThan(0, strpos($body, $className));
     $this->assertFalse(class_exists($fqcn, false));
     $this->assertTrue(file_exists($tmpFile));
     require $tmpFile;
     $this->assertTrue(class_exists($fqcn, false));
 }
Beispiel #18
0
 /**
  * Creates a new {@link \bitExpert\Disco\Proxy\LazyBean\MethodGenerator\Constructor}.
  *
  * @param ReflectionClass $originalClass
  * @param BeanFactoryConfigurationProperty $beanFactoryConfigurationProperty
  */
 public function __construct(ReflectionClass $originalClass, BeanFactoryConfigurationProperty $beanFactoryConfigurationProperty)
 {
     parent::__construct(UniqueIdentifierGenerator::getIdentifier('wrapBeanAsLazy'));
     $this->setParameter(new ParameterGenerator('beanId'));
     $this->setParameter(new ParameterGenerator('beanType'));
     $this->setParameter(new ParameterGenerator('instance'));
     $content = '$factory = new \\' . \bitExpert\Disco\Proxy\LazyBean\LazyBeanFactory::class . '($beanId, $this->' . $beanFactoryConfigurationProperty->getName() . '->getProxyManagerConfiguration());' . PHP_EOL;
     $content .= '$initializer = function (&$wrappedObject, \\' . \ProxyManager\Proxy\LazyLoadingInterface::class . ' $proxy, $method, array $parameters, &$initializer) use($instance) {' . PHP_EOL;
     $content .= '    $initializer = null;' . PHP_EOL;
     $content .= '    $wrappedObject = $instance;' . PHP_EOL;
     $content .= '    return true;' . PHP_EOL;
     $content .= '};' . PHP_EOL;
     $content .= PHP_EOL;
     $content .= '$initializer->bindTo($this);' . PHP_EOL;
     $content .= 'return $factory->createProxy($beanType, $initializer);' . PHP_EOL;
     $this->setVisibility(self::VISIBILITY_PROTECTED);
     $this->setBody($content);
 }
 /**
  * @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));
     }
 }
 /**
  * {@inheritDoc}
  *
  * @covers \ProxyManager\Factory\NullObjectFactory::__construct
  * @covers \ProxyManager\Factory\NullObjectFactory::createProxy
  * @covers \ProxyManager\Factory\NullObjectFactory::getGenerator
  *
  * NOTE: serious mocking going on in here (a class is generated on-the-fly) - careful
  */
 public function testWillTryAutoGeneration()
 {
     $instance = new stdClass();
     $proxyClassName = UniqueIdentifierGenerator::getIdentifier('bar');
     $generator = $this->getMock('ProxyManager\\GeneratorStrategy\\GeneratorStrategyInterface');
     $autoloader = $this->getMock('ProxyManager\\Autoloader\\AutoloaderInterface');
     $this->config->expects($this->any())->method('getGeneratorStrategy')->will($this->returnValue($generator));
     $this->config->expects($this->any())->method('getProxyAutoloader')->will($this->returnValue($autoloader));
     $generator->expects($this->once())->method('generate')->with($this->callback(function (ClassGenerator $targetClass) use($proxyClassName) {
         return $targetClass->getName() === $proxyClassName;
     }));
     // simulate autoloading
     $autoloader->expects($this->once())->method('__invoke')->with($proxyClassName)->will($this->returnCallback(function () use($proxyClassName) {
         eval('class ' . $proxyClassName . ' extends \\ProxyManagerTestAsset\\NullObjectMock {}');
     }));
     $this->inflector->expects($this->once())->method('getProxyClassName')->with('stdClass')->will($this->returnValue($proxyClassName));
     $this->inflector->expects($this->once())->method('getUserClassName')->with('stdClass')->will($this->returnValue('ProxyManagerTestAsset\\NullObjectMock'));
     $factory = new NullObjectFactory($this->config);
     /* @var $proxy \ProxyManagerTestAsset\NullObjectMock */
     $proxy = $factory->createProxy($instance);
     $this->assertInstanceOf($proxyClassName, $proxy);
 }
Beispiel #21
0
 /**
  * Constructor
  */
 public function __construct()
 {
     parent::__construct(UniqueIdentifierGenerator::getIdentifier('adapter'));
     $this->setVisibility(self::VISIBILITY_PRIVATE);
     $this->setDocblock('@var \\' . AdapterInterface::class . ' Remote web service adapter');
 }
 /**
  * Creates a new {@link \bitExpert\Disco\Proxy\Configuration\PropertyGenerator\SessionBeansProperty}.
  *
  * @throws InvalidArgumentException
  */
 public function __construct()
 {
     parent::__construct(UniqueIdentifierGenerator::getIdentifier('sessionBeans'));
     $this->setVisibility(self::VISIBILITY_PRIVATE);
     $this->setDocBlock('@var ' . \bitExpert\Disco\Store\BeanStore::class);
 }
Beispiel #23
0
 /**
  * Constructor
  */
 public function __construct()
 {
     parent::__construct(UniqueIdentifierGenerator::getIdentifier('initializer'));
     $this->setVisibility(self::VISIBILITY_PRIVATE);
     $this->setDocblock('@var \\Closure|null initializer responsible for generating the wrapped object');
 }
Beispiel #24
0
 /**
  * Constructor
  */
 public function __construct()
 {
     parent::__construct(UniqueIdentifierGenerator::getIdentifier('adapter'));
     $this->setVisibility(self::VISIBILITY_PRIVATE);
     $this->setDocblock('@var \\ProxyManager\\Factory\\RemoteObject\\AdapterInterface Remote web service adapter');
 }
 /**
  * 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;
 }
 public function testWhenFailingAllTemporaryFilesAreRemoved()
 {
     $tmpDirPath = sys_get_temp_dir() . '/' . uniqid('noTempFilesLeftBehind', true);
     mkdir($tmpDirPath);
     /* @var $locator \ProxyManager\FileLocator\FileLocatorInterface|\PHPUnit_Framework_MockObject_MockObject */
     $locator = $this->getMock('ProxyManager\\FileLocator\\FileLocatorInterface');
     $generator = new FileWriterGeneratorStrategy($locator);
     $tmpFile = $tmpDirPath . '/' . uniqid('FileWriterGeneratorStrategyFailedFileMoveTest', true) . '.php';
     $namespace = 'Foo';
     $className = UniqueIdentifierGenerator::getIdentifier('Bar');
     $fqcn = $namespace . '\\' . $className;
     $locator->expects($this->any())->method('getProxyFileName')->with($fqcn)->will($this->returnValue($tmpFile));
     mkdir($tmpFile);
     try {
         $generator->generate(new ClassGenerator($fqcn));
         $this->fail('An exception was supposed to be thrown');
     } catch (FileNotWritableException $exception) {
         rmdir($tmpFile);
         $this->assertEquals(array('.', '..'), scandir($tmpDirPath));
     }
 }
 /**
  * {@inheritDoc}
  *
  * @covers \ProxyManager\Factory\AccessInterceptorValueHolderFactory::__construct
  * @covers \ProxyManager\Factory\AccessInterceptorValueHolderFactory::createProxy
  * @covers \ProxyManager\Factory\AccessInterceptorValueHolderFactory::getGenerator
  *
  * NOTE: serious mocking going on in here (a class is generated on-the-fly) - careful
  */
 public function testWillTryAutoGeneration()
 {
     $instance = new stdClass();
     $proxyClassName = UniqueIdentifierGenerator::getIdentifier('bar');
     $generator = $this->getMock('ProxyManager\\GeneratorStrategy\\GeneratorStrategyInterface');
     $autoloader = $this->getMock('ProxyManager\\Autoloader\\AutoloaderInterface');
     $this->config->expects($this->any())->method('getGeneratorStrategy')->will($this->returnValue($generator));
     $this->config->expects($this->any())->method('getProxyAutoloader')->will($this->returnValue($autoloader));
     $generator->expects($this->once())->method('generate')->with($this->callback(function (ClassGenerator $targetClass) use($proxyClassName) {
         return $targetClass->getName() === $proxyClassName;
     }));
     // simulate autoloading
     $autoloader->expects($this->once())->method('__invoke')->with($proxyClassName)->will($this->returnCallback(function () use($proxyClassName) {
         eval('class ' . $proxyClassName . ' extends \\ProxyManagerTestAsset\\AccessInterceptorValueHolderMock {}');
     }));
     $this->inflector->expects($this->once())->method('getProxyClassName')->with('stdClass')->will($this->returnValue($proxyClassName));
     $this->inflector->expects($this->once())->method('getUserClassName')->with('stdClass')->will($this->returnValue('ProxyManagerTestAsset\\LazyLoadingMock'));
     $this->signatureChecker->expects($this->atLeastOnce())->method('checkSignature');
     $this->classSignatureGenerator->expects($this->once())->method('addSignature')->will($this->returnArgument(0));
     $factory = new AccessInterceptorValueHolderFactory($this->config);
     /* @var $proxy \ProxyManagerTestAsset\AccessInterceptorValueHolderMock */
     $proxy = $factory->createProxy($instance, array('foo'), array('bar'));
     $this->assertInstanceOf($proxyClassName, $proxy);
     $this->assertSame($instance, $proxy->instance);
     $this->assertSame(array('foo'), $proxy->prefixInterceptors);
     $this->assertSame(array('bar'), $proxy->suffixInterceptors);
 }
 /**
  * Creates a new {@link \bitExpert\Disco\Proxy\Configuration\PropertyGenerator\BeanFactoryConfigurationProperty}.
  *
  * @throws InvalidArgumentException
  */
 public function __construct()
 {
     parent::__construct(UniqueIdentifierGenerator::getIdentifier('config'));
     $this->setVisibility(self::VISIBILITY_PRIVATE);
     $this->setDocBlock('@var ' . BeanFactoryConfiguration::class);
 }
 /**
  * {@inheritDoc}
  *
  * @covers \ProxyManager\Factory\RemoteObjectFactory::__construct
  * @covers \ProxyManager\Factory\RemoteObjectFactory::createProxy
  * @covers \ProxyManager\Factory\RemoteObjectFactory::getGenerator
  *
  * NOTE: serious mocking going on in here (a class is generated on-the-fly) - careful
  */
 public function testWillTryAutoGeneration()
 {
     $proxyClassName = UniqueIdentifierGenerator::getIdentifier('bar');
     $generator = $this->getMock('ProxyManager\\GeneratorStrategy\\GeneratorStrategyInterface');
     $autoloader = $this->getMock('ProxyManager\\Autoloader\\AutoloaderInterface');
     $this->config->expects($this->any())->method('getGeneratorStrategy')->will($this->returnValue($generator));
     $this->config->expects($this->any())->method('getProxyAutoloader')->will($this->returnValue($autoloader));
     $generator->expects($this->once())->method('generate')->with($this->callback(function (ClassGenerator $targetClass) use($proxyClassName) {
         return $targetClass->getName() === $proxyClassName;
     }));
     // simulate autoloading
     $autoloader->expects($this->once())->method('__invoke')->with($proxyClassName)->will($this->returnCallback(function () use($proxyClassName) {
         eval('class ' . $proxyClassName . ' extends stdClass {}');
     }));
     $this->inflector->expects($this->once())->method('getProxyClassName')->with('ProxyManagerTestAsset\\BaseInterface')->will($this->returnValue($proxyClassName));
     $this->inflector->expects($this->once())->method('getUserClassName')->with('ProxyManagerTestAsset\\BaseInterface')->will($this->returnValue('stdClass'));
     $this->signatureChecker->expects($this->atLeastOnce())->method('checkSignature');
     $this->classSignatureGenerator->expects($this->once())->method('addSignature')->will($this->returnArgument(0));
     $adapter = $this->getMock('ProxyManager\\Factory\\RemoteObject\\AdapterInterface');
     $factory = new RemoteObjectFactory($adapter, $this->config);
     /* @var $proxy \stdClass */
     $proxy = $factory->createProxy('ProxyManagerTestAsset\\BaseInterface', $adapter);
     $this->assertInstanceOf($proxyClassName, $proxy);
 }
 /**
  * @dataProvider getBaseIdentifierNames
  *
  * @covers \ProxyManager\Generator\Util\UniqueIdentifierGenerator::getIdentifier
  */
 public function testGeneratesValidIdentifiers($name)
 {
     $this->assertRegExp('/^[a-zA-Z_\\x7f-\\xff][a-zA-Z0-9_\\x7f-\\xff]+$/', UniqueIdentifierGenerator::getIdentifier($name));
 }