Ejemplo n.º 1
0
 /**
  * Finds and registers Commands.
  *
  * Override this method if your bundle commands do not follow the conventions:
  *
  * * Commands are in the 'Command' sub-directory
  * * Commands extend Symfony\Component\Console\Command\Command
  *
  * @param \BackBee\Console\Console $console An Application instance
  */
 public function registerCommands(Console $console)
 {
     if (is_dir($dir = $this->getBBDir() . '/Console/Command')) {
         $finder = new Finder();
         $finder->files()->name('*Command.php')->in($dir);
         $ns = 'BackBee\\Console\\Command';
         foreach ($finder as $file) {
             if ($relativePath = $file->getRelativePath()) {
                 $ns .= '\\' . strtr($relativePath, '/', '\\');
             }
             $r = new \ReflectionClass($ns . '\\' . $file->getBasename('.php'));
             if ($r->isSubclassOf('BackBee\\Console\\AbstractCommand') && !$r->isAbstract() && !$r->getConstructor()->getNumberOfRequiredParameters()) {
                 $console->add($r->newInstance());
             }
         }
     }
     foreach ($this->getBundles() as $bundle) {
         if (!is_dir($dir = $bundle->getBaseDirectory() . '/Command')) {
             continue;
         }
         $finder = new Finder();
         $finder->files()->name('*Command.php')->in($dir);
         $ns = (new \ReflectionClass($bundle))->getNamespaceName() . '\\Command';
         foreach ($finder as $file) {
             if ($relativePath = $file->getRelativePath()) {
                 $ns .= '\\' . strtr($relativePath, '/', '\\');
             }
             $r = new \ReflectionClass($ns . '\\' . $file->getBasename('.php'));
             if ($r->isSubclassOf('BackBee\\Console\\AbstractCommand') && !$r->isAbstract() && 0 === $r->getConstructor()->getNumberOfRequiredParameters()) {
                 $instance = $r->newInstance();
                 $instance->setBundle($bundle);
                 $console->add($instance);
             }
         }
     }
 }
 /**
  * @expectedException \InvalidArgumentException
  * @expectedExceptionMessage File not found: file_doesnt_exist.ext
  * @covers ::execute
  */
 public function testExecute_fileNotFound()
 {
     // mock the Kernel or create one depending on your needs
     $application = new Console(self::$app);
     $application->add(new AclLoadCommand());
     $command = $application->find('acl:load');
     $commandTester = new CommandTester($command);
     $file = 'file_doesnt_exist.ext';
     $commandTester->execute(array('command' => $command->getName(), 'file' => $file));
 }