/** * @expectedException \InvalidArgumentException * @expectedExceptionMessage The output config file format foobar is not allowed. */ public function testExecuteFailedConfigFormatNotAllowed() { $application = new ConsoleApplication($this->silex, 'Fakery Generator Test Application', 'N/A'); $application->add(new GenerateCommand()); $command = $application->find('fakery:generate'); $commandTester = new CommandTester($command); $commandTester->execute(array('command' => $command->getName(), 'config' => static::$fixtures . 'Entity_User_fakery_generator_config_2014-04-14_10-57-17.json', '--config-format' => 'foobar')); }
/** * @dataProvider providerExecute */ public function testExecute($args, $expectedOutput) { $application = new ConsoleApplication($this->silex, 'Fakery Generator Test Application', 'N/A'); $application->add(new InfoCommand()); $command = $application->find('fakery:info'); $commandTester = new CommandTester($command); $commandTester->execute(array_merge(['command' => $command->getName()], $args)); $this->assertRegExp('/' . $expectedOutput . '/', $commandTester->getDisplay()); // $this->assertEquals($expectedOutput, $commandTester->getDisplay()); }
/** * @dataProvider providerExecute */ public function testExecute($configFile, $expectedOutput, $expectedStatusCode, $exception = null, $exceptionMessage = null) { if ($exception) { $this->setExpectedException($exception, $exceptionMessage); } $application = new ConsoleApplication($this->silex, 'Fakery Generator Test Application', 'N/A'); $application->add(new ValidateCommand()); $command = $application->find('fakery:validate'); $commandTester = new CommandTester($command); $commandTester->execute(['command' => $command->getName(), 'config' => static::$fixtures . $configFile]); $this->assertEquals($expectedStatusCode, $commandTester->getStatusCode()); $this->assertRegExp('/' . $expectedOutput . '/', $commandTester->getDisplay()); }
/** * @dataProvider providerExecute */ public function testExecute($format, $expectedException = null, $expectedExceptionMessage = null) { if (!empty($expectedException)) { $this->setExpectedException($expectedException, $expectedExceptionMessage); } $application = new ConsoleApplication($this->silex, 'Fakery Generator Test Application', 'N/A'); $application->add(new ConfigExampleCommand()); $command = $application->find('fakery:config:example'); $commandTester = new CommandTester($command); $commandTester->execute(['command' => $command->getName(), 'output-dir' => static::$dumpDir, '--format' => $format]); $filePattern = 'Entity_User_fakery_generator_config_\\d{4}-\\d{2}-\\d{2}_\\d{2}-\\d{2}-\\d{2}\\.' . $format; $outputPattern = '#Example Config file dumped to ' . preg_quote(static::$dumpDir, '#') . '/' . $filePattern . '#'; $this->assertRegExp($outputPattern, $commandTester->getDisplay()); $finder = new Finder(); $finder->name('/' . $filePattern . '/')->files()->in(static::$dumpDir); $this->assertCount(1, $finder); }
} use CSanquer\FakeryGenerator\Command\ConfigExampleCommand; use CSanquer\FakeryGenerator\Command\InfoCommand; use CSanquer\FakeryGenerator\Command\GenerateCommand; use CSanquer\FakeryGenerator\Command\ValidateCommand; use CSanquer\Silex\Tools\Command\AsseticDumpCommand; use CSanquer\Silex\Tools\Command\CacheClearCommand; use CSanquer\Silex\Tools\Command\ServerRunCommand; use CSanquer\Silex\Tools\ConsoleApplication; $console = new ConsoleApplication($app, 'Fakery Generator Application', 'N/A'); // register commands to the application //$console // ->register('my-command') // ->setDefinition(array( // // new InputOption('some-option', null, InputOption::VALUE_NONE, 'Some help'), // )) // ->setDescription('My command description') // ->setCode(function (InputInterface $input, OutputInterface $output) use ($app) { // // do something // }) //; // or add your existing commands to the application //$console->add(new MyCommand()); $console->add(new CacheClearCommand()); $console->add(new AsseticDumpCommand()); $console->add(new ServerRunCommand()); $console->add(new ValidateCommand()); $console->add(new InfoCommand()); $console->add(new ConfigExampleCommand()); $console->add(new GenerateCommand()); return $console;