Yosymfony\Spress\Plugin\ConsoleCommandBuilder::buildCommands PHP Méthode

buildCommands() public méthode

Gets a list of Symfony Console command.
public buildCommands ( ) : Command[]
Résultat Symfony\Component\Console\Command\Command[] Symfony Console commands
    public function buildCommands()
    {
        $result = [];
        $pluginsCollection = $this->pluginManager->getPluginCollection();
        foreach ($pluginsCollection as $plugin) {
            if ($this->isValidCommandPlugin($plugin) === true) {
                $result[] = $this->buildCommand($plugin);
            }
        }
        return $result;
    }

Usage Example

 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);
 }
All Usage Examples Of Yosymfony\Spress\Plugin\ConsoleCommandBuilder::buildCommands