public function testCachingFileScannerWillUseSameInternalFileScannerWithMatchingFileNameAnAnnotationManagerObject() { CachingFileScanner::clearCache(); // single entry, based on file $cfs1 = new CachingFileScanner(__DIR__ . '/../TestAsset/BarClass.php'); $this->assertContains('ZendTest\\Code\\TestAsset\\BarClass', $cfs1->getClassNames()); $this->assertEquals(1, $this->getCacheCount($cfs1)); // ensure same class is used internally $cfs2 = new CachingFileScanner(__DIR__ . '/../TestAsset/BarClass.php'); $this->assertEquals(1, $this->getCacheCount($cfs2)); $this->assertSameInternalFileScanner($cfs1, $cfs2); // ensure $cfs3 = new CachingFileScanner(__DIR__ . '/../TestAsset/FooClass.php'); $this->assertEquals(2, $this->getCacheCount($cfs3)); $this->assertDifferentInternalFileScanner($cfs2, $cfs3); $annoManager = new AnnotationManager(); $cfs4 = new CachingFileScanner(__DIR__ . '/../TestAsset/FooClass.php', $annoManager); $this->assertEquals(3, $this->getCacheCount($cfs4)); $this->assertDifferentInternalFileScanner($cfs3, $cfs4); $cfs5 = new CachingFileScanner(__DIR__ . '/../TestAsset/FooClass.php', $annoManager); $this->assertEquals(3, $this->getCacheCount($cfs5)); $this->assertSameInternalFileScanner($cfs4, $cfs5); $cfs6 = new CachingFileScanner(__DIR__ . '/../TestAsset/BarClass.php', $annoManager); $this->assertEquals(4, $this->getCacheCount($cfs6)); $this->assertDifferentInternalFileScanner($cfs5, $cfs6); }
/** * Create namespace code * * @param string $namespace * @param Reflection\ClassReflection $class * @return string the namespace + class + uses * @todo Detect defined constants */ protected function buildNamespace(Reflection\ClassReflection $class) { $code = "namespace {$class->getNamespaceName()} {" . PHP_EOL; $uses = array(); // Reformat uses foreach ($class->getDeclaringFile()->getUses() as $use) { $uses[$use['use']] = $use['as']; } //Just sort the uses ksort($uses); // Create block by block $code .= $this->buildUses($uses); // @TODO $this->buildConstants($class); $code .= $this->buildClassDecleration($class); $code .= $this->buildExtend($uses, $class); $code .= $this->buildInterface($uses, $class); $code .= PHP_EOL . $this->buildContent($class) . PHP_EOL; $code .= "}" . PHP_EOL . PHP_EOL; // Clear reflection memory \Zend\Code\Scanner\CachingFileScanner::clearCache(); return fwrite($this->handle, $code); }
protected function setUp() { CachingFileScanner::clearCache(); }