Ejemplo n.º 1
0
 public function testExecute()
 {
     $application = new Application();
     $commandTester = new CommandTester($application->getCommand('list'));
     $commandTester->execute(array());
     $this->assertRegExp('/help   Displays help for a command/', $commandTester->getDisplay(), '->execute() returns a list of available commands');
     $commandTester->execute(array('--xml' => true));
     $this->assertRegExp('/<command id="list" namespace="_global" name="list">/', $commandTester->getDisplay(), '->execute() returns a list of available commands in XML if --xml is passed');
 }
Ejemplo n.º 2
0
 public function testExecute()
 {
     $command = new HelpCommand();
     $command->setCommand(new ListCommand());
     $commandTester = new CommandTester($command);
     $commandTester->execute(array());
     $this->assertRegExp('/list \\[--xml\\] \\[namespace\\]/', $commandTester->getDisplay(), '->execute() returns a text help for the given command');
     $commandTester->execute(array('--xml' => true));
     $this->assertRegExp('/<command/', $commandTester->getDisplay(), '->execute() returns an XML help text if --xml is passed');
     $application = new Application();
     $commandTester = new CommandTester($application->getCommand('help'));
     $commandTester->execute(array('command_name' => 'list'));
     $this->assertRegExp('/list \\[--xml\\] \\[namespace\\]/', $commandTester->getDisplay(), '->execute() returns a text help for the given command');
     $commandTester->execute(array('command_name' => 'list', '--xml' => true));
     $this->assertRegExp('/<command/', $commandTester->getDisplay(), '->execute() returns an XML help text if --xml is passed');
 }
 /**
  * @dataProvider getFormat
  * @runInSeparateProcess
  */
 public function testExecution($format)
 {
     $tmpDir = sys_get_temp_dir() . '/sf_hello';
     $filesystem = new Filesystem();
     $filesystem->remove($tmpDir);
     $tester = new CommandTester(new InitApplicationCommand());
     $tester->execute(array('name' => 'Hello' . $format, 'path' => $tmpDir . '/hello' . $format, 'web_path' => $tmpDir . '/web', '--format' => $format));
     $filesystem->mkdirs($tmpDir . '/src');
     $filesystem->touch($tmpDir . '/src/autoload.php');
     $class = 'Hello' . $format . 'Kernel';
     $file = $tmpDir . '/hello' . $format . '/' . $class . '.php';
     $this->assertTrue(file_exists($file));
     $content = file_get_contents($file);
     $content = str_replace("__DIR__.'/../src/vendor/Symfony/src/Symfony/Bundle'", "'" . __DIR__ . "/../../..'", $content);
     file_put_contents($file, $content);
     require_once $file;
     $kernel = new $class('dev', true);
     $response = $kernel->handle(Request::create('/'));
     $this->assertRegExp('/successfully/', $response->getContent());
     $filesystem->remove($tmpDir);
 }
Ejemplo n.º 4
0
require_once __DIR__.'/../../../../bootstrap.php';

use Symfony\Components\Console\Tester\CommandTester;
use Symfony\Components\Console\Command\HelpCommand;
use Symfony\Components\Console\Command\ListCommand;
use Symfony\Components\Console\Application;

$t = new LimeTest(4);

// ->execute()
$t->diag('->execute()');

$command = new HelpCommand();
$command->setCommand(new ListCommand());

$commandTester = new CommandTester($command);
$commandTester->execute(array());
$t->like($commandTester->getDisplay(), '/list \[--xml\] \[namespace\]/', '->execute() returns a text help for the given command');

$commandTester->execute(array('--xml' => true));
$t->like($commandTester->getDisplay(), '/<command/', '->execute() returns an XML help text if --xml is passed');

$application = new Application();
$commandTester = new CommandTester($application->getCommand('help'));
$commandTester->execute(array('command_name' => 'list'));
$t->like($commandTester->getDisplay(), '/list \[--xml\] \[namespace\]/', '->execute() returns a text help for the given command');

$commandTester->execute(array('command_name' => 'list', '--xml' => true));
$t->like($commandTester->getDisplay(), '/<command/', '->execute() returns an XML help text if --xml is passed');
Ejemplo n.º 5
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.º 6
0
 public function testAsXml()
 {
     $command = new \TestCommand();
     $command->setApplication(new Application());
     $tester = new CommandTester($command);
     $tester->execute(array());
     $this->assertXmlStringEqualsXmlFile(self::$fixturesPath . '/command_asxml.txt', $command->asXml(), '->asXml() returns an XML representation of the command');
 }
Ejemplo n.º 7
0
 */

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()');
$t->is($tester->getInput()->getArgument('foo'), 'bar', '->getInput() returns the current input instance');

// ->getOutput()
$t->diag('->getOutput()');
rewind($tester->getOutput()->getStream());
Ejemplo n.º 8
0
<?php

/*
 * 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\Tester\CommandTester;
use Symfony\Components\Console\Application;

$t = new LimeTest(2);

$application = new Application();

// ->execute()
$t->diag('->execute()');

$commandTester = new CommandTester($application->getCommand('list'));
$commandTester->execute(array());
$t->like($commandTester->getDisplay(), '/help   Displays help for a command/', '->execute() returns a list of available commands');

$commandTester->execute(array('--xml' => true));
$t->like($commandTester->getDisplay(), '/<command id="list" namespace="_global" name="list">/', '->execute() returns a list of available commands in XML if --xml is passed');