Esempio n. 1
0
 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'));
 }
Esempio n. 2
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));
 }