Ejemplo n.º 1
0
 public function testAsXml()
 {
     $command = new \TestCommand();
     $command->setApplication(new Application());
     $tester = new CommandTester($command);
     $tester->execute(array('command' => $command->getName()));
     $this->assertXmlStringEqualsXmlFile(self::$fixturesPath . '/command_asxml.txt', $command->asXml(), '->asXml() returns an XML representation of the command');
 }
Ejemplo n.º 2
0
 public function testRunWithApplication()
 {
     $command = new \TestCommand();
     $command->setApplication(new Application());
     $exitCode = $command->run(new StringInput(''), new NullOutput());
     $this->assertSame(0, $exitCode, '->run() returns an integer exit code');
 }
Ejemplo n.º 3
0
 public function testLegacyAsXml()
 {
     $this->iniSet('error_reporting', -1 & ~E_USER_DEPRECATED);
     $command = new \TestCommand();
     $command->setApplication(new Application());
     $tester = new CommandTester($command);
     $tester->execute(array('command' => $command->getName()));
     $this->assertXmlStringEqualsXmlFile(self::$fixturesPath . '/command_asxml.txt', $command->asXml(), '->asXml() returns an XML representation of the command');
 }
Ejemplo n.º 4
0
 public function testMergeApplicationDefinitionWithoutArgsThenWithArgsAddsArgs()
 {
     $application1 = new Application();
     $application1->getDefinition()->addArguments(array(new InputArgument('foo')));
     $application1->getDefinition()->addOptions(array(new InputOption('bar')));
     $command = new \TestCommand();
     $command->setApplication($application1);
     $command->setDefinition($definition = new InputDefinition(array()));
     $r = new \ReflectionObject($command);
     $m = $r->getMethod('mergeApplicationDefinition');
     $m->setAccessible(true);
     $m->invoke($command, false);
     $this->assertTrue($command->getDefinition()->hasOption('bar'), '->mergeApplicationDefinition(false) merges the application and the command options');
     $this->assertFalse($command->getDefinition()->hasArgument('foo'), '->mergeApplicationDefinition(false) does not merge the application arguments');
     $m->invoke($command, true);
     $this->assertTrue($command->getDefinition()->hasArgument('foo'), '->mergeApplicationDefinition(true) merges the application arguments and the command arguments');
     $m->invoke($command);
     $this->assertEquals(2, $command->getDefinition()->getArgumentCount(), '->mergeApplicationDefinition() does not try to merge twice the application arguments');
 }
Ejemplo n.º 5
0
$command = new Command('foo');
try
{
  $command->run(new StringInput(''), new NullOutput());
  $t->fail('->run() throws a \LogicException if the execute() method has not been overriden and no code has been provided');
}
catch (\LogicException $e)
{
  $t->pass('->run() throws a \LogicException if the execute() method has not been overriden and no code has been provided');
}

// ->setCode()
$t->diag('->setCode()');
$command = new TestCommand();
$command->setApplication($application);
$ret = $command->setCode(function (InputInterface $input, OutputInterface $output)
{
  $output->writeln('from the code...');
});
$t->is($ret, $command, '->setCode() implements a fluent interface');
$tester = new CommandTester($command);
$tester->execute(array());
$t->is($tester->getDisplay(), "interact called\nfrom the code...\n");

// ->asText()
$t->diag('->asText()');
$t->is($command->asText(), file_get_contents($fixtures.'/command_astext.txt'), '->asText() returns a text representation of the command');

// ->asXml()
$t->diag('->asXml()');
Ejemplo n.º 6
0
 public function testAsXml()
 {
     $command = new \TestCommand();
     $command->setApplication(new Application());
     $tester = new CommandTester($command);
     $tester->execute(array());
     $this->assertEquals($command->asXml(), file_get_contents(self::$fixturesPath . '/command_asxml.txt'), '->asXml() returns an XML representation of the command');
 }