Author: Victor Puertas (vpgugr@gmail.com)
 /**
  * Gets the command's definition.
  *
  * @return \Yosymfony\Spress\Plugin\CommandDefinition Definition of the command.
  */
 public function getCommandDefinition()
 {
     $definition = new CommandDefinition('import:wordpress');
     $definition->setDescription('Import a blog from Wordpress');
     $definition->setHelp('Import command for WXR files generated by Wordpress');
     $definition->addArgument('file', CommandDefinition::REQUIRED, 'Path to WXR file');
     $definition->addOption('dry-run', null, null);
     $definition->addOption('post-layout', null, CommandDefinition::VALUE_REQUIRED, 'Layout for post items');
     $definition->addOption('fetch-images', null, null, 'Fetch images used by the Wordpress blog');
     $definition->addOption('not-replace-urls', null, null, 'Do not replace old Wordpress URLs to the new Spress path');
     $definition->addOption('assets-dir', null, CommandDefinition::VALUE_REQUIRED, 'Relative directory to content folder for storing the fetched images', 'assets');
     return $definition;
 }
 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);
 }
 /**
  * Gets the command's definition.
  *
  * @return \Yosymfony\Spress\Plugin\CommandDefinition Definition of the command.
  */
 public function getCommandDefinition()
 {
     $definition = new CommandDefinition('import:csv');
     $definition->setDescription('Import a blog from CSV files');
     $definition->setHelp('Import command for CSV files');
     $definition->addArgument('file', CommandDefinition::REQUIRED, 'Path to CSV file');
     $definition->addOption('dry-run', null, null);
     $definition->addOption('post-layout', null, CommandDefinition::VALUE_REQUIRED, 'Layout for post items');
     $definition->addOption('not-replace-urls', null, null, 'Do not replace old source URLs to the new Spress path');
     $definition->addOption('not-header', null, null);
     $definition->addOption('delimiter-character', null, CommandDefinition::VALUE_REQUIRED, 'Delimited character', ',');
     $definition->addOption('enclosure-character', null, CommandDefinition::VALUE_REQUIRED, 'Enclousure character', '"');
     $definition->addOption('terms-delimiter-character', null, CommandDefinition::VALUE_REQUIRED, 'Terms delimiter character. Used in categories and tags columns', ';');
     return $definition;
 }
 public function testCommandDefinitionWithArgumentsAndOptions()
 {
     $definition = new CommandDefinition('i18:extracts');
     $definition->setDescription('List of texts extracted from your site');
     $definition->setHelp('The <info>i18n:extracts</info> command help you to extract texts.');
     $definition->addArgument('file', null, 'File or directory', './');
     $definition->addOption('filter', 'f', null, 'Filter expression');
     $this->assertEquals('i18:extracts', $definition->getName());
     $this->assertEquals('List of texts extracted from your site', $definition->getDescription());
     $this->assertEquals('The <info>i18n:extracts</info> command help you to extract texts.', $definition->getHelp());
     $this->assertTrue(is_array($definition->getArguments()));
     $this->assertCount(1, $definition->getArguments());
     $argument = $definition->getArguments()[0];
     $this->assertCount(4, $argument);
     $this->assertEquals('file', $argument[0]);
     $this->assertEquals(CommandDefinition::OPTIONAL, $argument[1]);
     $this->assertEquals('File or directory', $argument[2]);
     $this->assertEquals('./', $argument[3]);
     $this->assertTrue(is_array($definition->getOptions()));
     $this->assertCount(1, $definition->getOptions());
     $option = $definition->getOptions()[0];
     $this->assertCount(5, $option);
     $this->assertEquals('filter', $option[0]);
     $this->assertEquals('f', $option[1]);
     $this->assertEquals(CommandDefinition::VALUE_NONE, $option[2]);
     $this->assertEquals('Filter expression', $option[3]);
     $this->assertNull($option[4]);
 }