diff options
Diffstat (limited to 'vendor/symfony/console/Tests/Command')
4 files changed, 151 insertions, 43 deletions
diff --git a/vendor/symfony/console/Tests/Command/CommandTest.php b/vendor/symfony/console/Tests/Command/CommandTest.php index e8836d8c..4fcbf957 100644 --- a/vendor/symfony/console/Tests/Command/CommandTest.php +++ b/vendor/symfony/console/Tests/Command/CommandTest.php @@ -11,6 +11,7 @@ namespace Symfony\Component\Console\Tests\Command; +use PHPUnit\Framework\TestCase; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Helper\FormatterHelper; use Symfony\Component\Console\Application; @@ -23,7 +24,7 @@ use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Output\NullOutput; use Symfony\Component\Console\Tester\CommandTester; -class CommandTest extends \PHPUnit_Framework_TestCase +class CommandTest extends TestCase { protected static $fixturesPath; @@ -45,7 +46,7 @@ class CommandTest extends \PHPUnit_Framework_TestCase */ public function testCommandNameCannotBeEmpty() { - new Command(); + (new Application())->add(new Command()); } public function testSetApplication() @@ -54,6 +55,14 @@ class CommandTest extends \PHPUnit_Framework_TestCase $command = new \TestCommand(); $command->setApplication($application); $this->assertEquals($application, $command->getApplication(), '->setApplication() sets the current application'); + $this->assertEquals($application->getHelperSet(), $command->getHelperSet()); + } + + public function testSetApplicationNull() + { + $command = new \TestCommand(); + $command->setApplication(null); + $this->assertNull($command->getHelperSet()); } public function testSetGetDefinition() @@ -84,6 +93,13 @@ class CommandTest extends \PHPUnit_Framework_TestCase $this->assertTrue($command->getDefinition()->hasOption('foo'), '->addOption() adds an option to the command'); } + public function testSetHidden() + { + $command = new \TestCommand(); + $command->setHidden(true); + $this->assertTrue($command->isHidden()); + } + public function testGetNamespaceGetNameSetName() { $command = new \TestCommand(); @@ -101,7 +117,12 @@ class CommandTest extends \PHPUnit_Framework_TestCase */ public function testInvalidCommandNames($name) { - $this->setExpectedException('InvalidArgumentException', sprintf('Command name "%s" is invalid.', $name)); + if (method_exists($this, 'expectException')) { + $this->expectException('InvalidArgumentException'); + $this->expectExceptionMessage(sprintf('Command name "%s" is invalid.', $name)); + } else { + $this->setExpectedException('InvalidArgumentException', sprintf('Command name "%s" is invalid.', $name)); + } $command = new \TestCommand(); $command->setName($name); @@ -156,6 +177,13 @@ class CommandTest extends \PHPUnit_Framework_TestCase $this->assertEquals(array('name1'), $command->getAliases(), '->setAliases() sets the aliases'); } + public function testSetAliasesNull() + { + $command = new \TestCommand(); + $this->{method_exists($this, $_ = 'expectException') ? $_ : 'setExpectedException'}('InvalidArgumentException'); + $command->setAliases(null); + } + public function testGetSynopsis() { $command = new \TestCommand(); @@ -164,6 +192,15 @@ class CommandTest extends \PHPUnit_Framework_TestCase $this->assertEquals('namespace:name [--foo] [--] [<bar>]', $command->getSynopsis(), '->getSynopsis() returns the synopsis'); } + public function testAddGetUsages() + { + $command = new \TestCommand(); + $command->addUsage('foo1'); + $command->addUsage('foo2'); + $this->assertContains('namespace:name foo1', $command->getUsages()); + $this->assertContains('namespace:name foo2', $command->getUsages()); + } + public function testGetHelper() { $application = new Application(); @@ -257,7 +294,7 @@ class CommandTest extends \PHPUnit_Framework_TestCase } /** - * @expectedException Symfony\Component\Console\Exception\InvalidOptionException + * @expectedException \Symfony\Component\Console\Exception\InvalidOptionException * @expectedExceptionMessage The "--bar" option does not exist. */ public function testRunWithInvalidOption() @@ -273,10 +310,10 @@ class CommandTest extends \PHPUnit_Framework_TestCase $exitCode = $command->run(new StringInput(''), new NullOutput()); $this->assertSame(0, $exitCode, '->run() returns integer exit code (treats null as 0)'); - $command = $this->getMock('TestCommand', array('execute')); + $command = $this->getMockBuilder('TestCommand')->setMethods(array('execute'))->getMock(); $command->expects($this->once()) - ->method('execute') - ->will($this->returnValue('2.3')); + ->method('execute') + ->will($this->returnValue('2.3')); $exitCode = $command->run(new StringInput(''), new NullOutput()); $this->assertSame(2, $exitCode, '->run() returns integer exit code (casts numeric to int)'); } @@ -297,6 +334,20 @@ class CommandTest extends \PHPUnit_Framework_TestCase $this->assertSame(0, $command->run(new StringInput(''), new NullOutput())); } + public function testRunWithProcessTitle() + { + $command = new \TestCommand(); + $command->setApplication(new Application()); + $command->setProcessTitle('foo'); + $this->assertSame(0, $command->run(new StringInput(''), new NullOutput())); + 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.'); + } + $this->assertEquals('foo', cli_get_process_title()); + } + } + public function testSetCode() { $command = new \TestCommand(); @@ -319,7 +370,6 @@ class CommandTest extends \PHPUnit_Framework_TestCase /** * @dataProvider getSetCodeBindToClosureTests - * @requires PHP 5.4 */ public function testSetCodeBindToClosure($previouslyBound, $expected) { @@ -335,53 +385,42 @@ class CommandTest extends \PHPUnit_Framework_TestCase $this->assertEquals('interact called'.PHP_EOL.$expected.PHP_EOL, $tester->getDisplay()); } - public function testSetCodeWithNonClosureCallable() + public function testSetCodeWithStaticClosure() { $command = new \TestCommand(); - $ret = $command->setCode(array($this, 'callableMethodCommand')); - $this->assertEquals($command, $ret, '->setCode() implements a fluent interface'); + $command->setCode(self::createClosure()); $tester = new CommandTester($command); $tester->execute(array()); - $this->assertEquals('interact called'.PHP_EOL.'from the code...'.PHP_EOL, $tester->getDisplay()); - } - /** - * @expectedException \InvalidArgumentException - * @expectedExceptionMessage Invalid callable provided to Command::setCode. - */ - public function testSetCodeWithNonCallable() - { - $command = new \TestCommand(); - $command->setCode(array($this, 'nonExistentMethod')); + 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()); + } } - public function callableMethodCommand(InputInterface $input, OutputInterface $output) + private static function createClosure() { - $output->writeln('from the code...'); + return function (InputInterface $input, OutputInterface $output) { + $output->writeln(isset($this) ? 'bound' : 'not bound'); + }; } - /** - * @group legacy - */ - public function testLegacyAsText() + public function testSetCodeWithNonClosureCallable() { $command = new \TestCommand(); - $command->setApplication(new Application()); + $ret = $command->setCode(array($this, 'callableMethodCommand')); + $this->assertEquals($command, $ret, '->setCode() implements a fluent interface'); $tester = new CommandTester($command); - $tester->execute(array('command' => $command->getName())); - $this->assertStringEqualsFile(self::$fixturesPath.'/command_astext.txt', $command->asText(), '->asText() returns a text representation of the command'); + $tester->execute(array()); + $this->assertEquals('interact called'.PHP_EOL.'from the code...'.PHP_EOL, $tester->getDisplay()); } - /** - * @group legacy - */ - public function testLegacyAsXml() + public function callableMethodCommand(InputInterface $input, OutputInterface $output) { - $command = new \TestCommand(); - $command->setApplication(new Application()); - $tester = new CommandTester($command); - $tester->execute(array('command' => $command->getName())); - $this->assertXmlStringEqualsXmlFile(self::$fixturesPath.'/command_asxml.txt', $command->asXml(), '->asXml() returns an XML representation of the command'); + $output->writeln('from the code...'); } } diff --git a/vendor/symfony/console/Tests/Command/HelpCommandTest.php b/vendor/symfony/console/Tests/Command/HelpCommandTest.php index 9e068587..4d618ac1 100644 --- a/vendor/symfony/console/Tests/Command/HelpCommandTest.php +++ b/vendor/symfony/console/Tests/Command/HelpCommandTest.php @@ -11,12 +11,13 @@ namespace Symfony\Component\Console\Tests\Command; +use PHPUnit\Framework\TestCase; use Symfony\Component\Console\Tester\CommandTester; use Symfony\Component\Console\Command\HelpCommand; use Symfony\Component\Console\Command\ListCommand; use Symfony\Component\Console\Application; -class HelpCommandTest extends \PHPUnit_Framework_TestCase +class HelpCommandTest extends TestCase { public function testExecuteForCommandAlias() { @@ -64,7 +65,7 @@ class HelpCommandTest extends \PHPUnit_Framework_TestCase $application = new Application(); $commandTester = new CommandTester($application->get('help')); $commandTester->execute(array('command_name' => 'list', '--format' => 'xml')); - $this->assertContains('list [--xml] [--raw] [--format FORMAT] [--] [<namespace>]', $commandTester->getDisplay(), '->execute() returns a text help for the given command'); + $this->assertContains('list [--raw] [--format FORMAT] [--] [<namespace>]', $commandTester->getDisplay(), '->execute() returns a text help for the given command'); $this->assertContains('<command', $commandTester->getDisplay(), '->execute() returns an XML help text if --format=xml is passed'); } } diff --git a/vendor/symfony/console/Tests/Command/ListCommandTest.php b/vendor/symfony/console/Tests/Command/ListCommandTest.php index a166a040..64478ecc 100644 --- a/vendor/symfony/console/Tests/Command/ListCommandTest.php +++ b/vendor/symfony/console/Tests/Command/ListCommandTest.php @@ -11,10 +11,11 @@ namespace Symfony\Component\Console\Tests\Command; +use PHPUnit\Framework\TestCase; use Symfony\Component\Console\Tester\CommandTester; use Symfony\Component\Console\Application; -class ListCommandTest extends \PHPUnit_Framework_TestCase +class ListCommandTest extends TestCase { public function testExecuteListsCommands() { @@ -30,7 +31,7 @@ class ListCommandTest extends \PHPUnit_Framework_TestCase $application = new Application(); $commandTester = new CommandTester($command = $application->get('list')); $commandTester->execute(array('command' => $command->getName(), '--format' => 'xml')); - $this->assertRegExp('/<command id="list" name="list">/', $commandTester->getDisplay(), '->execute() returns a list of available commands in XML if --xml is passed'); + $this->assertRegExp('/<command id="list" name="list" hidden="0">/', $commandTester->getDisplay(), '->execute() returns a list of available commands in XML if --xml is passed'); } public function testExecuteListsCommandsWithRawOption() diff --git a/vendor/symfony/console/Tests/Command/LockableTraitTest.php b/vendor/symfony/console/Tests/Command/LockableTraitTest.php new file mode 100644 index 00000000..a622d1b4 --- /dev/null +++ b/vendor/symfony/console/Tests/Command/LockableTraitTest.php @@ -0,0 +1,67 @@ +<?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\Command; + +use PHPUnit\Framework\TestCase; +use Symfony\Component\Console\Tester\CommandTester; +use Symfony\Component\Lock\Factory; +use Symfony\Component\Lock\Store\FlockStore; +use Symfony\Component\Lock\Store\SemaphoreStore; + +class LockableTraitTest extends TestCase +{ + protected static $fixturesPath; + + public static function setUpBeforeClass() + { + self::$fixturesPath = __DIR__.'/../Fixtures/'; + require_once self::$fixturesPath.'/FooLockCommand.php'; + require_once self::$fixturesPath.'/FooLock2Command.php'; + } + + public function testLockIsReleased() + { + $command = new \FooLockCommand(); + + $tester = new CommandTester($command); + $this->assertSame(2, $tester->execute(array())); + $this->assertSame(2, $tester->execute(array())); + } + + public function testLockReturnsFalseIfAlreadyLockedByAnotherCommand() + { + $command = new \FooLockCommand(); + + if (SemaphoreStore::isSupported(false)) { + $store = new SemaphoreStore(); + } else { + $store = new FlockStore(); + } + + $lock = (new Factory($store))->createLock($command->getName()); + $lock->acquire(); + + $tester = new CommandTester($command); + $this->assertSame(1, $tester->execute(array())); + + $lock->release(); + $this->assertSame(2, $tester->execute(array())); + } + + public function testMultipleLockCallsThrowLogicException() + { + $command = new \FooLock2Command(); + + $tester = new CommandTester($command); + $this->assertSame(1, $tester->execute(array())); + } +} |