/** * @param string $name */ private function iExecuteCommandAndConfirm($name) { $this->dialog = $this->command->getHelper('dialog'); $inputString = 'y' . PHP_EOL; $this->dialog->setInputStream($this->getInputStream($inputString)); $this->tester->execute(['command' => $name]); }
public function testRun() { $app = $this->getApp(); $command = new LogClear($app); $dialog = new DialogHelper(); $dialog->setInputStream($this->getInputStream("Yes\n")); $command->setHelperSet(new HelperSet(array($dialog))); $tester = new CommandTester($command); $tester->execute(array()); $result = $tester->getDisplay(); $this->assertRegexp('/System & change logs cleared/', $result); }
/** * Check that Magento is not removed if confirmation is denied */ public function testUninstallDoesNotUninstallIfConfirmationDenied() { $application = $this->getApplication(); $application->add(new UninstallCommand()); $command = $this->getApplication()->find('uninstall'); $commandTester = new CommandTester($command); $dialog = new DialogHelper(); $dialog->setInputStream($this->getInputStream('no\\n')); $command->setHelperSet(new HelperSet(array($dialog))); $commandTester->execute(array('command' => $command->getName(), '--installationFolder' => $this->getTestMagentoRoot())); $this->assertEquals("Really uninstall ? [n]: ", $commandTester->getDisplay()); //check magento still installed $this->assertFileExists($this->getTestMagentoRoot() . '/app/etc/local.xml'); }
public function testAskAndValidate() { $dialog = new DialogHelper(); $helperSet = new HelperSet(array(new FormatterHelper())); $dialog->setHelperSet($helperSet); $question = 'What color was the white horse of Henry IV?'; $error = 'This is not a color!'; $validator = function ($color) use($error) { if (!in_array($color, array('white', 'black'))) { throw new \InvalidArgumentException($error); } return $color; }; $dialog->setInputStream($this->getInputStream("\nblack\n")); $this->assertEquals('white', $dialog->askAndValidate($this->getOutputStream(), $question, $validator, 2, 'white')); $this->assertEquals('black', $dialog->askAndValidate($this->getOutputStream(), $question, $validator, 2, 'white')); $dialog->setInputStream($this->getInputStream("green\nyellow\norange\n")); try { $this->assertEquals('white', $dialog->askAndValidate($this->getOutputStream(), $question, $validator, 2, 'white')); $this->fail(); } catch (\InvalidArgumentException $e) { $this->assertEquals($error, $e->getMessage()); } }
public function testInteractiveCommand() { $command = $this->console->find('new'); // prepare the data that will be input interactively // code copied from Sensio\Bundle\GeneratorBundle\Tests\Command\GenerateCommandTest.php $dialog = new DialogHelper(); $dialog->setInputStream($this->getInputStream("\n\nThe Origin of Species\n")); $helper = new HelperSet(array(new FormatterHelper(), $dialog)); $command->setHelperSet($helper); $tester = new CommandTester($command); $tester->execute(array('command' => $command->getName(), '--dir' => $this->tmpDir), array('interactive' => true)); $this->assertContains('ERROR: The title cannot be empty.', $tester->getDisplay(), 'The interactive generator validates wrong title input'); $this->assertContains('Welcome to the easybook interactive book generator', $tester->getDisplay(), 'The interactive generator welcome message is shown'); $this->assertContains('Please, type the title of the book (e.g. The Origin of Species)', $tester->getDisplay(), 'The interactive generator asks for the title of the book'); $this->assertContains('OK You can start writing your book in the following directory', $tester->getDisplay(), 'Interactive book generation is successfully completed'); $this->assertContains('the-origin-of-species', $tester->getDisplay(), 'The book is generated in the proper directory'); }
public function testInteractiveCommand() { $command = $this->console->find('customize'); // prepare the data that will be input interactively // code copied from Sensio\Bundle\GeneratorBundle\Tests\Command\GenerateCommandTest.php $dialog = new DialogHelper(); $dialog->setInputStream($this->getInputStream("\n\nthe-origin-of-species\n\n\nweb\n")); $helper = new HelperSet(array(new FormatterHelper(), $dialog)); $command->setHelperSet($helper); $tester = new CommandTester($command); $tester->execute(array('command' => $command->getName(), '--dir' => $this->tmpDir), array('interactive' => true)); $app = $command->getApp(); $this->assertContains($app['app.signature'], $tester->getDisplay(), 'The interactive customizer displays the application signature'); $this->assertContains('Welcome to the easybook interactive book customizer', $tester->getDisplay(), 'The interactive customizer welcome message is shown'); $this->assertContains('Please, type the slug of the book (e.g. the-origin-of-species)', $tester->getDisplay(), 'The interactive generator asks for the title of the book'); $this->assertContains('ERROR: The slug can only contain letters, numbers and dashes (no spaces)', $tester->getDisplay(), 'Interactive publisher validates wrong "slug" input'); $this->assertContains('OK You can now customize the book design with the following stylesheet:', $tester->getDisplay(), 'The custom CSS is successfully generated'); }
public function testInteractiveCommand() { $command = $this->console->find('publish'); // prepare the data that will be input interactively // code copied from Sensio\Bundle\GeneratorBundle\Tests\Command\GenerateCommandTest.php $dialog = new DialogHelper(); $dialog->setInputStream($this->getInputStream("\n\nthe-origin-of-species\n\n\nweb\n")); $helper = new HelperSet(array(new FormatterHelper(), $dialog)); $command->setHelperSet($helper); $tester = new CommandTester($command); $tester->execute(array('command' => $command->getName(), '--dir' => $this->tmpDir), array('interactive' => true)); $this->assertContains('Welcome to the easybook interactive book publisher', $tester->getDisplay(), 'The interactive publisher welcome message is shown'); $this->assertContains('Please, type the slug of the book (e.g. the-origin-of-species)', $tester->getDisplay(), 'The interactive generator asks for the title of the book'); $this->assertContains('ERROR: The slug can only contain letters, numbers and dashes (no spaces)', $tester->getDisplay(), 'Interactive publisher validates wrong "slug" input'); $this->assertContains('ERROR: The edition cannot be empty.', $tester->getDisplay(), 'Interactive publisher validates wrong "edition" input'); $this->assertContains('Publishing web edition of The Origin of Species book...', $tester->getDisplay(), 'The book is being published'); $this->assertContains('OK You can access the book in the following directory:', $tester->getDisplay(), 'The book is successfully published'); $this->assertContains('/the-origin-of-species/Output/web', $tester->getDisplay(), 'The book is published in the proper directory'); }