Author: Victor Puertas (vpgugr@gmail.com)
 public function testBuildCommands()
 {
     $definition = new CommandDefinition('self-update');
     $definition->setDescription('Update spress.phar to the latest version.');
     $definition->setHelp('The self-update command replace your spress.phar by the latest version.');
     $definition->addOption('all');
     $definition->addArgument('dir');
     $input = $this->getMockBuilder('\\Symfony\\Component\\Console\\Input\\InputInterface')->getMock();
     $input->expects($this->once())->method('getArguments')->will($this->returnValue([]));
     $input->expects($this->once())->method('getOptions')->will($this->returnValue([]));
     $output = $this->getMockBuilder('\\Symfony\\Component\\Console\\Output\\OutputInterface')->getMock();
     $commandPluginMock = $this->getMockBuilder('\\Yosymfony\\Spress\\Plugin\\CommandPlugin')->getMock();
     $commandPluginMock->expects($this->once())->method('getCommandDefinition')->will($this->returnValue($definition));
     $commandPluginMock->expects($this->once())->method('executeCommand');
     $pm = new PluginManager(new EventDispatcher());
     $pm->addPlugin('emptyCommandPlugin', $commandPluginMock);
     $builder = new ConsoleCommandBuilder($pm);
     $symfonyConsoleCommands = $builder->buildCommands();
     $this->assertTrue(is_array($symfonyConsoleCommands));
     $this->assertCount(1, $symfonyConsoleCommands);
     $this->assertContainsOnlyInstancesOf('Symfony\\Component\\Console\\Command\\Command', $symfonyConsoleCommands);
     $symfonyConsoleCommand = $symfonyConsoleCommands[0];
     $this->assertCount(1, $symfonyConsoleCommand->getDefinition()->getOptions());
     $this->assertCount(1, $symfonyConsoleCommand->getDefinition()->getArguments());
     $this->assertEquals('Update spress.phar to the latest version.', $symfonyConsoleCommand->getDescription());
     $this->assertEquals('The self-update command replace your spress.phar by the latest version.', $symfonyConsoleCommand->getHelp());
     $symfonyConsoleCommand->run($input, $output);
 }
Exemple #2
0
 /**
  * Registers the command plugins present in the current directory.
  */
 public function registerCommandPlugins()
 {
     $spress = $this->getSpress();
     try {
         $pm = $spress['spress.plugin.pluginManager'];
         $commandBuilder = new ConsoleCommandBuilder($pm);
         $consoleCommandFromPlugins = $commandBuilder->buildCommands();
         foreach ($consoleCommandFromPlugins as $consoleCommand) {
             $this->add($consoleCommand);
         }
     } catch (\Exception $e) {
     }
 }