mirror of
https://github.com/linuxserver/Heimdall.git
synced 2025-12-05 06:23:53 +09:00
update to laravel 5.7 and try getting autologin saved
This commit is contained in:
207
vendor/symfony/console/Tests/ApplicationTest.php
vendored
207
vendor/symfony/console/Tests/ApplicationTest.php
vendored
@@ -16,24 +16,24 @@ use Symfony\Component\Console\Application;
|
||||
use Symfony\Component\Console\Command\Command;
|
||||
use Symfony\Component\Console\CommandLoader\FactoryCommandLoader;
|
||||
use Symfony\Component\Console\DependencyInjection\AddConsoleCommandPass;
|
||||
use Symfony\Component\Console\Helper\HelperSet;
|
||||
use Symfony\Component\Console\Event\ConsoleCommandEvent;
|
||||
use Symfony\Component\Console\Event\ConsoleErrorEvent;
|
||||
use Symfony\Component\Console\Event\ConsoleTerminateEvent;
|
||||
use Symfony\Component\Console\Exception\CommandNotFoundException;
|
||||
use Symfony\Component\Console\Exception\NamespaceNotFoundException;
|
||||
use Symfony\Component\Console\Helper\FormatterHelper;
|
||||
use Symfony\Component\Console\Helper\HelperSet;
|
||||
use Symfony\Component\Console\Input\ArgvInput;
|
||||
use Symfony\Component\Console\Input\ArrayInput;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Input\InputArgument;
|
||||
use Symfony\Component\Console\Input\InputDefinition;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Input\InputOption;
|
||||
use Symfony\Component\Console\Output\NullOutput;
|
||||
use Symfony\Component\Console\Output\Output;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
use Symfony\Component\Console\Output\StreamOutput;
|
||||
use Symfony\Component\Console\Tester\ApplicationTester;
|
||||
use Symfony\Component\Console\Event\ConsoleCommandEvent;
|
||||
use Symfony\Component\Console\Event\ConsoleErrorEvent;
|
||||
use Symfony\Component\Console\Event\ConsoleExceptionEvent;
|
||||
use Symfony\Component\Console\Event\ConsoleTerminateEvent;
|
||||
use Symfony\Component\Console\Exception\CommandNotFoundException;
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
use Symfony\Component\EventDispatcher\EventDispatcher;
|
||||
|
||||
@@ -57,6 +57,7 @@ class ApplicationTest extends TestCase
|
||||
require_once self::$fixturesPath.'/BarBucCommand.php';
|
||||
require_once self::$fixturesPath.'/FooSubnamespaced1Command.php';
|
||||
require_once self::$fixturesPath.'/FooSubnamespaced2Command.php';
|
||||
require_once self::$fixturesPath.'/FooWithoutAliasCommand.php';
|
||||
require_once self::$fixturesPath.'/TestTiti.php';
|
||||
require_once self::$fixturesPath.'/TestToto.php';
|
||||
}
|
||||
@@ -276,10 +277,10 @@ class ApplicationTest extends TestCase
|
||||
$expectedMsg = "The namespace \"f\" is ambiguous.\nDid you mean one of these?\n foo\n foo1";
|
||||
|
||||
if (method_exists($this, 'expectException')) {
|
||||
$this->expectException(CommandNotFoundException::class);
|
||||
$this->expectException(NamespaceNotFoundException::class);
|
||||
$this->expectExceptionMessage($expectedMsg);
|
||||
} else {
|
||||
$this->setExpectedException(CommandNotFoundException::class, $expectedMsg);
|
||||
$this->setExpectedException(NamespaceNotFoundException::class, $expectedMsg);
|
||||
}
|
||||
|
||||
$application->findNamespace('f');
|
||||
@@ -294,7 +295,7 @@ class ApplicationTest extends TestCase
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \Symfony\Component\Console\Exception\CommandNotFoundException
|
||||
* @expectedException \Symfony\Component\Console\Exception\NamespaceNotFoundException
|
||||
* @expectedExceptionMessage There are no commands defined in the "bar" namespace.
|
||||
*/
|
||||
public function testFindInvalidNamespace()
|
||||
@@ -458,6 +459,52 @@ class ApplicationTest extends TestCase
|
||||
$application->find($name);
|
||||
}
|
||||
|
||||
public function testDontRunAlternativeNamespaceName()
|
||||
{
|
||||
$application = new Application();
|
||||
$application->add(new \Foo1Command());
|
||||
$application->setAutoExit(false);
|
||||
$tester = new ApplicationTester($application);
|
||||
$tester->run(array('command' => 'foos:bar1'), array('decorated' => false));
|
||||
$this->assertSame('
|
||||
|
||||
There are no commands defined in the "foos" namespace.
|
||||
|
||||
Did you mean this?
|
||||
foo
|
||||
|
||||
|
||||
', $tester->getDisplay(true));
|
||||
}
|
||||
|
||||
public function testCanRunAlternativeCommandName()
|
||||
{
|
||||
$application = new Application();
|
||||
$application->add(new \FooWithoutAliasCommand());
|
||||
$application->setAutoExit(false);
|
||||
$tester = new ApplicationTester($application);
|
||||
$tester->setInputs(array('y'));
|
||||
$tester->run(array('command' => 'foos'), array('decorated' => false));
|
||||
$display = trim($tester->getDisplay(true));
|
||||
$this->assertContains('Command "foos" is not defined', $display);
|
||||
$this->assertContains('Do you want to run "foo" instead? (yes/no) [no]:', $display);
|
||||
$this->assertContains('called', $display);
|
||||
}
|
||||
|
||||
public function testDontRunAlternativeCommandName()
|
||||
{
|
||||
$application = new Application();
|
||||
$application->add(new \FooWithoutAliasCommand());
|
||||
$application->setAutoExit(false);
|
||||
$tester = new ApplicationTester($application);
|
||||
$tester->setInputs(array('n'));
|
||||
$exitCode = $tester->run(array('command' => 'foos'), array('decorated' => false));
|
||||
$this->assertSame(1, $exitCode);
|
||||
$display = trim($tester->getDisplay(true));
|
||||
$this->assertContains('Command "foos" is not defined', $display);
|
||||
$this->assertContains('Do you want to run "foo" instead? (yes/no) [no]:', $display);
|
||||
}
|
||||
|
||||
public function provideInvalidCommandNamesSingle()
|
||||
{
|
||||
return array(
|
||||
@@ -575,7 +622,8 @@ class ApplicationTest extends TestCase
|
||||
$application->find('foo2:command');
|
||||
$this->fail('->find() throws a CommandNotFoundException if namespace does not exist');
|
||||
} catch (\Exception $e) {
|
||||
$this->assertInstanceOf('Symfony\Component\Console\Exception\CommandNotFoundException', $e, '->find() throws a CommandNotFoundException if namespace does not exist');
|
||||
$this->assertInstanceOf('Symfony\Component\Console\Exception\NamespaceNotFoundException', $e, '->find() throws a NamespaceNotFoundException if namespace does not exist');
|
||||
$this->assertInstanceOf('Symfony\Component\Console\Exception\CommandNotFoundException', $e, 'NamespaceNotFoundException extends from CommandNotFoundException');
|
||||
$this->assertCount(3, $e->getAlternatives());
|
||||
$this->assertContains('foo', $e->getAlternatives());
|
||||
$this->assertContains('foo1', $e->getAlternatives());
|
||||
@@ -912,6 +960,30 @@ class ApplicationTest extends TestCase
|
||||
$this->assertSame(4, $exitCode, '->run() returns integer exit code extracted from raised exception');
|
||||
}
|
||||
|
||||
public function testRunDispatchesIntegerExitCode()
|
||||
{
|
||||
$passedRightValue = false;
|
||||
|
||||
// We can assume here that some other test asserts that the event is dispatched at all
|
||||
$dispatcher = new EventDispatcher();
|
||||
$dispatcher->addListener('console.terminate', function (ConsoleTerminateEvent $event) use (&$passedRightValue) {
|
||||
$passedRightValue = (4 === $event->getExitCode());
|
||||
});
|
||||
|
||||
$application = new Application();
|
||||
$application->setDispatcher($dispatcher);
|
||||
$application->setAutoExit(false);
|
||||
|
||||
$application->register('test')->setCode(function (InputInterface $input, OutputInterface $output) {
|
||||
throw new \Exception('', 4);
|
||||
});
|
||||
|
||||
$tester = new ApplicationTester($application);
|
||||
$tester->run(array('command' => 'test'));
|
||||
|
||||
$this->assertTrue($passedRightValue, '-> exit code 4 was passed in the console.terminate event');
|
||||
}
|
||||
|
||||
public function testRunReturnsExitCodeOneForExceptionCodeZero()
|
||||
{
|
||||
$exception = new \Exception('', 0);
|
||||
@@ -927,6 +999,30 @@ class ApplicationTest extends TestCase
|
||||
$this->assertSame(1, $exitCode, '->run() returns exit code 1 when exception code is 0');
|
||||
}
|
||||
|
||||
public function testRunDispatchesExitCodeOneForExceptionCodeZero()
|
||||
{
|
||||
$passedRightValue = false;
|
||||
|
||||
// We can assume here that some other test asserts that the event is dispatched at all
|
||||
$dispatcher = new EventDispatcher();
|
||||
$dispatcher->addListener('console.terminate', function (ConsoleTerminateEvent $event) use (&$passedRightValue) {
|
||||
$passedRightValue = (1 === $event->getExitCode());
|
||||
});
|
||||
|
||||
$application = new Application();
|
||||
$application->setDispatcher($dispatcher);
|
||||
$application->setAutoExit(false);
|
||||
|
||||
$application->register('test')->setCode(function (InputInterface $input, OutputInterface $output) {
|
||||
throw new \Exception();
|
||||
});
|
||||
|
||||
$tester = new ApplicationTester($application);
|
||||
$tester->run(array('command' => 'test'));
|
||||
|
||||
$this->assertTrue($passedRightValue, '-> exit code 1 was passed in the console.terminate event');
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \LogicException
|
||||
* @expectedExceptionMessage An option with shortcut "e" already exists.
|
||||
@@ -1164,9 +1260,6 @@ class ApplicationTest extends TestCase
|
||||
$this->assertContains('before.error.after.', $tester->getDisplay());
|
||||
}
|
||||
|
||||
/**
|
||||
* @requires PHP 7
|
||||
*/
|
||||
public function testRunWithError()
|
||||
{
|
||||
$application = new Application();
|
||||
@@ -1235,36 +1328,6 @@ class ApplicationTest extends TestCase
|
||||
$this->assertEquals(1, $tester->getStatusCode());
|
||||
}
|
||||
|
||||
/**
|
||||
* @group legacy
|
||||
* @expectedDeprecation The "ConsoleEvents::EXCEPTION" event is deprecated since Symfony 3.3 and will be removed in 4.0. Listen to the "ConsoleEvents::ERROR" event instead.
|
||||
*/
|
||||
public function testLegacyExceptionListenersAreStillTriggered()
|
||||
{
|
||||
$dispatcher = $this->getDispatcher();
|
||||
$dispatcher->addListener('console.exception', function (ConsoleExceptionEvent $event) {
|
||||
$event->getOutput()->write('caught.');
|
||||
|
||||
$event->setException(new \RuntimeException('replaced in caught.'));
|
||||
});
|
||||
|
||||
$application = new Application();
|
||||
$application->setDispatcher($dispatcher);
|
||||
$application->setAutoExit(false);
|
||||
|
||||
$application->register('foo')->setCode(function (InputInterface $input, OutputInterface $output) {
|
||||
throw new \RuntimeException('foo');
|
||||
});
|
||||
|
||||
$tester = new ApplicationTester($application);
|
||||
$tester->run(array('command' => 'foo'));
|
||||
$this->assertContains('before.caught.error.after.', $tester->getDisplay());
|
||||
$this->assertContains('replaced in caught.', $tester->getDisplay());
|
||||
}
|
||||
|
||||
/**
|
||||
* @requires PHP 7
|
||||
*/
|
||||
public function testErrorIsRethrownIfNotHandledByConsoleErrorEvent()
|
||||
{
|
||||
$application = new Application();
|
||||
@@ -1287,7 +1350,6 @@ class ApplicationTest extends TestCase
|
||||
}
|
||||
|
||||
/**
|
||||
* @requires PHP 7
|
||||
* @expectedException \LogicException
|
||||
* @expectedExceptionMessage error
|
||||
*/
|
||||
@@ -1309,9 +1371,6 @@ class ApplicationTest extends TestCase
|
||||
$this->assertContains('before.dym.error.after.', $tester->getDisplay(), 'The PHP Error did not dispached events');
|
||||
}
|
||||
|
||||
/**
|
||||
* @requires PHP 7
|
||||
*/
|
||||
public function testRunDispatchesAllEventsWithError()
|
||||
{
|
||||
$application = new Application();
|
||||
@@ -1329,9 +1388,6 @@ class ApplicationTest extends TestCase
|
||||
$this->assertContains('before.dym.error.after.', $tester->getDisplay(), 'The PHP Error did not dispached events');
|
||||
}
|
||||
|
||||
/**
|
||||
* @requires PHP 7
|
||||
*/
|
||||
public function testRunWithErrorFailingStatusCode()
|
||||
{
|
||||
$application = new Application();
|
||||
@@ -1422,24 +1478,6 @@ class ApplicationTest extends TestCase
|
||||
$this->assertEquals('some test value', $extraValue);
|
||||
}
|
||||
|
||||
/**
|
||||
* @group legacy
|
||||
*/
|
||||
public function testTerminalDimensions()
|
||||
{
|
||||
$application = new Application();
|
||||
$originalDimensions = $application->getTerminalDimensions();
|
||||
$this->assertCount(2, $originalDimensions);
|
||||
|
||||
$width = 80;
|
||||
if ($originalDimensions[0] == $width) {
|
||||
$width = 100;
|
||||
}
|
||||
|
||||
$application->setTerminalDimensions($width, 80);
|
||||
$this->assertSame(array($width, 80), $application->getTerminalDimensions());
|
||||
}
|
||||
|
||||
public function testSetRunCustomDefaultCommand()
|
||||
{
|
||||
$command = new \FooCommand();
|
||||
@@ -1592,9 +1630,6 @@ class ApplicationTest extends TestCase
|
||||
return $dispatcher;
|
||||
}
|
||||
|
||||
/**
|
||||
* @requires PHP 7
|
||||
*/
|
||||
public function testErrorIsRethrownIfNotHandledByConsoleErrorEventWithCatchingEnabled()
|
||||
{
|
||||
$application = new Application();
|
||||
@@ -1615,6 +1650,34 @@ class ApplicationTest extends TestCase
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \RuntimeException
|
||||
* @expectedExceptionMessage foo
|
||||
*/
|
||||
public function testThrowingErrorListener()
|
||||
{
|
||||
$dispatcher = $this->getDispatcher();
|
||||
$dispatcher->addListener('console.error', function (ConsoleErrorEvent $event) {
|
||||
throw new \RuntimeException('foo');
|
||||
});
|
||||
|
||||
$dispatcher->addListener('console.command', function () {
|
||||
throw new \RuntimeException('bar');
|
||||
});
|
||||
|
||||
$application = new Application();
|
||||
$application->setDispatcher($dispatcher);
|
||||
$application->setAutoExit(false);
|
||||
$application->setCatchExceptions(false);
|
||||
|
||||
$application->register('foo')->setCode(function (InputInterface $input, OutputInterface $output) {
|
||||
$output->write('foo.');
|
||||
});
|
||||
|
||||
$tester = new ApplicationTester($application);
|
||||
$tester->run(array('command' => 'foo'));
|
||||
}
|
||||
|
||||
protected function tearDown()
|
||||
{
|
||||
putenv('SHELL_VERBOSITY');
|
||||
|
||||
@@ -12,16 +12,16 @@
|
||||
namespace Symfony\Component\Console\Tests\Command;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Component\Console\Application;
|
||||
use Symfony\Component\Console\Command\Command;
|
||||
use Symfony\Component\Console\Helper\FormatterHelper;
|
||||
use Symfony\Component\Console\Application;
|
||||
use Symfony\Component\Console\Input\InputDefinition;
|
||||
use Symfony\Component\Console\Input\InputArgument;
|
||||
use Symfony\Component\Console\Input\InputOption;
|
||||
use Symfony\Component\Console\Input\InputDefinition;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Input\InputOption;
|
||||
use Symfony\Component\Console\Input\StringInput;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
use Symfony\Component\Console\Output\NullOutput;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
use Symfony\Component\Console\Tester\CommandTester;
|
||||
|
||||
class CommandTest extends TestCase
|
||||
@@ -340,7 +340,7 @@ class CommandTest extends TestCase
|
||||
$command->setApplication(new Application());
|
||||
$command->setProcessTitle('foo');
|
||||
$this->assertSame(0, $command->run(new StringInput(''), new NullOutput()));
|
||||
if (function_exists('cli_set_process_title')) {
|
||||
if (\function_exists('cli_set_process_title')) {
|
||||
if (null === @cli_get_process_title() && 'Darwin' === PHP_OS) {
|
||||
$this->markTestSkipped('Running "cli_get_process_title" as an unprivileged user is not supported on MacOS.');
|
||||
}
|
||||
@@ -392,13 +392,7 @@ class CommandTest extends TestCase
|
||||
$tester = new CommandTester($command);
|
||||
$tester->execute(array());
|
||||
|
||||
if (\PHP_VERSION_ID < 70000) {
|
||||
// Cannot bind static closures in PHP 5
|
||||
$this->assertEquals('interact called'.PHP_EOL.'not bound'.PHP_EOL, $tester->getDisplay());
|
||||
} else {
|
||||
// Can bind static closures in PHP 7
|
||||
$this->assertEquals('interact called'.PHP_EOL.'bound'.PHP_EOL, $tester->getDisplay());
|
||||
}
|
||||
$this->assertEquals('interact called'.PHP_EOL.'bound'.PHP_EOL, $tester->getDisplay());
|
||||
}
|
||||
|
||||
private static function createClosure()
|
||||
|
||||
@@ -12,10 +12,10 @@
|
||||
namespace Symfony\Component\Console\Tests\Command;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Component\Console\Tester\CommandTester;
|
||||
use Symfony\Component\Console\Application;
|
||||
use Symfony\Component\Console\Command\HelpCommand;
|
||||
use Symfony\Component\Console\Command\ListCommand;
|
||||
use Symfony\Component\Console\Application;
|
||||
use Symfony\Component\Console\Tester\CommandTester;
|
||||
|
||||
class HelpCommandTest extends TestCase
|
||||
{
|
||||
|
||||
@@ -12,8 +12,8 @@
|
||||
namespace Symfony\Component\Console\Tests\Command;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Component\Console\Tester\CommandTester;
|
||||
use Symfony\Component\Console\Application;
|
||||
use Symfony\Component\Console\Tester\CommandTester;
|
||||
|
||||
class ListCommandTest extends TestCase
|
||||
{
|
||||
|
||||
@@ -41,7 +41,7 @@ class LockableTraitTest extends TestCase
|
||||
{
|
||||
$command = new \FooLockCommand();
|
||||
|
||||
if (SemaphoreStore::isSupported(false)) {
|
||||
if (SemaphoreStore::isSupported()) {
|
||||
$store = new SemaphoreStore();
|
||||
} else {
|
||||
$store = new FlockStore();
|
||||
|
||||
@@ -12,10 +12,12 @@
|
||||
namespace Symfony\Component\Console\Tests\DependencyInjection;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Component\Console\Command\Command;
|
||||
use Symfony\Component\Console\CommandLoader\ContainerCommandLoader;
|
||||
use Symfony\Component\Console\DependencyInjection\AddConsoleCommandPass;
|
||||
use Symfony\Component\Console\Command\Command;
|
||||
use Symfony\Component\DependencyInjection\Argument\ServiceClosureArgument;
|
||||
use Symfony\Component\DependencyInjection\ChildDefinition;
|
||||
use Symfony\Component\DependencyInjection\Compiler\PassConfig;
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
use Symfony\Component\DependencyInjection\Definition;
|
||||
use Symfony\Component\DependencyInjection\TypedReference;
|
||||
@@ -28,31 +30,30 @@ class AddConsoleCommandPassTest extends TestCase
|
||||
public function testProcess($public)
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
$container->addCompilerPass(new AddConsoleCommandPass());
|
||||
$container->addCompilerPass(new AddConsoleCommandPass(), PassConfig::TYPE_BEFORE_REMOVING);
|
||||
$container->setParameter('my-command.class', 'Symfony\Component\Console\Tests\DependencyInjection\MyCommand');
|
||||
|
||||
$id = 'my-command';
|
||||
$definition = new Definition('%my-command.class%');
|
||||
$definition->setPublic($public);
|
||||
$definition->addTag('console.command');
|
||||
$container->setDefinition('my-command', $definition);
|
||||
$container->setDefinition($id, $definition);
|
||||
|
||||
$container->compile();
|
||||
|
||||
$alias = 'console.command.symfony_component_console_tests_dependencyinjection_mycommand';
|
||||
$alias = 'console.command.public_alias.my-command';
|
||||
|
||||
if ($public) {
|
||||
$this->assertFalse($container->hasAlias($alias));
|
||||
$id = 'my-command';
|
||||
} else {
|
||||
$id = $alias;
|
||||
// The alias is replaced by a Definition by the ReplaceAliasByActualDefinitionPass
|
||||
// in case the original service is private
|
||||
$this->assertFalse($container->hasDefinition('my-command'));
|
||||
$this->assertFalse($container->hasDefinition($id));
|
||||
$this->assertTrue($container->hasDefinition($alias));
|
||||
}
|
||||
|
||||
$this->assertTrue($container->hasParameter('console.command.ids'));
|
||||
$this->assertSame(array($alias => $id), $container->getParameter('console.command.ids'));
|
||||
$this->assertSame(array($public ? $id : $alias), $container->getParameter('console.command.ids'));
|
||||
}
|
||||
|
||||
public function testProcessRegistersLazyCommands()
|
||||
@@ -73,8 +74,7 @@ class AddConsoleCommandPassTest extends TestCase
|
||||
$this->assertSame(ContainerCommandLoader::class, $commandLoader->getClass());
|
||||
$this->assertSame(array('my:command' => 'my-command', 'my:alias' => 'my-command'), $commandLoader->getArgument(1));
|
||||
$this->assertEquals(array(array('my-command' => new ServiceClosureArgument(new TypedReference('my-command', MyCommand::class)))), $commandLocator->getArguments());
|
||||
$this->assertSame(array('console.command.symfony_component_console_tests_dependencyinjection_mycommand' => 'my-command'), $container->getParameter('console.command.ids'));
|
||||
$this->assertSame(array('my-command' => true), $container->getParameter('console.lazy_command.ids'));
|
||||
$this->assertSame(array(), $container->getParameter('console.command.ids'));
|
||||
$this->assertSame(array(array('setName', array('my:command')), array('setAliases', array(array('my:alias')))), $command->getMethodCalls());
|
||||
}
|
||||
|
||||
@@ -96,8 +96,7 @@ class AddConsoleCommandPassTest extends TestCase
|
||||
$this->assertSame(ContainerCommandLoader::class, $commandLoader->getClass());
|
||||
$this->assertSame(array('default' => 'with-default-name'), $commandLoader->getArgument(1));
|
||||
$this->assertEquals(array(array('with-default-name' => new ServiceClosureArgument(new TypedReference('with-default-name', NamedCommand::class)))), $commandLocator->getArguments());
|
||||
$this->assertSame(array('console.command.symfony_component_console_tests_dependencyinjection_namedcommand' => 'with-default-name'), $container->getParameter('console.command.ids'));
|
||||
$this->assertSame(array('with-default-name' => true), $container->getParameter('console.lazy_command.ids'));
|
||||
$this->assertSame(array(), $container->getParameter('console.command.ids'));
|
||||
|
||||
$container = new ContainerBuilder();
|
||||
$container
|
||||
@@ -127,7 +126,7 @@ class AddConsoleCommandPassTest extends TestCase
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
$container->setResourceTracking(false);
|
||||
$container->addCompilerPass(new AddConsoleCommandPass());
|
||||
$container->addCompilerPass(new AddConsoleCommandPass(), PassConfig::TYPE_BEFORE_REMOVING);
|
||||
|
||||
$definition = new Definition('Symfony\Component\Console\Tests\DependencyInjection\MyCommand');
|
||||
$definition->addTag('console.command');
|
||||
@@ -145,7 +144,7 @@ class AddConsoleCommandPassTest extends TestCase
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
$container->setResourceTracking(false);
|
||||
$container->addCompilerPass(new AddConsoleCommandPass());
|
||||
$container->addCompilerPass(new AddConsoleCommandPass(), PassConfig::TYPE_BEFORE_REMOVING);
|
||||
|
||||
$definition = new Definition('SplObjectStorage');
|
||||
$definition->addTag('console.command');
|
||||
@@ -170,10 +169,82 @@ class AddConsoleCommandPassTest extends TestCase
|
||||
|
||||
(new AddConsoleCommandPass())->process($container);
|
||||
|
||||
$alias1 = 'console.command.symfony_component_console_tests_dependencyinjection_mycommand';
|
||||
$alias2 = $alias1.'_my-command2';
|
||||
$this->assertTrue($container->hasAlias($alias1));
|
||||
$this->assertTrue($container->hasAlias($alias2));
|
||||
$aliasPrefix = 'console.command.public_alias.';
|
||||
$this->assertTrue($container->hasAlias($aliasPrefix.'my-command1'));
|
||||
$this->assertTrue($container->hasAlias($aliasPrefix.'my-command2'));
|
||||
}
|
||||
|
||||
public function testProcessOnChildDefinitionWithClass()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
$container->addCompilerPass(new AddConsoleCommandPass(), PassConfig::TYPE_BEFORE_REMOVING);
|
||||
$className = 'Symfony\Component\Console\Tests\DependencyInjection\MyCommand';
|
||||
|
||||
$parentId = 'my-parent-command';
|
||||
$childId = 'my-child-command';
|
||||
|
||||
$parentDefinition = new Definition(/* no class */);
|
||||
$parentDefinition->setAbstract(true)->setPublic(false);
|
||||
|
||||
$childDefinition = new ChildDefinition($parentId);
|
||||
$childDefinition->addTag('console.command')->setPublic(true);
|
||||
$childDefinition->setClass($className);
|
||||
|
||||
$container->setDefinition($parentId, $parentDefinition);
|
||||
$container->setDefinition($childId, $childDefinition);
|
||||
|
||||
$container->compile();
|
||||
$command = $container->get($childId);
|
||||
|
||||
$this->assertInstanceOf($className, $command);
|
||||
}
|
||||
|
||||
public function testProcessOnChildDefinitionWithParentClass()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
$container->addCompilerPass(new AddConsoleCommandPass(), PassConfig::TYPE_BEFORE_REMOVING);
|
||||
$className = 'Symfony\Component\Console\Tests\DependencyInjection\MyCommand';
|
||||
|
||||
$parentId = 'my-parent-command';
|
||||
$childId = 'my-child-command';
|
||||
|
||||
$parentDefinition = new Definition($className);
|
||||
$parentDefinition->setAbstract(true)->setPublic(false);
|
||||
|
||||
$childDefinition = new ChildDefinition($parentId);
|
||||
$childDefinition->addTag('console.command')->setPublic(true);
|
||||
|
||||
$container->setDefinition($parentId, $parentDefinition);
|
||||
$container->setDefinition($childId, $childDefinition);
|
||||
|
||||
$container->compile();
|
||||
$command = $container->get($childId);
|
||||
|
||||
$this->assertInstanceOf($className, $command);
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \RuntimeException
|
||||
* @expectedExceptionMessage The definition for "my-child-command" has no class.
|
||||
*/
|
||||
public function testProcessOnChildDefinitionWithoutClass()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
$container->addCompilerPass(new AddConsoleCommandPass(), PassConfig::TYPE_BEFORE_REMOVING);
|
||||
|
||||
$parentId = 'my-parent-command';
|
||||
$childId = 'my-child-command';
|
||||
|
||||
$parentDefinition = new Definition();
|
||||
$parentDefinition->setAbstract(true)->setPublic(false);
|
||||
|
||||
$childDefinition = new ChildDefinition($parentId);
|
||||
$childDefinition->addTag('console.command')->setPublic(true);
|
||||
|
||||
$container->setDefinition($parentId, $parentDefinition);
|
||||
$container->setDefinition($childId, $childDefinition);
|
||||
|
||||
$container->compile();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -20,8 +20,8 @@ use Symfony\Component\Console\EventListener\ErrorListener;
|
||||
use Symfony\Component\Console\Input\ArgvInput;
|
||||
use Symfony\Component\Console\Input\ArrayInput;
|
||||
use Symfony\Component\Console\Input\Input;
|
||||
use Symfony\Component\Console\Input\StringInput;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Input\StringInput;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
|
||||
class ErrorListenerTest extends TestCase
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
<?php
|
||||
|
||||
|
||||
use Symfony\Component\Console\Command\Command;
|
||||
|
||||
class Foo6Command extends Command
|
||||
|
||||
21
vendor/symfony/console/Tests/Fixtures/FooWithoutAliasCommand.php
vendored
Normal file
21
vendor/symfony/console/Tests/Fixtures/FooWithoutAliasCommand.php
vendored
Normal file
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
use Symfony\Component\Console\Command\Command;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
|
||||
class FooWithoutAliasCommand extends Command
|
||||
{
|
||||
protected function configure()
|
||||
{
|
||||
$this
|
||||
->setName('foo')
|
||||
->setDescription('The foo command')
|
||||
;
|
||||
}
|
||||
|
||||
protected function execute(InputInterface $input, OutputInterface $output)
|
||||
{
|
||||
$output->writeln('called');
|
||||
}
|
||||
}
|
||||
34
vendor/symfony/console/Tests/Fixtures/Style/SymfonyStyle/command/command_4_with_iterators.php
vendored
Normal file
34
vendor/symfony/console/Tests/Fixtures/Style/SymfonyStyle/command/command_4_with_iterators.php
vendored
Normal file
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
use Symfony\Component\Console\Style\SymfonyStyle;
|
||||
|
||||
//Ensure has single blank line after any text and a title
|
||||
return function (InputInterface $input, OutputInterface $output) {
|
||||
$output = new SymfonyStyle($input, $output);
|
||||
|
||||
$output->write('Lorem ipsum dolor sit amet');
|
||||
$output->title('First title');
|
||||
|
||||
$output->writeln('Lorem ipsum dolor sit amet');
|
||||
$output->title('Second title');
|
||||
|
||||
$output->write('Lorem ipsum dolor sit amet');
|
||||
$output->write('');
|
||||
$output->title('Third title');
|
||||
|
||||
//Ensure edge case by appending empty strings to history:
|
||||
$output->write('Lorem ipsum dolor sit amet');
|
||||
$output->write(new \ArrayIterator(array('', '', '')));
|
||||
$output->title('Fourth title');
|
||||
|
||||
//Ensure have manual control over number of blank lines:
|
||||
$output->writeln('Lorem ipsum dolor sit amet');
|
||||
$output->writeln(new \ArrayIterator(array('', ''))); //Should append an extra blank line
|
||||
$output->title('Fifth title');
|
||||
|
||||
$output->writeln('Lorem ipsum dolor sit amet');
|
||||
$output->newLine(2); //Should append an extra blank line
|
||||
$output->title('Fifth title');
|
||||
};
|
||||
@@ -1,9 +1,9 @@
|
||||
<?php
|
||||
|
||||
use Symfony\Component\Console\Helper\TableCell;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
use Symfony\Component\Console\Style\SymfonyStyle;
|
||||
use Symfony\Component\Console\Helper\TableCell;
|
||||
|
||||
//Ensure formatting tables when using multiple headers with TableCell
|
||||
return function (InputInterface $input, OutputInterface $output) {
|
||||
|
||||
32
vendor/symfony/console/Tests/Fixtures/Style/SymfonyStyle/output/output_4_with_iterators.txt
vendored
Normal file
32
vendor/symfony/console/Tests/Fixtures/Style/SymfonyStyle/output/output_4_with_iterators.txt
vendored
Normal file
@@ -0,0 +1,32 @@
|
||||
Lorem ipsum dolor sit amet
|
||||
|
||||
First title
|
||||
===========
|
||||
|
||||
Lorem ipsum dolor sit amet
|
||||
|
||||
Second title
|
||||
============
|
||||
|
||||
Lorem ipsum dolor sit amet
|
||||
|
||||
Third title
|
||||
===========
|
||||
|
||||
Lorem ipsum dolor sit amet
|
||||
|
||||
Fourth title
|
||||
============
|
||||
|
||||
Lorem ipsum dolor sit amet
|
||||
|
||||
|
||||
Fifth title
|
||||
===========
|
||||
|
||||
Lorem ipsum dolor sit amet
|
||||
|
||||
|
||||
Fifth title
|
||||
===========
|
||||
|
||||
@@ -1,3 +1,6 @@
|
||||
Description:
|
||||
Lists commands
|
||||
|
||||
Usage:
|
||||
list [options] [--] [<namespace>]
|
||||
|
||||
|
||||
@@ -1,3 +1,6 @@
|
||||
Description:
|
||||
Lists commands
|
||||
|
||||
Usage:
|
||||
list [options] [--] [<namespace>]
|
||||
|
||||
|
||||
@@ -1,3 +1,6 @@
|
||||
<comment>Description:</comment>
|
||||
command 1 description
|
||||
|
||||
<comment>Usage:</comment>
|
||||
descriptor:command1
|
||||
alias1
|
||||
|
||||
@@ -1,3 +1,6 @@
|
||||
<comment>Description:</comment>
|
||||
command 2 description
|
||||
|
||||
<comment>Usage:</comment>
|
||||
descriptor:command2 [options] [--] \<argument_name>
|
||||
descriptor:command2 -o|--option_name \<argument_name>
|
||||
|
||||
@@ -1,3 +1,6 @@
|
||||
<comment>Description:</comment>
|
||||
command åèä description
|
||||
|
||||
<comment>Usage:</comment>
|
||||
descriptor:åèä [options] [--] \<argument_åèä>
|
||||
descriptor:åèä -o|--option_name \<argument_name>
|
||||
|
||||
@@ -12,8 +12,8 @@
|
||||
namespace Symfony\Component\Console\Tests\Formatter;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Component\Console\Formatter\OutputFormatterStyleStack;
|
||||
use Symfony\Component\Console\Formatter\OutputFormatterStyle;
|
||||
use Symfony\Component\Console\Formatter\OutputFormatterStyleStack;
|
||||
|
||||
class OutputFormatterStyleStackTest extends TestCase
|
||||
{
|
||||
|
||||
@@ -196,17 +196,6 @@ class OutputFormatterTest extends TestCase
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @group legacy
|
||||
* @dataProvider provideInlineStyleTagsWithUnknownOptions
|
||||
* @expectedDeprecation Unknown style options are deprecated since Symfony 3.2 and will be removed in 4.0. Exception "Invalid option specified: "%s". Expected one of (bold, underscore, blink, reverse, conceal)".
|
||||
*/
|
||||
public function testInlineStyleOptionsUnknownAreDeprecated($tag, $option)
|
||||
{
|
||||
$formatter = new OutputFormatter(true);
|
||||
$formatter->format($tag);
|
||||
}
|
||||
|
||||
public function provideInlineStyleTagsWithUnknownOptions()
|
||||
{
|
||||
return array(
|
||||
|
||||
@@ -12,8 +12,8 @@
|
||||
namespace Symfony\Component\Console\Tests\Helper;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Component\Console\Helper\HelperSet;
|
||||
use Symfony\Component\Console\Command\Command;
|
||||
use Symfony\Component\Console\Helper\HelperSet;
|
||||
|
||||
class HelperSetTest extends TestCase
|
||||
{
|
||||
|
||||
@@ -14,8 +14,8 @@ namespace Symfony\Component\Console\Tests\Helper;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Component\Console\Helper\DebugFormatterHelper;
|
||||
use Symfony\Component\Console\Helper\HelperSet;
|
||||
use Symfony\Component\Console\Output\StreamOutput;
|
||||
use Symfony\Component\Console\Helper\ProcessHelper;
|
||||
use Symfony\Component\Console\Output\StreamOutput;
|
||||
use Symfony\Component\Process\Process;
|
||||
|
||||
class ProcessHelperTest extends TestCase
|
||||
|
||||
@@ -12,8 +12,10 @@
|
||||
namespace Symfony\Component\Console\Tests\Helper;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Component\Console\Helper\ProgressBar;
|
||||
use Symfony\Component\Console\Formatter\OutputFormatter;
|
||||
use Symfony\Component\Console\Helper\Helper;
|
||||
use Symfony\Component\Console\Helper\ProgressBar;
|
||||
use Symfony\Component\Console\Output\ConsoleSectionOutput;
|
||||
use Symfony\Component\Console\Output\StreamOutput;
|
||||
|
||||
/**
|
||||
@@ -310,6 +312,88 @@ class ProgressBarTest extends TestCase
|
||||
);
|
||||
}
|
||||
|
||||
public function testOverwriteWithSectionOutput()
|
||||
{
|
||||
$sections = array();
|
||||
$stream = $this->getOutputStream(true);
|
||||
$output = new ConsoleSectionOutput($stream->getStream(), $sections, $stream->getVerbosity(), $stream->isDecorated(), new OutputFormatter());
|
||||
|
||||
$bar = new ProgressBar($output, 50);
|
||||
$bar->start();
|
||||
$bar->display();
|
||||
$bar->advance();
|
||||
$bar->advance();
|
||||
|
||||
rewind($output->getStream());
|
||||
$this->assertEquals(
|
||||
' 0/50 [>---------------------------] 0%'.PHP_EOL.
|
||||
"\x1b[1A\x1b[0J".' 0/50 [>---------------------------] 0%'.PHP_EOL.
|
||||
"\x1b[1A\x1b[0J".' 1/50 [>---------------------------] 2%'.PHP_EOL.
|
||||
"\x1b[1A\x1b[0J".' 2/50 [=>--------------------------] 4%'.PHP_EOL,
|
||||
stream_get_contents($output->getStream())
|
||||
);
|
||||
}
|
||||
|
||||
public function testOverwriteMultipleProgressBarsWithSectionOutputs()
|
||||
{
|
||||
$sections = array();
|
||||
$stream = $this->getOutputStream(true);
|
||||
$output1 = new ConsoleSectionOutput($stream->getStream(), $sections, $stream->getVerbosity(), $stream->isDecorated(), new OutputFormatter());
|
||||
$output2 = new ConsoleSectionOutput($stream->getStream(), $sections, $stream->getVerbosity(), $stream->isDecorated(), new OutputFormatter());
|
||||
|
||||
$progress = new ProgressBar($output1, 50);
|
||||
$progress2 = new ProgressBar($output2, 50);
|
||||
|
||||
$progress->start();
|
||||
$progress2->start();
|
||||
|
||||
$progress2->advance();
|
||||
$progress->advance();
|
||||
|
||||
rewind($stream->getStream());
|
||||
|
||||
$this->assertEquals(
|
||||
' 0/50 [>---------------------------] 0%'.PHP_EOL.
|
||||
' 0/50 [>---------------------------] 0%'.PHP_EOL.
|
||||
"\x1b[1A\x1b[0J".' 1/50 [>---------------------------] 2%'.PHP_EOL.
|
||||
"\x1b[2A\x1b[0J".' 1/50 [>---------------------------] 2%'.PHP_EOL.
|
||||
"\x1b[1A\x1b[0J".' 1/50 [>---------------------------] 2%'.PHP_EOL.
|
||||
' 1/50 [>---------------------------] 2%'.PHP_EOL,
|
||||
stream_get_contents($stream->getStream())
|
||||
);
|
||||
}
|
||||
|
||||
public function testMultipleSectionsWithCustomFormat()
|
||||
{
|
||||
$sections = array();
|
||||
$stream = $this->getOutputStream(true);
|
||||
$output1 = new ConsoleSectionOutput($stream->getStream(), $sections, $stream->getVerbosity(), $stream->isDecorated(), new OutputFormatter());
|
||||
$output2 = new ConsoleSectionOutput($stream->getStream(), $sections, $stream->getVerbosity(), $stream->isDecorated(), new OutputFormatter());
|
||||
|
||||
ProgressBar::setFormatDefinition('test', '%current%/%max% [%bar%] %percent:3s%% Fruitcake marzipan toffee. Cupcake gummi bears tart dessert ice cream chupa chups cupcake chocolate bar sesame snaps. Croissant halvah cookie jujubes powder macaroon. Fruitcake bear claw bonbon jelly beans oat cake pie muffin Fruitcake marzipan toffee.');
|
||||
|
||||
$progress = new ProgressBar($output1, 50);
|
||||
$progress2 = new ProgressBar($output2, 50);
|
||||
$progress2->setFormat('test');
|
||||
|
||||
$progress->start();
|
||||
$progress2->start();
|
||||
|
||||
$progress->advance();
|
||||
$progress2->advance();
|
||||
|
||||
rewind($stream->getStream());
|
||||
|
||||
$this->assertEquals(' 0/50 [>---------------------------] 0%'.PHP_EOL.
|
||||
' 0/50 [>] 0% Fruitcake marzipan toffee. Cupcake gummi bears tart dessert ice cream chupa chups cupcake chocolate bar sesame snaps. Croissant halvah cookie jujubes powder macaroon. Fruitcake bear claw bonbon jelly beans oat cake pie muffin Fruitcake marzipan toffee.'.PHP_EOL.
|
||||
"\x1b[4A\x1b[0J".' 0/50 [>] 0% Fruitcake marzipan toffee. Cupcake gummi bears tart dessert ice cream chupa chups cupcake chocolate bar sesame snaps. Croissant halvah cookie jujubes powder macaroon. Fruitcake bear claw bonbon jelly beans oat cake pie muffin Fruitcake marzipan toffee.'.PHP_EOL.
|
||||
"\x1b[3A\x1b[0J".' 1/50 [>---------------------------] 2%'.PHP_EOL.
|
||||
' 0/50 [>] 0% Fruitcake marzipan toffee. Cupcake gummi bears tart dessert ice cream chupa chups cupcake chocolate bar sesame snaps. Croissant halvah cookie jujubes powder macaroon. Fruitcake bear claw bonbon jelly beans oat cake pie muffin Fruitcake marzipan toffee.'.PHP_EOL.
|
||||
"\x1b[3A\x1b[0J".' 1/50 [>] 2% Fruitcake marzipan toffee. Cupcake gummi bears tart dessert ice cream chupa chups cupcake chocolate bar sesame snaps. Croissant halvah cookie jujubes powder macaroon. Fruitcake bear claw bonbon jelly beans oat cake pie muffin Fruitcake marzipan toffee.'.PHP_EOL,
|
||||
stream_get_contents($stream->getStream())
|
||||
);
|
||||
}
|
||||
|
||||
public function testStartWithMax()
|
||||
{
|
||||
$bar = new ProgressBar($output = $this->getOutputStream());
|
||||
@@ -592,6 +676,29 @@ class ProgressBarTest extends TestCase
|
||||
);
|
||||
}
|
||||
|
||||
public function testSettingMaxStepsDuringProgressing()
|
||||
{
|
||||
$output = $this->getOutputStream();
|
||||
$bar = new ProgressBar($output);
|
||||
$bar->start();
|
||||
$bar->setProgress(2);
|
||||
$bar->setMaxSteps(10);
|
||||
$bar->setProgress(5);
|
||||
$bar->setMaxSteps(100);
|
||||
$bar->setProgress(10);
|
||||
$bar->finish();
|
||||
|
||||
rewind($output->getStream());
|
||||
$this->assertEquals(
|
||||
rtrim(' 0 [>---------------------------]').
|
||||
rtrim($this->generateOutput(' 2 [-->-------------------------]')).
|
||||
rtrim($this->generateOutput(' 5/10 [==============>-------------] 50%')).
|
||||
rtrim($this->generateOutput(' 10/100 [==>-------------------------] 10%')).
|
||||
rtrim($this->generateOutput(' 100/100 [============================] 100%')),
|
||||
stream_get_contents($output->getStream())
|
||||
);
|
||||
}
|
||||
|
||||
public function testWithSmallScreen()
|
||||
{
|
||||
$output = $this->getOutputStream();
|
||||
|
||||
@@ -12,9 +12,9 @@
|
||||
namespace Symfony\Component\Console\Tests\Helper;
|
||||
|
||||
use Symfony\Component\Console\Formatter\OutputFormatter;
|
||||
use Symfony\Component\Console\Helper\QuestionHelper;
|
||||
use Symfony\Component\Console\Helper\HelperSet;
|
||||
use Symfony\Component\Console\Helper\FormatterHelper;
|
||||
use Symfony\Component\Console\Helper\HelperSet;
|
||||
use Symfony\Component\Console\Helper\QuestionHelper;
|
||||
use Symfony\Component\Console\Output\StreamOutput;
|
||||
use Symfony\Component\Console\Question\ChoiceQuestion;
|
||||
use Symfony\Component\Console\Question\ConfirmationQuestion;
|
||||
@@ -221,7 +221,7 @@ class QuestionHelperTest extends AbstractQuestionHelperTest
|
||||
|
||||
public function testAskHiddenResponse()
|
||||
{
|
||||
if ('\\' === DIRECTORY_SEPARATOR) {
|
||||
if ('\\' === \DIRECTORY_SEPARATOR) {
|
||||
$this->markTestSkipped('This test is not supported on Windows');
|
||||
}
|
||||
|
||||
@@ -276,7 +276,7 @@ class QuestionHelperTest extends AbstractQuestionHelperTest
|
||||
|
||||
$error = 'This is not a color!';
|
||||
$validator = function ($color) use ($error) {
|
||||
if (!in_array($color, array('white', 'black'))) {
|
||||
if (!\in_array($color, array('white', 'black'))) {
|
||||
throw new \InvalidArgumentException($error);
|
||||
}
|
||||
|
||||
@@ -490,357 +490,6 @@ class QuestionHelperTest extends AbstractQuestionHelperTest
|
||||
$dialog->ask($this->createStreamableInputInterfaceMock($this->getInputStream("\n")), $output, $question);
|
||||
}
|
||||
|
||||
/**
|
||||
* @group legacy
|
||||
*/
|
||||
public function testLegacyAskChoice()
|
||||
{
|
||||
$questionHelper = new QuestionHelper();
|
||||
|
||||
$helperSet = new HelperSet(array(new FormatterHelper()));
|
||||
$questionHelper->setHelperSet($helperSet);
|
||||
|
||||
$heroes = array('Superman', 'Batman', 'Spiderman');
|
||||
|
||||
$questionHelper->setInputStream($this->getInputStream("\n1\n 1 \nFabien\n1\nFabien\n1\n0,2\n 0 , 2 \n\n\n"));
|
||||
|
||||
$question = new ChoiceQuestion('What is your favorite superhero?', $heroes, '2');
|
||||
$question->setMaxAttempts(1);
|
||||
// first answer is an empty answer, we're supposed to receive the default value
|
||||
$this->assertEquals('Spiderman', $questionHelper->ask($this->createInputInterfaceMock(), $this->createOutputInterface(), $question));
|
||||
|
||||
$question = new ChoiceQuestion('What is your favorite superhero?', $heroes);
|
||||
$question->setMaxAttempts(1);
|
||||
$this->assertEquals('Batman', $questionHelper->ask($this->createInputInterfaceMock(), $this->createOutputInterface(), $question));
|
||||
$this->assertEquals('Batman', $questionHelper->ask($this->createInputInterfaceMock(), $this->createOutputInterface(), $question));
|
||||
|
||||
$question = new ChoiceQuestion('What is your favorite superhero?', $heroes);
|
||||
$question->setErrorMessage('Input "%s" is not a superhero!');
|
||||
$question->setMaxAttempts(2);
|
||||
$this->assertEquals('Batman', $questionHelper->ask($this->createInputInterfaceMock(), $output = $this->createOutputInterface(), $question));
|
||||
|
||||
rewind($output->getStream());
|
||||
$stream = stream_get_contents($output->getStream());
|
||||
$this->assertContains('Input "Fabien" is not a superhero!', $stream);
|
||||
|
||||
try {
|
||||
$question = new ChoiceQuestion('What is your favorite superhero?', $heroes, '1');
|
||||
$question->setMaxAttempts(1);
|
||||
$questionHelper->ask($this->createInputInterfaceMock(), $output = $this->createOutputInterface(), $question);
|
||||
$this->fail();
|
||||
} catch (\InvalidArgumentException $e) {
|
||||
$this->assertEquals('Value "Fabien" is invalid', $e->getMessage());
|
||||
}
|
||||
|
||||
$question = new ChoiceQuestion('What is your favorite superhero?', $heroes, null);
|
||||
$question->setMaxAttempts(1);
|
||||
$question->setMultiselect(true);
|
||||
|
||||
$this->assertEquals(array('Batman'), $questionHelper->ask($this->createInputInterfaceMock(), $this->createOutputInterface(), $question));
|
||||
$this->assertEquals(array('Superman', 'Spiderman'), $questionHelper->ask($this->createInputInterfaceMock(), $this->createOutputInterface(), $question));
|
||||
$this->assertEquals(array('Superman', 'Spiderman'), $questionHelper->ask($this->createInputInterfaceMock(), $this->createOutputInterface(), $question));
|
||||
|
||||
$question = new ChoiceQuestion('What is your favorite superhero?', $heroes, '0,1');
|
||||
$question->setMaxAttempts(1);
|
||||
$question->setMultiselect(true);
|
||||
|
||||
$this->assertEquals(array('Superman', 'Batman'), $questionHelper->ask($this->createInputInterfaceMock(), $this->createOutputInterface(), $question));
|
||||
|
||||
$question = new ChoiceQuestion('What is your favorite superhero?', $heroes, ' 0 , 1 ');
|
||||
$question->setMaxAttempts(1);
|
||||
$question->setMultiselect(true);
|
||||
|
||||
$this->assertEquals(array('Superman', 'Batman'), $questionHelper->ask($this->createInputInterfaceMock(), $this->createOutputInterface(), $question));
|
||||
}
|
||||
|
||||
/**
|
||||
* @group legacy
|
||||
*/
|
||||
public function testLegacyAsk()
|
||||
{
|
||||
$dialog = new QuestionHelper();
|
||||
|
||||
$dialog->setInputStream($this->getInputStream("\n8AM\n"));
|
||||
|
||||
$question = new Question('What time is it?', '2PM');
|
||||
$this->assertEquals('2PM', $dialog->ask($this->createInputInterfaceMock(), $this->createOutputInterface(), $question));
|
||||
|
||||
$question = new Question('What time is it?', '2PM');
|
||||
$this->assertEquals('8AM', $dialog->ask($this->createInputInterfaceMock(), $output = $this->createOutputInterface(), $question));
|
||||
|
||||
rewind($output->getStream());
|
||||
$this->assertEquals('What time is it?', stream_get_contents($output->getStream()));
|
||||
}
|
||||
|
||||
/**
|
||||
* @group legacy
|
||||
*/
|
||||
public function testLegacyAskWithAutocomplete()
|
||||
{
|
||||
if (!$this->hasSttyAvailable()) {
|
||||
$this->markTestSkipped('`stty` is required to test autocomplete functionality');
|
||||
}
|
||||
|
||||
// Acm<NEWLINE>
|
||||
// Ac<BACKSPACE><BACKSPACE>s<TAB>Test<NEWLINE>
|
||||
// <NEWLINE>
|
||||
// <UP ARROW><UP ARROW><NEWLINE>
|
||||
// <UP ARROW><UP ARROW><UP ARROW><UP ARROW><UP ARROW><TAB>Test<NEWLINE>
|
||||
// <DOWN ARROW><NEWLINE>
|
||||
// S<BACKSPACE><BACKSPACE><DOWN ARROW><DOWN ARROW><NEWLINE>
|
||||
// F00<BACKSPACE><BACKSPACE>oo<TAB><NEWLINE>
|
||||
$inputStream = $this->getInputStream("Acm\nAc\177\177s\tTest\n\n\033[A\033[A\n\033[A\033[A\033[A\033[A\033[A\tTest\n\033[B\nS\177\177\033[B\033[B\nF00\177\177oo\t\n");
|
||||
|
||||
$dialog = new QuestionHelper();
|
||||
$dialog->setInputStream($inputStream);
|
||||
$helperSet = new HelperSet(array(new FormatterHelper()));
|
||||
$dialog->setHelperSet($helperSet);
|
||||
|
||||
$question = new Question('Please select a bundle', 'FrameworkBundle');
|
||||
$question->setAutocompleterValues(array('AcmeDemoBundle', 'AsseticBundle', 'SecurityBundle', 'FooBundle'));
|
||||
|
||||
$this->assertEquals('AcmeDemoBundle', $dialog->ask($this->createInputInterfaceMock(), $this->createOutputInterface(), $question));
|
||||
$this->assertEquals('AsseticBundleTest', $dialog->ask($this->createInputInterfaceMock(), $this->createOutputInterface(), $question));
|
||||
$this->assertEquals('FrameworkBundle', $dialog->ask($this->createInputInterfaceMock(), $this->createOutputInterface(), $question));
|
||||
$this->assertEquals('SecurityBundle', $dialog->ask($this->createInputInterfaceMock(), $this->createOutputInterface(), $question));
|
||||
$this->assertEquals('FooBundleTest', $dialog->ask($this->createInputInterfaceMock(), $this->createOutputInterface(), $question));
|
||||
$this->assertEquals('AcmeDemoBundle', $dialog->ask($this->createInputInterfaceMock(), $this->createOutputInterface(), $question));
|
||||
$this->assertEquals('AsseticBundle', $dialog->ask($this->createInputInterfaceMock(), $this->createOutputInterface(), $question));
|
||||
$this->assertEquals('FooBundle', $dialog->ask($this->createInputInterfaceMock(), $this->createOutputInterface(), $question));
|
||||
}
|
||||
|
||||
/**
|
||||
* @group legacy
|
||||
*/
|
||||
public function testLegacyAskWithAutocompleteWithNonSequentialKeys()
|
||||
{
|
||||
if (!$this->hasSttyAvailable()) {
|
||||
$this->markTestSkipped('`stty` is required to test autocomplete functionality');
|
||||
}
|
||||
|
||||
// <UP ARROW><UP ARROW><NEWLINE><DOWN ARROW><DOWN ARROW><NEWLINE>
|
||||
$inputStream = $this->getInputStream("\033[A\033[A\n\033[B\033[B\n");
|
||||
|
||||
$dialog = new QuestionHelper();
|
||||
$dialog->setInputStream($inputStream);
|
||||
$dialog->setHelperSet(new HelperSet(array(new FormatterHelper())));
|
||||
|
||||
$question = new ChoiceQuestion('Please select a bundle', array(1 => 'AcmeDemoBundle', 4 => 'AsseticBundle'));
|
||||
$question->setMaxAttempts(1);
|
||||
|
||||
$this->assertEquals('AcmeDemoBundle', $dialog->ask($this->createInputInterfaceMock(), $this->createOutputInterface(), $question));
|
||||
$this->assertEquals('AsseticBundle', $dialog->ask($this->createInputInterfaceMock(), $this->createOutputInterface(), $question));
|
||||
}
|
||||
|
||||
/**
|
||||
* @group legacy
|
||||
*/
|
||||
public function testLegacyAskHiddenResponse()
|
||||
{
|
||||
if ('\\' === DIRECTORY_SEPARATOR) {
|
||||
$this->markTestSkipped('This test is not supported on Windows');
|
||||
}
|
||||
|
||||
$dialog = new QuestionHelper();
|
||||
$dialog->setInputStream($this->getInputStream("8AM\n"));
|
||||
|
||||
$question = new Question('What time is it?');
|
||||
$question->setHidden(true);
|
||||
|
||||
$this->assertEquals('8AM', $dialog->ask($this->createInputInterfaceMock(), $this->createOutputInterface(), $question));
|
||||
}
|
||||
|
||||
/**
|
||||
* @group legacy
|
||||
* @dataProvider getAskConfirmationData
|
||||
*/
|
||||
public function testLegacyAskConfirmation($question, $expected, $default = true)
|
||||
{
|
||||
$dialog = new QuestionHelper();
|
||||
|
||||
$dialog->setInputStream($this->getInputStream($question."\n"));
|
||||
$question = new ConfirmationQuestion('Do you like French fries?', $default);
|
||||
$this->assertEquals($expected, $dialog->ask($this->createInputInterfaceMock(), $this->createOutputInterface(), $question), 'confirmation question should '.($expected ? 'pass' : 'cancel'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @group legacy
|
||||
*/
|
||||
public function testLegacyAskConfirmationWithCustomTrueAnswer()
|
||||
{
|
||||
$dialog = new QuestionHelper();
|
||||
|
||||
$dialog->setInputStream($this->getInputStream("j\ny\n"));
|
||||
$question = new ConfirmationQuestion('Do you like French fries?', false, '/^(j|y)/i');
|
||||
$this->assertTrue($dialog->ask($this->createInputInterfaceMock(), $this->createOutputInterface(), $question));
|
||||
$question = new ConfirmationQuestion('Do you like French fries?', false, '/^(j|y)/i');
|
||||
$this->assertTrue($dialog->ask($this->createInputInterfaceMock(), $this->createOutputInterface(), $question));
|
||||
}
|
||||
|
||||
/**
|
||||
* @group legacy
|
||||
*/
|
||||
public function testLegacyAskAndValidate()
|
||||
{
|
||||
$dialog = new QuestionHelper();
|
||||
$helperSet = new HelperSet(array(new FormatterHelper()));
|
||||
$dialog->setHelperSet($helperSet);
|
||||
|
||||
$error = 'This is not a color!';
|
||||
$validator = function ($color) use ($error) {
|
||||
if (!in_array($color, array('white', 'black'))) {
|
||||
throw new \InvalidArgumentException($error);
|
||||
}
|
||||
|
||||
return $color;
|
||||
};
|
||||
|
||||
$question = new Question('What color was the white horse of Henry IV?', 'white');
|
||||
$question->setValidator($validator);
|
||||
$question->setMaxAttempts(2);
|
||||
|
||||
$dialog->setInputStream($this->getInputStream("\nblack\n"));
|
||||
$this->assertEquals('white', $dialog->ask($this->createInputInterfaceMock(), $this->createOutputInterface(), $question));
|
||||
$this->assertEquals('black', $dialog->ask($this->createInputInterfaceMock(), $this->createOutputInterface(), $question));
|
||||
|
||||
$dialog->setInputStream($this->getInputStream("green\nyellow\norange\n"));
|
||||
try {
|
||||
$dialog->ask($this->createInputInterfaceMock(), $this->createOutputInterface(), $question);
|
||||
$this->fail();
|
||||
} catch (\InvalidArgumentException $e) {
|
||||
$this->assertEquals($error, $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @group legacy
|
||||
* @dataProvider simpleAnswerProvider
|
||||
*/
|
||||
public function testLegacySelectChoiceFromSimpleChoices($providedAnswer, $expectedValue)
|
||||
{
|
||||
$possibleChoices = array(
|
||||
'My environment 1',
|
||||
'My environment 2',
|
||||
'My environment 3',
|
||||
);
|
||||
|
||||
$dialog = new QuestionHelper();
|
||||
$dialog->setInputStream($this->getInputStream($providedAnswer."\n"));
|
||||
$helperSet = new HelperSet(array(new FormatterHelper()));
|
||||
$dialog->setHelperSet($helperSet);
|
||||
|
||||
$question = new ChoiceQuestion('Please select the environment to load', $possibleChoices);
|
||||
$question->setMaxAttempts(1);
|
||||
$answer = $dialog->ask($this->createInputInterfaceMock(), $this->createOutputInterface(), $question);
|
||||
|
||||
$this->assertSame($expectedValue, $answer);
|
||||
}
|
||||
|
||||
/**
|
||||
* @group legacy
|
||||
* @dataProvider mixedKeysChoiceListAnswerProvider
|
||||
*/
|
||||
public function testLegacyChoiceFromChoicelistWithMixedKeys($providedAnswer, $expectedValue)
|
||||
{
|
||||
$possibleChoices = array(
|
||||
'0' => 'No environment',
|
||||
'1' => 'My environment 1',
|
||||
'env_2' => 'My environment 2',
|
||||
3 => 'My environment 3',
|
||||
);
|
||||
|
||||
$dialog = new QuestionHelper();
|
||||
$dialog->setInputStream($this->getInputStream($providedAnswer."\n"));
|
||||
$helperSet = new HelperSet(array(new FormatterHelper()));
|
||||
$dialog->setHelperSet($helperSet);
|
||||
|
||||
$question = new ChoiceQuestion('Please select the environment to load', $possibleChoices);
|
||||
$question->setMaxAttempts(1);
|
||||
$answer = $dialog->ask($this->createInputInterfaceMock(), $this->createOutputInterface(), $question);
|
||||
|
||||
$this->assertSame($expectedValue, $answer);
|
||||
}
|
||||
|
||||
/**
|
||||
* @group legacy
|
||||
* @dataProvider answerProvider
|
||||
*/
|
||||
public function testLegacySelectChoiceFromChoiceList($providedAnswer, $expectedValue)
|
||||
{
|
||||
$possibleChoices = array(
|
||||
'env_1' => 'My environment 1',
|
||||
'env_2' => 'My environment',
|
||||
'env_3' => 'My environment',
|
||||
);
|
||||
|
||||
$dialog = new QuestionHelper();
|
||||
$dialog->setInputStream($this->getInputStream($providedAnswer."\n"));
|
||||
$helperSet = new HelperSet(array(new FormatterHelper()));
|
||||
$dialog->setHelperSet($helperSet);
|
||||
|
||||
$question = new ChoiceQuestion('Please select the environment to load', $possibleChoices);
|
||||
$question->setMaxAttempts(1);
|
||||
$answer = $dialog->ask($this->createInputInterfaceMock(), $this->createOutputInterface(), $question);
|
||||
|
||||
$this->assertSame($expectedValue, $answer);
|
||||
}
|
||||
|
||||
/**
|
||||
* @group legacy
|
||||
* @expectedException \InvalidArgumentException
|
||||
* @expectedExceptionMessage The provided answer is ambiguous. Value should be one of env_2 or env_3.
|
||||
*/
|
||||
public function testLegacyAmbiguousChoiceFromChoicelist()
|
||||
{
|
||||
$possibleChoices = array(
|
||||
'env_1' => 'My first environment',
|
||||
'env_2' => 'My environment',
|
||||
'env_3' => 'My environment',
|
||||
);
|
||||
|
||||
$dialog = new QuestionHelper();
|
||||
$dialog->setInputStream($this->getInputStream("My environment\n"));
|
||||
$helperSet = new HelperSet(array(new FormatterHelper()));
|
||||
$dialog->setHelperSet($helperSet);
|
||||
|
||||
$question = new ChoiceQuestion('Please select the environment to load', $possibleChoices);
|
||||
$question->setMaxAttempts(1);
|
||||
|
||||
$dialog->ask($this->createInputInterfaceMock(), $this->createOutputInterface(), $question);
|
||||
}
|
||||
|
||||
/**
|
||||
* @requires function mb_strwidth
|
||||
* @group legacy
|
||||
*/
|
||||
public function testLegacyChoiceOutputFormattingQuestionForUtf8Keys()
|
||||
{
|
||||
$question = 'Lorem ipsum?';
|
||||
$possibleChoices = array(
|
||||
'foo' => 'foo',
|
||||
'żółw' => 'bar',
|
||||
'łabądź' => 'baz',
|
||||
);
|
||||
$outputShown = array(
|
||||
$question,
|
||||
' [<info>foo </info>] foo',
|
||||
' [<info>żółw </info>] bar',
|
||||
' [<info>łabądź</info>] baz',
|
||||
);
|
||||
$output = $this->getMockBuilder('\Symfony\Component\Console\Output\OutputInterface')->getMock();
|
||||
$output->method('getFormatter')->willReturn(new OutputFormatter());
|
||||
|
||||
$dialog = new QuestionHelper();
|
||||
$dialog->setInputStream($this->getInputStream("\n"));
|
||||
$helperSet = new HelperSet(array(new FormatterHelper()));
|
||||
$dialog->setHelperSet($helperSet);
|
||||
|
||||
$output->expects($this->once())->method('writeln')->with($this->equalTo($outputShown));
|
||||
|
||||
$question = new ChoiceQuestion($question, $possibleChoices, 'foo');
|
||||
$dialog->ask($this->createInputInterfaceMock(), $output, $question);
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \Symfony\Component\Console\Exception\RuntimeException
|
||||
* @expectedExceptionMessage Aborted
|
||||
|
||||
@@ -6,8 +6,8 @@ use Symfony\Component\Console\Helper\FormatterHelper;
|
||||
use Symfony\Component\Console\Helper\HelperSet;
|
||||
use Symfony\Component\Console\Helper\SymfonyQuestionHelper;
|
||||
use Symfony\Component\Console\Output\StreamOutput;
|
||||
use Symfony\Component\Console\Question\Question;
|
||||
use Symfony\Component\Console\Question\ChoiceQuestion;
|
||||
use Symfony\Component\Console\Question\Question;
|
||||
|
||||
/**
|
||||
* @group tty
|
||||
@@ -74,6 +74,18 @@ class SymfonyQuestionHelperTest extends AbstractQuestionHelperTest
|
||||
$this->assertOutputContains('What is your favorite superhero? [Superman, Batman]', $output);
|
||||
}
|
||||
|
||||
public function testAskChoiceWithChoiceValueAsDefault()
|
||||
{
|
||||
$questionHelper = new SymfonyQuestionHelper();
|
||||
$helperSet = new HelperSet(array(new FormatterHelper()));
|
||||
$questionHelper->setHelperSet($helperSet);
|
||||
$question = new ChoiceQuestion('What is your favorite superhero?', array('Superman', 'Batman', 'Spiderman'), 'Batman');
|
||||
$question->setMaxAttempts(1);
|
||||
|
||||
$this->assertSame('Batman', $questionHelper->ask($this->createStreamableInputInterfaceMock($this->getInputStream("Batman\n")), $output = $this->createOutputInterface(), $question));
|
||||
$this->assertOutputContains('What is your favorite superhero? [Batman]', $output);
|
||||
}
|
||||
|
||||
public function testAskReturnsNullIfValidatorAllowsIt()
|
||||
{
|
||||
$questionHelper = new SymfonyQuestionHelper();
|
||||
|
||||
200
vendor/symfony/console/Tests/Helper/TableTest.php
vendored
200
vendor/symfony/console/Tests/Helper/TableTest.php
vendored
@@ -12,10 +12,12 @@
|
||||
namespace Symfony\Component\Console\Tests\Helper;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Component\Console\Formatter\OutputFormatter;
|
||||
use Symfony\Component\Console\Helper\Table;
|
||||
use Symfony\Component\Console\Helper\TableStyle;
|
||||
use Symfony\Component\Console\Helper\TableSeparator;
|
||||
use Symfony\Component\Console\Helper\TableCell;
|
||||
use Symfony\Component\Console\Helper\TableSeparator;
|
||||
use Symfony\Component\Console\Helper\TableStyle;
|
||||
use Symfony\Component\Console\Output\ConsoleSectionOutput;
|
||||
use Symfony\Component\Console\Output\StreamOutput;
|
||||
|
||||
class TableTest extends TestCase
|
||||
@@ -136,6 +138,45 @@ TABLE
|
||||
80-902734-1-6 And Then There Were None Agatha Christie
|
||||
=============== ========================== ==================
|
||||
|
||||
TABLE
|
||||
),
|
||||
array(
|
||||
array('ISBN', 'Title', 'Author'),
|
||||
$books,
|
||||
'box',
|
||||
<<<'TABLE'
|
||||
┌───────────────┬──────────────────────────┬──────────────────┐
|
||||
│ ISBN │ Title │ Author │
|
||||
├───────────────┼──────────────────────────┼──────────────────┤
|
||||
│ 99921-58-10-7 │ Divine Comedy │ Dante Alighieri │
|
||||
│ 9971-5-0210-0 │ A Tale of Two Cities │ Charles Dickens │
|
||||
│ 960-425-059-0 │ The Lord of the Rings │ J. R. R. Tolkien │
|
||||
│ 80-902734-1-6 │ And Then There Were None │ Agatha Christie │
|
||||
└───────────────┴──────────────────────────┴──────────────────┘
|
||||
|
||||
TABLE
|
||||
),
|
||||
array(
|
||||
array('ISBN', 'Title', 'Author'),
|
||||
array(
|
||||
array('99921-58-10-7', 'Divine Comedy', 'Dante Alighieri'),
|
||||
array('9971-5-0210-0', 'A Tale of Two Cities', 'Charles Dickens'),
|
||||
new TableSeparator(),
|
||||
array('960-425-059-0', 'The Lord of the Rings', 'J. R. R. Tolkien'),
|
||||
array('80-902734-1-6', 'And Then There Were None', 'Agatha Christie'),
|
||||
),
|
||||
'box-double',
|
||||
<<<'TABLE'
|
||||
╔═══════════════╤══════════════════════════╤══════════════════╗
|
||||
║ ISBN │ Title │ Author ║
|
||||
╠═══════════════╪══════════════════════════╪══════════════════╣
|
||||
║ 99921-58-10-7 │ Divine Comedy │ Dante Alighieri ║
|
||||
║ 9971-5-0210-0 │ A Tale of Two Cities │ Charles Dickens ║
|
||||
╟───────────────┼──────────────────────────┼──────────────────╢
|
||||
║ 960-425-059-0 │ The Lord of the Rings │ J. R. R. Tolkien ║
|
||||
║ 80-902734-1-6 │ And Then There Were None │ Agatha Christie ║
|
||||
╚═══════════════╧══════════════════════════╧══════════════════╝
|
||||
|
||||
TABLE
|
||||
),
|
||||
array(
|
||||
@@ -610,9 +651,9 @@ TABLE;
|
||||
{
|
||||
$style = new TableStyle();
|
||||
$style
|
||||
->setHorizontalBorderChar('.')
|
||||
->setVerticalBorderChar('.')
|
||||
->setCrossingChar('.')
|
||||
->setHorizontalBorderChars('.')
|
||||
->setVerticalBorderChars('.')
|
||||
->setDefaultCrossingChar('.')
|
||||
;
|
||||
|
||||
Table::setStyleDefinition('dotfull', $style);
|
||||
@@ -742,7 +783,7 @@ TABLE;
|
||||
$table->render();
|
||||
}
|
||||
|
||||
public function testColumnWith()
|
||||
public function testColumnWidth()
|
||||
{
|
||||
$table = new Table($output = $this->getOutputStream());
|
||||
$table
|
||||
@@ -774,7 +815,7 @@ TABLE;
|
||||
$this->assertEquals($expected, $this->getOutputContent($output));
|
||||
}
|
||||
|
||||
public function testColumnWiths()
|
||||
public function testColumnWidths()
|
||||
{
|
||||
$table = new Table($output = $this->getOutputStream());
|
||||
$table
|
||||
@@ -805,6 +846,115 @@ TABLE;
|
||||
$this->assertEquals($expected, $this->getOutputContent($output));
|
||||
}
|
||||
|
||||
public function testSectionOutput()
|
||||
{
|
||||
$sections = array();
|
||||
$stream = $this->getOutputStream(true);
|
||||
$output = new ConsoleSectionOutput($stream->getStream(), $sections, $stream->getVerbosity(), $stream->isDecorated(), new OutputFormatter());
|
||||
$table = new Table($output);
|
||||
$table
|
||||
->setHeaders(array('ISBN', 'Title', 'Author', 'Price'))
|
||||
->setRows(array(
|
||||
array('99921-58-10-7', 'Divine Comedy', 'Dante Alighieri', '9.95'),
|
||||
));
|
||||
|
||||
$table->render();
|
||||
|
||||
$table->appendRow(array('9971-5-0210-0', 'A Tale of Two Cities', 'Charles Dickens', '139.25'));
|
||||
|
||||
$expected =
|
||||
<<<TABLE
|
||||
+---------------+---------------+-----------------+-------+
|
||||
|\033[32m ISBN \033[39m|\033[32m Title \033[39m|\033[32m Author \033[39m|\033[32m Price \033[39m|
|
||||
+---------------+---------------+-----------------+-------+
|
||||
| 99921-58-10-7 | Divine Comedy | Dante Alighieri | 9.95 |
|
||||
+---------------+---------------+-----------------+-------+
|
||||
\x1b[5A\x1b[0J+---------------+----------------------+-----------------+--------+
|
||||
|\033[32m ISBN \033[39m|\033[32m Title \033[39m|\033[32m Author \033[39m|\033[32m Price \033[39m|
|
||||
+---------------+----------------------+-----------------+--------+
|
||||
| 99921-58-10-7 | Divine Comedy | Dante Alighieri | 9.95 |
|
||||
| 9971-5-0210-0 | A Tale of Two Cities | Charles Dickens | 139.25 |
|
||||
+---------------+----------------------+-----------------+--------+
|
||||
|
||||
TABLE;
|
||||
|
||||
$this->assertEquals($expected, $this->getOutputContent($output));
|
||||
}
|
||||
|
||||
public function testSectionOutputDoesntClearIfTableIsntRendered()
|
||||
{
|
||||
$sections = array();
|
||||
$stream = $this->getOutputStream(true);
|
||||
$output = new ConsoleSectionOutput($stream->getStream(), $sections, $stream->getVerbosity(), $stream->isDecorated(), new OutputFormatter());
|
||||
$table = new Table($output);
|
||||
$table
|
||||
->setHeaders(array('ISBN', 'Title', 'Author', 'Price'))
|
||||
->setRows(array(
|
||||
array('99921-58-10-7', 'Divine Comedy', 'Dante Alighieri', '9.95'),
|
||||
));
|
||||
|
||||
$table->appendRow(array('9971-5-0210-0', 'A Tale of Two Cities', 'Charles Dickens', '139.25'));
|
||||
|
||||
$expected =
|
||||
<<<TABLE
|
||||
+---------------+----------------------+-----------------+--------+
|
||||
|\033[32m ISBN \033[39m|\033[32m Title \033[39m|\033[32m Author \033[39m|\033[32m Price \033[39m|
|
||||
+---------------+----------------------+-----------------+--------+
|
||||
| 99921-58-10-7 | Divine Comedy | Dante Alighieri | 9.95 |
|
||||
| 9971-5-0210-0 | A Tale of Two Cities | Charles Dickens | 139.25 |
|
||||
+---------------+----------------------+-----------------+--------+
|
||||
|
||||
TABLE;
|
||||
|
||||
$this->assertEquals($expected, $this->getOutputContent($output));
|
||||
}
|
||||
|
||||
public function testSectionOutputWithoutDecoration()
|
||||
{
|
||||
$sections = array();
|
||||
$stream = $this->getOutputStream();
|
||||
$output = new ConsoleSectionOutput($stream->getStream(), $sections, $stream->getVerbosity(), $stream->isDecorated(), new OutputFormatter());
|
||||
$table = new Table($output);
|
||||
$table
|
||||
->setHeaders(array('ISBN', 'Title', 'Author', 'Price'))
|
||||
->setRows(array(
|
||||
array('99921-58-10-7', 'Divine Comedy', 'Dante Alighieri', '9.95'),
|
||||
));
|
||||
|
||||
$table->render();
|
||||
|
||||
$table->appendRow(array('9971-5-0210-0', 'A Tale of Two Cities', 'Charles Dickens', '139.25'));
|
||||
|
||||
$expected =
|
||||
<<<TABLE
|
||||
+---------------+---------------+-----------------+-------+
|
||||
| ISBN | Title | Author | Price |
|
||||
+---------------+---------------+-----------------+-------+
|
||||
| 99921-58-10-7 | Divine Comedy | Dante Alighieri | 9.95 |
|
||||
+---------------+---------------+-----------------+-------+
|
||||
+---------------+----------------------+-----------------+--------+
|
||||
| ISBN | Title | Author | Price |
|
||||
+---------------+----------------------+-----------------+--------+
|
||||
| 99921-58-10-7 | Divine Comedy | Dante Alighieri | 9.95 |
|
||||
| 9971-5-0210-0 | A Tale of Two Cities | Charles Dickens | 139.25 |
|
||||
+---------------+----------------------+-----------------+--------+
|
||||
|
||||
TABLE;
|
||||
|
||||
$this->assertEquals($expected, $this->getOutputContent($output));
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \Symfony\Component\Console\Exception\RuntimeException
|
||||
* @expectedExceptionMessage Output should be an instance of "Symfony\Component\Console\Output\ConsoleSectionOutput" when calling "Symfony\Component\Console\Helper\Table::appendRow".
|
||||
*/
|
||||
public function testAppendRowWithoutSectionOutput()
|
||||
{
|
||||
$table = new Table($this->getOutputStream());
|
||||
|
||||
$table->appendRow(array('9971-5-0210-0', 'A Tale of Two Cities', 'Charles Dickens', '139.25'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \Symfony\Component\Console\Exception\InvalidArgumentException
|
||||
* @expectedExceptionMessage Style "absent" is not defined.
|
||||
@@ -824,6 +974,42 @@ TABLE;
|
||||
Table::getStyleDefinition('absent');
|
||||
}
|
||||
|
||||
public function testBoxedStyleWithColspan()
|
||||
{
|
||||
$boxed = new TableStyle();
|
||||
$boxed
|
||||
->setHorizontalBorderChars('─')
|
||||
->setVerticalBorderChars('│')
|
||||
->setCrossingChars('┼', '┌', '┬', '┐', '┤', '┘', '┴', '└', '├')
|
||||
;
|
||||
|
||||
$table = new Table($output = $this->getOutputStream());
|
||||
$table->setStyle($boxed);
|
||||
$table
|
||||
->setHeaders(array('ISBN', 'Title', 'Author'))
|
||||
->setRows(array(
|
||||
array('99921-58-10-7', 'Divine Comedy', 'Dante Alighieri'),
|
||||
new TableSeparator(),
|
||||
array(new TableCell('This value spans 3 columns.', array('colspan' => 3))),
|
||||
))
|
||||
;
|
||||
$table->render();
|
||||
|
||||
$expected =
|
||||
<<<TABLE
|
||||
┌───────────────┬───────────────┬─────────────────┐
|
||||
│ ISBN │ Title │ Author │
|
||||
├───────────────┼───────────────┼─────────────────┤
|
||||
│ 99921-58-10-7 │ Divine Comedy │ Dante Alighieri │
|
||||
├───────────────┼───────────────┼─────────────────┤
|
||||
│ This value spans 3 columns. │
|
||||
└───────────────┴───────────────┴─────────────────┘
|
||||
|
||||
TABLE;
|
||||
|
||||
$this->assertSame($expected, $this->getOutputContent($output));
|
||||
}
|
||||
|
||||
protected function getOutputStream($decorated = false)
|
||||
{
|
||||
return new StreamOutput($this->stream, StreamOutput::VERBOSITY_NORMAL, $decorated);
|
||||
|
||||
@@ -13,8 +13,8 @@ namespace Symfony\Component\Console\Tests\Input;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Component\Console\Input\ArgvInput;
|
||||
use Symfony\Component\Console\Input\InputDefinition;
|
||||
use Symfony\Component\Console\Input\InputArgument;
|
||||
use Symfony\Component\Console\Input\InputDefinition;
|
||||
use Symfony\Component\Console\Input\InputOption;
|
||||
|
||||
class ArgvInputTest extends TestCase
|
||||
@@ -246,6 +246,11 @@ class ArgvInputTest extends TestCase
|
||||
new InputDefinition(array(new InputArgument('number'))),
|
||||
'The "-1" option does not exist.',
|
||||
),
|
||||
array(
|
||||
array('cli.php', '-fЩ'),
|
||||
new InputDefinition(array(new InputOption('foo', 'f', InputOption::VALUE_NONE))),
|
||||
'The "-Щ" option does not exist.',
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -395,25 +400,26 @@ class ArgvInputTest extends TestCase
|
||||
/**
|
||||
* @dataProvider provideGetParameterOptionValues
|
||||
*/
|
||||
public function testGetParameterOptionEqualSign($argv, $key, $onlyParams, $expected)
|
||||
public function testGetParameterOptionEqualSign($argv, $key, $default, $onlyParams, $expected)
|
||||
{
|
||||
$input = new ArgvInput($argv);
|
||||
$this->assertEquals($expected, $input->getParameterOption($key, false, $onlyParams), '->getParameterOption() returns the expected value');
|
||||
$this->assertEquals($expected, $input->getParameterOption($key, $default, $onlyParams), '->getParameterOption() returns the expected value');
|
||||
}
|
||||
|
||||
public function provideGetParameterOptionValues()
|
||||
{
|
||||
return array(
|
||||
array(array('app/console', 'foo:bar', '-e', 'dev'), '-e', false, 'dev'),
|
||||
array(array('app/console', 'foo:bar', '--env=dev'), '--env', false, 'dev'),
|
||||
array(array('app/console', 'foo:bar', '-e', 'dev'), array('-e', '--env'), false, 'dev'),
|
||||
array(array('app/console', 'foo:bar', '--env=dev'), array('-e', '--env'), false, 'dev'),
|
||||
array(array('app/console', 'foo:bar', '--env=dev', '--en=1'), array('--en'), false, '1'),
|
||||
array(array('app/console', 'foo:bar', '--env=dev', '', '--en=1'), array('--en'), false, '1'),
|
||||
array(array('app/console', 'foo:bar', '--env', 'val'), '--env', false, 'val'),
|
||||
array(array('app/console', 'foo:bar', '--env', 'val', '--dummy'), '--env', false, 'val'),
|
||||
array(array('app/console', 'foo:bar', '--', '--env=dev'), '--env', false, 'dev'),
|
||||
array(array('app/console', 'foo:bar', '--', '--env=dev'), '--env', true, false),
|
||||
array(array('app/console', 'foo:bar'), '-e', 'default', false, 'default'),
|
||||
array(array('app/console', 'foo:bar', '-e', 'dev'), '-e', 'default', false, 'dev'),
|
||||
array(array('app/console', 'foo:bar', '--env=dev'), '--env', 'default', false, 'dev'),
|
||||
array(array('app/console', 'foo:bar', '-e', 'dev'), array('-e', '--env'), 'default', false, 'dev'),
|
||||
array(array('app/console', 'foo:bar', '--env=dev'), array('-e', '--env'), 'default', false, 'dev'),
|
||||
array(array('app/console', 'foo:bar', '--env=dev', '--en=1'), array('--en'), 'default', false, '1'),
|
||||
array(array('app/console', 'foo:bar', '--env=dev', '', '--en=1'), array('--en'), 'default', false, '1'),
|
||||
array(array('app/console', 'foo:bar', '--env', 'val'), '--env', 'default', false, 'val'),
|
||||
array(array('app/console', 'foo:bar', '--env', 'val', '--dummy'), '--env', 'default', false, 'val'),
|
||||
array(array('app/console', 'foo:bar', '--', '--env=dev'), '--env', 'default', false, 'dev'),
|
||||
array(array('app/console', 'foo:bar', '--', '--env=dev'), '--env', 'default', true, 'default'),
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -13,8 +13,8 @@ namespace Symfony\Component\Console\Tests\Input;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Component\Console\Input\ArrayInput;
|
||||
use Symfony\Component\Console\Input\InputDefinition;
|
||||
use Symfony\Component\Console\Input\InputArgument;
|
||||
use Symfony\Component\Console\Input\InputDefinition;
|
||||
use Symfony\Component\Console\Input\InputOption;
|
||||
|
||||
class ArrayInputTest extends TestCase
|
||||
@@ -47,14 +47,14 @@ class ArrayInputTest extends TestCase
|
||||
{
|
||||
$input = new ArrayInput(array('name' => 'Fabien', '--foo' => 'bar'));
|
||||
$this->assertEquals('bar', $input->getParameterOption('--foo'), '->getParameterOption() returns the option of specified name');
|
||||
$this->assertFalse($input->getParameterOption('--bar'), '->getParameterOption() returns the default if an option is not present in the passed parameters');
|
||||
$this->assertEquals('default', $input->getParameterOption('--bar', 'default'), '->getParameterOption() returns the default value if an option is not present in the passed parameters');
|
||||
|
||||
$input = new ArrayInput(array('Fabien', '--foo' => 'bar'));
|
||||
$this->assertEquals('bar', $input->getParameterOption('--foo'), '->getParameterOption() returns the option of specified name');
|
||||
|
||||
$input = new ArrayInput(array('--foo', '--', '--bar' => 'woop'));
|
||||
$this->assertEquals('woop', $input->getParameterOption('--bar'), '->getParameterOption() returns the correct value if an option is present in the passed parameters');
|
||||
$this->assertFalse($input->getParameterOption('--bar', false, true), '->getParameterOption() returns false if an option is present in the passed parameters after an end of options signal');
|
||||
$this->assertEquals('default', $input->getParameterOption('--bar', 'default', true), '->getParameterOption() returns the default value if an option is present in the passed parameters after an end of options signal');
|
||||
}
|
||||
|
||||
public function testParseArguments()
|
||||
|
||||
@@ -38,26 +38,12 @@ class InputArgumentTest extends TestCase
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider provideInvalidModes
|
||||
* @expectedException \InvalidArgumentException
|
||||
* @expectedExceptionMessage Argument mode "-1" is not valid.
|
||||
*/
|
||||
public function testInvalidModes($mode)
|
||||
public function testInvalidModes()
|
||||
{
|
||||
if (method_exists($this, 'expectException')) {
|
||||
$this->expectException('InvalidArgumentException');
|
||||
$this->expectExceptionMessage(sprintf('Argument mode "%s" is not valid.', $mode));
|
||||
} else {
|
||||
$this->setExpectedException('InvalidArgumentException', sprintf('Argument mode "%s" is not valid.', $mode));
|
||||
}
|
||||
|
||||
new InputArgument('foo', $mode);
|
||||
}
|
||||
|
||||
public function provideInvalidModes()
|
||||
{
|
||||
return array(
|
||||
array('ANOTHER_ONE'),
|
||||
array(-1),
|
||||
);
|
||||
new InputArgument('foo', '-1');
|
||||
}
|
||||
|
||||
public function testIsArray()
|
||||
|
||||
@@ -12,8 +12,8 @@
|
||||
namespace Symfony\Component\Console\Tests\Input;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Component\Console\Input\InputDefinition;
|
||||
use Symfony\Component\Console\Input\InputArgument;
|
||||
use Symfony\Component\Console\Input\InputDefinition;
|
||||
use Symfony\Component\Console\Input\InputOption;
|
||||
|
||||
class InputDefinitionTest extends TestCase
|
||||
@@ -374,8 +374,9 @@ class InputDefinitionTest extends TestCase
|
||||
|
||||
array(new InputDefinition(array(new InputArgument('foo', InputArgument::REQUIRED))), '<foo>', 'puts arguments in angle brackets'),
|
||||
array(new InputDefinition(array(new InputArgument('foo'))), '[<foo>]', 'puts optional arguments in square brackets'),
|
||||
array(new InputDefinition(array(new InputArgument('foo', InputArgument::IS_ARRAY))), '[<foo>]...', 'uses an ellipsis for array arguments'),
|
||||
array(new InputDefinition(array(new InputArgument('foo', InputArgument::REQUIRED | InputArgument::IS_ARRAY))), '<foo> (<foo>)...', 'uses parenthesis and ellipsis for required array arguments'),
|
||||
array(new InputDefinition(array(new InputArgument('foo'), new InputArgument('bar'))), '[<foo> [<bar>]]', 'chains optional arguments inside brackets'),
|
||||
array(new InputDefinition(array(new InputArgument('foo', InputArgument::IS_ARRAY))), '[<foo>...]', 'uses an ellipsis for array arguments'),
|
||||
array(new InputDefinition(array(new InputArgument('foo', InputArgument::REQUIRED | InputArgument::IS_ARRAY))), '<foo>...', 'uses an ellipsis for required array arguments'),
|
||||
|
||||
array(new InputDefinition(array(new InputOption('foo'), new InputArgument('foo', InputArgument::REQUIRED))), '[--foo] [--] <foo>', 'puts [--] between options and arguments'),
|
||||
);
|
||||
|
||||
@@ -74,26 +74,12 @@ class InputOptionTest extends TestCase
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider provideInvalidModes
|
||||
* @expectedException \InvalidArgumentException
|
||||
* @expectedExceptionMessage Option mode "-1" is not valid.
|
||||
*/
|
||||
public function testInvalidModes($mode)
|
||||
public function testInvalidModes()
|
||||
{
|
||||
if (method_exists($this, 'expectException')) {
|
||||
$this->expectException('InvalidArgumentException');
|
||||
$this->expectExceptionMessage(sprintf('Option mode "%s" is not valid.', $mode));
|
||||
} else {
|
||||
$this->setExpectedException('InvalidArgumentException', sprintf('Option mode "%s" is not valid.', $mode));
|
||||
}
|
||||
|
||||
new InputOption('foo', 'f', $mode);
|
||||
}
|
||||
|
||||
public function provideInvalidModes()
|
||||
{
|
||||
return array(
|
||||
array('ANOTHER_ONE'),
|
||||
array(-1),
|
||||
);
|
||||
new InputOption('foo', 'f', '-1');
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -13,8 +13,8 @@ namespace Symfony\Component\Console\Tests\Input;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Component\Console\Input\ArrayInput;
|
||||
use Symfony\Component\Console\Input\InputDefinition;
|
||||
use Symfony\Component\Console\Input\InputArgument;
|
||||
use Symfony\Component\Console\Input\InputDefinition;
|
||||
use Symfony\Component\Console\Input\InputOption;
|
||||
|
||||
class InputTest extends TestCase
|
||||
|
||||
@@ -16,8 +16,8 @@ use Psr\Log\LoggerInterface;
|
||||
use Psr\Log\LogLevel;
|
||||
use Symfony\Component\Console\Logger\ConsoleLogger;
|
||||
use Symfony\Component\Console\Output\BufferedOutput;
|
||||
use Symfony\Component\Console\Tests\Fixtures\DummyOutput;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
use Symfony\Component\Console\Tests\Fixtures\DummyOutput;
|
||||
|
||||
/**
|
||||
* Console logger test.
|
||||
|
||||
163
vendor/symfony/console/Tests/Output/ConsoleSectionOutputTest.php
vendored
Normal file
163
vendor/symfony/console/Tests/Output/ConsoleSectionOutputTest.php
vendored
Normal file
@@ -0,0 +1,163 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\Console\Tests\Output;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Component\Console\Formatter\OutputFormatter;
|
||||
use Symfony\Component\Console\Helper\QuestionHelper;
|
||||
use Symfony\Component\Console\Input\StreamableInputInterface;
|
||||
use Symfony\Component\Console\Output\ConsoleSectionOutput;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
use Symfony\Component\Console\Output\StreamOutput;
|
||||
use Symfony\Component\Console\Question\Question;
|
||||
|
||||
class ConsoleSectionOutputTest extends TestCase
|
||||
{
|
||||
private $stream;
|
||||
|
||||
protected function setUp()
|
||||
{
|
||||
$this->stream = fopen('php://memory', 'r+b', false);
|
||||
}
|
||||
|
||||
protected function tearDown()
|
||||
{
|
||||
$this->stream = null;
|
||||
}
|
||||
|
||||
public function testClearAll()
|
||||
{
|
||||
$sections = array();
|
||||
$output = new ConsoleSectionOutput($this->stream, $sections, OutputInterface::VERBOSITY_NORMAL, true, new OutputFormatter());
|
||||
|
||||
$output->writeln('Foo'.PHP_EOL.'Bar');
|
||||
$output->clear();
|
||||
|
||||
rewind($output->getStream());
|
||||
$this->assertEquals('Foo'.PHP_EOL.'Bar'.PHP_EOL.sprintf("\x1b[%dA", 2)."\x1b[0J", stream_get_contents($output->getStream()));
|
||||
}
|
||||
|
||||
public function testClearNumberOfLines()
|
||||
{
|
||||
$sections = array();
|
||||
$output = new ConsoleSectionOutput($this->stream, $sections, OutputInterface::VERBOSITY_NORMAL, true, new OutputFormatter());
|
||||
|
||||
$output->writeln("Foo\nBar\nBaz\nFooBar");
|
||||
$output->clear(2);
|
||||
|
||||
rewind($output->getStream());
|
||||
$this->assertEquals("Foo\nBar\nBaz\nFooBar".PHP_EOL.sprintf("\x1b[%dA", 2)."\x1b[0J", stream_get_contents($output->getStream()));
|
||||
}
|
||||
|
||||
public function testClearNumberOfLinesWithMultipleSections()
|
||||
{
|
||||
$output = new StreamOutput($this->stream);
|
||||
$sections = array();
|
||||
$output1 = new ConsoleSectionOutput($output->getStream(), $sections, OutputInterface::VERBOSITY_NORMAL, true, new OutputFormatter());
|
||||
$output2 = new ConsoleSectionOutput($output->getStream(), $sections, OutputInterface::VERBOSITY_NORMAL, true, new OutputFormatter());
|
||||
|
||||
$output2->writeln('Foo');
|
||||
$output2->writeln('Bar');
|
||||
$output2->clear(1);
|
||||
$output1->writeln('Baz');
|
||||
|
||||
rewind($output->getStream());
|
||||
|
||||
$this->assertEquals('Foo'.PHP_EOL.'Bar'.PHP_EOL."\x1b[1A\x1b[0J\e[1A\e[0J".'Baz'.PHP_EOL.'Foo'.PHP_EOL, stream_get_contents($output->getStream()));
|
||||
}
|
||||
|
||||
public function testClearPreservingEmptyLines()
|
||||
{
|
||||
$output = new StreamOutput($this->stream);
|
||||
$sections = array();
|
||||
$output1 = new ConsoleSectionOutput($output->getStream(), $sections, OutputInterface::VERBOSITY_NORMAL, true, new OutputFormatter());
|
||||
$output2 = new ConsoleSectionOutput($output->getStream(), $sections, OutputInterface::VERBOSITY_NORMAL, true, new OutputFormatter());
|
||||
|
||||
$output2->writeln(PHP_EOL.'foo');
|
||||
$output2->clear(1);
|
||||
$output1->writeln('bar');
|
||||
|
||||
rewind($output->getStream());
|
||||
|
||||
$this->assertEquals(PHP_EOL.'foo'.PHP_EOL."\x1b[1A\x1b[0J\x1b[1A\x1b[0J".'bar'.PHP_EOL.PHP_EOL, stream_get_contents($output->getStream()));
|
||||
}
|
||||
|
||||
public function testOverwrite()
|
||||
{
|
||||
$sections = array();
|
||||
$output = new ConsoleSectionOutput($this->stream, $sections, OutputInterface::VERBOSITY_NORMAL, true, new OutputFormatter());
|
||||
|
||||
$output->writeln('Foo');
|
||||
$output->overwrite('Bar');
|
||||
|
||||
rewind($output->getStream());
|
||||
$this->assertEquals('Foo'.PHP_EOL."\x1b[1A\x1b[0JBar".PHP_EOL, stream_get_contents($output->getStream()));
|
||||
}
|
||||
|
||||
public function testOverwriteMultipleLines()
|
||||
{
|
||||
$sections = array();
|
||||
$output = new ConsoleSectionOutput($this->stream, $sections, OutputInterface::VERBOSITY_NORMAL, true, new OutputFormatter());
|
||||
|
||||
$output->writeln('Foo'.PHP_EOL.'Bar'.PHP_EOL.'Baz');
|
||||
$output->overwrite('Bar');
|
||||
|
||||
rewind($output->getStream());
|
||||
$this->assertEquals('Foo'.PHP_EOL.'Bar'.PHP_EOL.'Baz'.PHP_EOL.sprintf("\x1b[%dA", 3)."\x1b[0J".'Bar'.PHP_EOL, stream_get_contents($output->getStream()));
|
||||
}
|
||||
|
||||
public function testAddingMultipleSections()
|
||||
{
|
||||
$sections = array();
|
||||
$output1 = new ConsoleSectionOutput($this->stream, $sections, OutputInterface::VERBOSITY_NORMAL, true, new OutputFormatter());
|
||||
$output2 = new ConsoleSectionOutput($this->stream, $sections, OutputInterface::VERBOSITY_NORMAL, true, new OutputFormatter());
|
||||
|
||||
$this->assertCount(2, $sections);
|
||||
}
|
||||
|
||||
public function testMultipleSectionsOutput()
|
||||
{
|
||||
$output = new StreamOutput($this->stream);
|
||||
$sections = array();
|
||||
$output1 = new ConsoleSectionOutput($output->getStream(), $sections, OutputInterface::VERBOSITY_NORMAL, true, new OutputFormatter());
|
||||
$output2 = new ConsoleSectionOutput($output->getStream(), $sections, OutputInterface::VERBOSITY_NORMAL, true, new OutputFormatter());
|
||||
|
||||
$output1->writeln('Foo');
|
||||
$output2->writeln('Bar');
|
||||
|
||||
$output1->overwrite('Baz');
|
||||
$output2->overwrite('Foobar');
|
||||
|
||||
rewind($output->getStream());
|
||||
$this->assertEquals('Foo'.PHP_EOL.'Bar'.PHP_EOL."\x1b[2A\x1b[0JBar".PHP_EOL."\x1b[1A\x1b[0JBaz".PHP_EOL.'Bar'.PHP_EOL."\x1b[1A\x1b[0JFoobar".PHP_EOL, stream_get_contents($output->getStream()));
|
||||
}
|
||||
|
||||
public function testClearSectionContainingQuestion()
|
||||
{
|
||||
$inputStream = fopen('php://memory', 'r+b', false);
|
||||
fwrite($inputStream, "Batman & Robin\n");
|
||||
rewind($inputStream);
|
||||
|
||||
$input = $this->getMockBuilder(StreamableInputInterface::class)->getMock();
|
||||
$input->expects($this->once())->method('isInteractive')->willReturn(true);
|
||||
$input->expects($this->once())->method('getStream')->willReturn($inputStream);
|
||||
|
||||
$sections = array();
|
||||
$output = new ConsoleSectionOutput($this->stream, $sections, OutputInterface::VERBOSITY_NORMAL, true, new OutputFormatter());
|
||||
|
||||
(new QuestionHelper())->ask($input, $output, new Question('What\'s your favorite super hero?'));
|
||||
$output->clear();
|
||||
|
||||
rewind($output->getStream());
|
||||
$this->assertSame('What\'s your favorite super hero?'.PHP_EOL."\x1b[2A\x1b[0J", stream_get_contents($output->getStream()));
|
||||
}
|
||||
}
|
||||
@@ -12,8 +12,8 @@
|
||||
namespace Symfony\Component\Console\Tests\Output;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Component\Console\Output\Output;
|
||||
use Symfony\Component\Console\Formatter\OutputFormatterStyle;
|
||||
use Symfony\Component\Console\Output\Output;
|
||||
|
||||
class OutputTest extends TestCase
|
||||
{
|
||||
@@ -81,6 +81,19 @@ class OutputTest extends TestCase
|
||||
$this->assertEquals("foo\nbar\n", $output->output, '->writeln() can take an array of messages to output');
|
||||
}
|
||||
|
||||
public function testWriteAnIterableOfMessages()
|
||||
{
|
||||
$output = new TestOutput();
|
||||
$output->writeln($this->generateMessages());
|
||||
$this->assertEquals("foo\nbar\n", $output->output, '->writeln() can take an iterable of messages to output');
|
||||
}
|
||||
|
||||
private function generateMessages(): iterable
|
||||
{
|
||||
yield 'foo';
|
||||
yield 'bar';
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider provideWriteArguments
|
||||
*/
|
||||
|
||||
@@ -13,12 +13,12 @@ namespace Symfony\Component\Console\Tests\Style;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Component\Console\Command\Command;
|
||||
use Symfony\Component\Console\Tester\CommandTester;
|
||||
use Symfony\Component\Console\Formatter\OutputFormatter;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
use Symfony\Component\Console\Output\ConsoleOutputInterface;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Output\ConsoleOutputInterface;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
use Symfony\Component\Console\Style\SymfonyStyle;
|
||||
use Symfony\Component\Console\Tester\CommandTester;
|
||||
|
||||
class SymfonyStyleTest extends TestCase
|
||||
{
|
||||
|
||||
@@ -13,7 +13,9 @@ namespace Symfony\Component\Console\Tests\Tester;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Component\Console\Application;
|
||||
use Symfony\Component\Console\Helper\QuestionHelper;
|
||||
use Symfony\Component\Console\Output\Output;
|
||||
use Symfony\Component\Console\Question\Question;
|
||||
use Symfony\Component\Console\Tester\ApplicationTester;
|
||||
|
||||
class ApplicationTesterTest extends TestCase
|
||||
@@ -27,7 +29,9 @@ class ApplicationTesterTest extends TestCase
|
||||
$this->application->setAutoExit(false);
|
||||
$this->application->register('foo')
|
||||
->addArgument('foo')
|
||||
->setCode(function ($input, $output) { $output->writeln('foo'); })
|
||||
->setCode(function ($input, $output) {
|
||||
$output->writeln('foo');
|
||||
})
|
||||
;
|
||||
|
||||
$this->tester = new ApplicationTester($this->application);
|
||||
@@ -63,6 +67,25 @@ class ApplicationTesterTest extends TestCase
|
||||
$this->assertEquals('foo'.PHP_EOL, $this->tester->getDisplay(), '->getDisplay() returns the display of the last execution');
|
||||
}
|
||||
|
||||
public function testSetInputs()
|
||||
{
|
||||
$application = new Application();
|
||||
$application->setAutoExit(false);
|
||||
$application->register('foo')->setCode(function ($input, $output) {
|
||||
$helper = new QuestionHelper();
|
||||
$helper->ask($input, $output, new Question('Q1'));
|
||||
$helper->ask($input, $output, new Question('Q2'));
|
||||
$helper->ask($input, $output, new Question('Q3'));
|
||||
});
|
||||
$tester = new ApplicationTester($application);
|
||||
|
||||
$tester->setInputs(array('I1', 'I2', 'I3'));
|
||||
$tester->run(array('command' => 'foo'));
|
||||
|
||||
$this->assertSame(0, $tester->getStatusCode());
|
||||
$this->assertEquals('Q1Q2Q3', $tester->getDisplay(true));
|
||||
}
|
||||
|
||||
public function testGetStatusCode()
|
||||
{
|
||||
$this->assertSame(0, $this->tester->getStatusCode(), '->getStatusCode() returns the status code');
|
||||
|
||||
@@ -14,12 +14,12 @@ namespace Symfony\Component\Console\Tests\Tester;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Component\Console\Application;
|
||||
use Symfony\Component\Console\Command\Command;
|
||||
use Symfony\Component\Console\Output\Output;
|
||||
use Symfony\Component\Console\Tester\CommandTester;
|
||||
use Symfony\Component\Console\Question\Question;
|
||||
use Symfony\Component\Console\Helper\HelperSet;
|
||||
use Symfony\Component\Console\Helper\QuestionHelper;
|
||||
use Symfony\Component\Console\Output\Output;
|
||||
use Symfony\Component\Console\Question\Question;
|
||||
use Symfony\Component\Console\Style\SymfonyStyle;
|
||||
use Symfony\Component\Console\Tester\CommandTester;
|
||||
|
||||
class CommandTesterTest extends TestCase
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user