/**
  * {@inheritdoc}
  */
 protected function getGenerators(InputInterface $input, OutputInterface $output)
 {
     $directoryName = $input->getArgument('directory');
     $directory = realpath($directoryName);
     if (!is_dir($directory)) {
         throw new \RuntimeException(sprintf('Invalid directory path "%s".', $directory));
     }
     $generators = [];
     foreach (ClassUtils::getFilesInDirectory($directory, $this->getTestsDirectoryName(), 'php') as $fileName) {
         $classes = ClassUtils::getClassesInFile($fileName);
         if (empty($classes)) {
             $interfaces = ClassUtils::getInterfacesInFile($fileName);
             if (!empty($interfaces)) {
                 continue;
             }
             $output->writeln(sprintf('<comment>Could not find class in "%s".</comment>', $fileName));
         }
         foreach ($classes as $className) {
             $generators[] = new TestGenerator($className, $this->getTestsCaseClassName(), $this->getTestsDirectoryName());
         }
     }
     if (!empty($generators)) {
         $testCaseGenerator = new TestCaseGenerator($generators[0]->getFullClassName(), $this->getTestsCaseClassName(), $this->getTestsDirectoryName());
         if (!is_file($testCaseGenerator->getTargetSourceFile())) {
             $generators[] = $testCaseGenerator;
         }
     }
     return $generators;
 }
예제 #2
0
 /**
  * {@inheritdoc}
  */
 protected function getGenerators(InputInterface $input, OutputInterface $output)
 {
     $fileName = $input->getArgument('file');
     $classes = ClassUtils::getClassesInFile($fileName);
     if (empty($classes)) {
         $output->writeln(sprintf('<comment>Could not find class in "%s".</comment>', $fileName));
     }
     $generators = [];
     foreach ($classes as $className) {
         $generators[] = new TestGenerator($className, $this->getTestsCaseClassName(), $this->getTestsDirectoryName());
     }
     if (!empty($generators)) {
         $testCaseGenerator = new TestCaseGenerator($generators[0]->getFullClassName(), $this->getTestsCaseClassName(), $this->getTestsDirectoryName());
         if (!is_file($testCaseGenerator->getTargetSourceFile())) {
             $generators[] = $testCaseGenerator;
         }
     }
     return $generators;
 }
예제 #3
0
 /**
  * @param string $sourceFile
  *
  * @return string
  */
 private function getClassName($sourceFile)
 {
     $classes = ClassUtils::getClassesInFile($sourceFile);
     if (count($classes) > 0) {
         return $classes[0];
     }
     return;
 }
예제 #4
0
 /**
  * {@inheritdoc}
  */
 public function getAllClassNames()
 {
     if ($this->classNames !== null) {
         return $this->classNames;
     }
     if (!$this->paths) {
         throw MappingException::pathRequired();
     }
     $includedFiles = [];
     foreach ($this->paths as $path) {
         if (!is_dir($path)) {
             throw MappingException::invalidDirectory($path);
         }
         $iterator = new \RegexIterator(new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($path, \FilesystemIterator::SKIP_DOTS), \RecursiveIteratorIterator::LEAVES_ONLY), '/^.+' . preg_quote($this->fileExtension) . '$/i', \RecursiveRegexIterator::GET_MATCH);
         foreach ($iterator as $file) {
             $sourceFile = $file[0];
             if (!preg_match('(^phar:)i', $sourceFile)) {
                 $sourceFile = realpath($sourceFile);
             }
             foreach ($this->excludePaths as $excludePath) {
                 $exclude = str_replace('\\', '/', realpath($excludePath));
                 $current = str_replace('\\', '/', $sourceFile);
                 if (strpos($current, $exclude) !== false) {
                     continue 2;
                 }
             }
             require_once $sourceFile;
             $includedFiles[] = $sourceFile;
         }
     }
     $this->classNames = [];
     foreach ($includedFiles as $includedFile) {
         $this->classNames = array_merge($this->classNames, ClassUtils::getClassesInFile($includedFile));
     }
     return $this->classNames;
 }
예제 #5
0
 /**
  * @param string $filename
  *
  * @return MigrationInterface
  */
 protected function getMigratorClass($filename)
 {
     $classes = ClassUtils::getClassesInFile($filename);
     foreach ($classes as $className) {
         $reflector = new \ReflectionClass($className);
         return $reflector->newInstanceWithoutConstructor();
     }
     return;
 }