Ejemplo n.º 1
0
 /**
  * @expectedException        \InvalidArgumentException
  * @expectedExceptionMessage Invalid callable provided to Command::setCode.
  */
 public function testSetCodeWithNonCallable()
 {
     $command = new \TestCommand();
     $command->setCode(array($this, 'nonExistentMethod'));
 }
Ejemplo n.º 2
0
 public function testSetCode()
 {
     $command = new \TestCommand();
     $ret = $command->setCode(function (InputInterface $input, OutputInterface $output)
     {
         $output->writeln('from the code...');
     });
     $this->assertEquals($command, $ret, '->setCode() implements a fluent interface');
     $tester = new CommandTester($command);
     $tester->execute(array());
     $this->assertEquals('interact called'.PHP_EOL.'from the code...'.PHP_EOL, $tester->getDisplay());
 }
Ejemplo n.º 3
0
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()');
$t->is($command->asXml(), file_get_contents($fixtures.'/command_asxml.txt'), '->asXml() returns an XML representation of the command');
Ejemplo n.º 4
0
 public function testSetCodeWithNonClosureCallable()
 {
     $command = new \TestCommand();
     $ret = $command->setCode(array($this, 'callableMethodCommand'));
     $this->assertEquals($command, $ret, '->setCode() implements a fluent interface');
     $tester = new CommandTester($command);
     $tester->execute(array());
     $this->assertEquals('interact called' . PHP_EOL . 'from the code...' . PHP_EOL, $tester->getDisplay());
 }
Ejemplo n.º 5
0
 public function testSetCode()
 {
     $application = new Application();
     $command = new \TestCommand();
     $command->setApplication($application);
     $ret = $command->setCode(function (InputInterface $input, OutputInterface $output) {
         $output->writeln('from the code...');
     });
     $this->assertEquals($ret, $command, '->setCode() implements a fluent interface');
     $tester = new CommandTester($command);
     $tester->execute(array());
     $this->assertEquals($tester->getDisplay(), "interact called\nfrom the code...\n");
 }