/**
  * {@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);
 }
 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->signatureChecker->expects($this->atLeastOnce())->method('checkSignature');
     $this->classSignatureGenerator->expects($this->once())->method('addSignature')->will($this->returnArgument(0));
     $this->assertSame($generatedClass, $generateProxy->invoke($this->factory, 'stdClass'));
     $this->assertTrue(class_exists($generatedClass, false));
     $this->assertSame($generatedClass, $generateProxy->invoke($this->factory, 'stdClass'));
 }
 /**
  * {@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);
 }