public function testReturnsFormattedArrayOfUseStatements()
 {
     $uses = array(array('use' => 'Zend\\Console\\Request', 'as' => 'ConsoleRequest'), array('use' => 'Zend\\Mvc\\MvcEvent', 'as' => null));
     $expected = array('Zend\\Console\\Request' => 'ConsoleRequest', 'Zend\\Mvc\\MvcEvent' => null);
     Phake::when($this->mockFileReflection)->getUses()->thenReturn($uses);
     $this->assertEquals($expected, $this->sut->getUseNames($this->mockFileReflection));
 }
 /**
  * Generate code to cache from class reflection.
  *
  * @todo maybe move some of this into Zend\Code
  *
  * @param  ClassReflection $classReflection
  * @return string
  */
 public function getCacheCode(ClassReflection $classReflection)
 {
     $useString = $this->fileReflectionService->getUseString($classReflection->getDeclaringFile());
     $declaration = $this->classDeclarationService->getClassDeclaration($classReflection);
     $classContents = $classReflection->getContents(false);
     $classFileDir = dirname($classReflection->getFileName());
     $classContents = trim(str_replace('__DIR__', sprintf("'%s'", $classFileDir), $classContents));
     $return = "\nnamespace " . $classReflection->getNamespaceName() . " {\n" . $useString . $declaration . "\n" . $classContents . "\n}\n";
     return $return;
 }
 public function getClassUseName(ClassReflection $currentClass, ClassReflection $useClass)
 {
     $useNames = $this->fileReflectionUseStatementService->getUseNames($currentClass->getDeclaringFile());
     $fullUseClassName = $useClass->getName();
     $classUseName = null;
     if (array_key_exists($fullUseClassName, $useNames)) {
         $classUseName = $useNames[$fullUseClassName] ?: $useClass->getShortName();
     } else {
         if (0 === strpos($fullUseClassName, $currentClass->getNamespaceName())) {
             $classUseName = substr($fullUseClassName, strlen($currentClass->getNamespaceName()) + 1);
         } else {
             $classUseName = '\\' . $fullUseClassName;
         }
     }
     return $classUseName;
 }