/**
  * {@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;
 }
Esempio n. 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;
 }