예제 #1
0
$command->setApplication($application);
$tester = new CommandTester($command);
try
{
  $tester->execute(array('--bar' => true));
  $t->fail('->run() throws a \RuntimeException when the input does not validate the current InputDefinition');
}
catch (\RuntimeException $e)
{
  $t->pass('->run() throws a \RuntimeException when the input does not validate the current InputDefinition');
}

$t->is($tester->execute(array(), array('interactive' => true)), "interact called\nexecute called\n", '->run() calls the interact() method if the input is interactive');
$t->is($tester->execute(array(), array('interactive' => false)), "execute called\n", '->run() does not call the interact() method if the input is not interactive');

$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)
예제 #2
0
 /**
  * Adds a command object.
  *
  * If a command with the same name already exists, it will be overridden.
  *
  * @param Command $command A Command object
  *
  * @return Command The registered command
  */
 public function addCommand(Command $command)
 {
     $command->setApplication($this);
     $this->commands[$command->getFullName()] = $command;
     foreach ($command->getAliases() as $alias) {
         $this->aliases[$alias] = $command;
     }
     return $command;
 }
예제 #3
0
 public function mergeApplicationDefinition()
 {
   return parent::mergeApplicationDefinition();
 }
예제 #4
0
 public function testRun()
 {
     $command = new \TestCommand();
     $application = new Application();
     $command->setApplication($application);
     $tester = new CommandTester($command);
     try {
         $tester->execute(array('--bar' => true));
         $this->fail('->run() throws a \\InvalidArgumentException when the input does not validate the current InputDefinition');
     } catch (\Exception $e) {
         $this->assertInstanceOf('\\InvalidArgumentException', $e, '->run() throws a \\InvalidArgumentException when the input does not validate the current InputDefinition');
         $this->assertEquals('The "--bar" option does not exist.', $e->getMessage(), '->run() throws a \\InvalidArgumentException when the input does not validate the current InputDefinition');
     }
     $this->assertEquals('interact called' . PHP_EOL . 'execute called' . PHP_EOL, $tester->execute(array(), array('interactive' => true)), '->run() calls the interact() method if the input is interactive');
     $this->assertEquals('execute called' . PHP_EOL, $tester->execute(array(), array('interactive' => false)), '->run() does not call the interact() method if the input is not interactive');
     $command = new Command('foo');
     try {
         $command->run(new StringInput(''), new NullOutput());
         $this->fail('->run() throws a \\LogicException if the execute() method has not been overriden and no code has been provided');
     } catch (\Exception $e) {
         $this->assertInstanceOf('\\LogicException', $e, '->run() throws a \\LogicException if the execute() method has not been overriden and no code has been provided');
         $this->assertEquals('You must override the execute() method in the concrete command class.', $e->getMessage(), '->run() throws a \\LogicException if the execute() method has not been overriden and no code has been provided');
     }
 }
예제 #5
0
 * This file is part of the symfony package.
 * (c) Fabien Potencier <*****@*****.**>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

require_once __DIR__.'/../../../../bootstrap.php';

use Symfony\Components\Console\Command\Command;
use Symfony\Components\Console\Output\Output;
use Symfony\Components\Console\Tester\CommandTester;

$t = new LimeTest(6);

$command = new Command('foo');
$command->addArgument('command');
$command->addArgument('foo');
$command->setCode(function ($input, $output) { $output->writeln('foo'); });

$tester = new CommandTester($command);
$tester->execute(array('foo' => 'bar'), array('interactive' => false, 'decorated' => false, 'verbosity' => Output::VERBOSITY_VERBOSE));

// ->execute()
$t->diag('->execute()');
$t->is($tester->getInput()->isInteractive(), false, '->execute() takes an interactive option');
$t->is($tester->getOutput()->isDecorated(), false, '->execute() takes a decorated option');
$t->is($tester->getOutput()->getVerbosity(), Output::VERBOSITY_VERBOSE, '->execute() takes a verbosity option');

// ->getInput()
$t->diag('->getInput()');
예제 #6
0
 public function getHelper($name)
 {
     return parent::getHelper($name);
 }
예제 #7
0
 public function testRun()
 {
     $command = new \TestCommand();
     $application = new Application();
     $command->setApplication($application);
     $tester = new CommandTester($command);
     try {
         $tester->execute(array('--bar' => true));
         $this->fail('->run() throws a \\RuntimeException when the input does not validate the current InputDefinition');
     } catch (\RuntimeException $e) {
     }
     $this->assertEquals($tester->execute(array(), array('interactive' => true)), "interact called\nexecute called\n", '->run() calls the interact() method if the input is interactive');
     $this->assertEquals($tester->execute(array(), array('interactive' => false)), "execute called\n", '->run() does not call the interact() method if the input is not interactive');
     $command = new Command('foo');
     try {
         $command->run(new StringInput(''), new NullOutput());
         $this->fail('->run() throws a \\LogicException if the execute() method has not been overriden and no code has been provided');
     } catch (\LogicException $e) {
     }
 }