From b3dbccb3bb6f9145f0c82bc1fcc8097daee83ac3 Mon Sep 17 00:00:00 2001 From: "Alexander M. Turek" Date: Sun, 27 Dec 2020 00:49:32 +0100 Subject: [PATCH 01/15] CS: Apply ternary_to_null_coalescing fixer --- Application.php | 10 +++++----- Descriptor/ApplicationDescription.php | 2 +- Descriptor/JsonDescriptor.php | 4 ++-- Descriptor/MarkdownDescriptor.php | 2 +- Descriptor/TextDescriptor.php | 6 +++--- Descriptor/XmlDescriptor.php | 2 +- Formatter/OutputFormatter.php | 2 +- Helper/ProgressBar.php | 4 ++-- Helper/ProgressIndicator.php | 4 ++-- Helper/QuestionHelper.php | 4 ++-- Helper/SymfonyQuestionHelper.php | 2 +- Helper/Table.php | 6 +++--- Input/Input.php | 2 +- Style/SymfonyStyle.php | 2 +- Tester/TesterTrait.php | 4 ++-- 15 files changed, 28 insertions(+), 28 deletions(-) diff --git a/Application.php b/Application.php index bc3f23b5e..e71a16d10 100644 --- a/Application.php +++ b/Application.php @@ -925,11 +925,11 @@ private function doActuallyRenderThrowable(\Throwable $e, OutputInterface $outpu ]); for ($i = 0, $count = \count($trace); $i < $count; ++$i) { - $class = isset($trace[$i]['class']) ? $trace[$i]['class'] : ''; - $type = isset($trace[$i]['type']) ? $trace[$i]['type'] : ''; - $function = isset($trace[$i]['function']) ? $trace[$i]['function'] : ''; - $file = isset($trace[$i]['file']) ? $trace[$i]['file'] : 'n/a'; - $line = isset($trace[$i]['line']) ? $trace[$i]['line'] : 'n/a'; + $class = $trace[$i]['class'] ?? ''; + $type = $trace[$i]['type'] ?? ''; + $function = $trace[$i]['function'] ?? ''; + $file = $trace[$i]['file'] ?? 'n/a'; + $line = $trace[$i]['line'] ?? 'n/a'; $output->writeln(sprintf(' %s%s at %s:%s', $class, $function ? $type.$function.'()' : '', $file, $line), OutputInterface::VERBOSITY_QUIET); } diff --git a/Descriptor/ApplicationDescription.php b/Descriptor/ApplicationDescription.php index 3192c0f6f..3970b9000 100644 --- a/Descriptor/ApplicationDescription.php +++ b/Descriptor/ApplicationDescription.php @@ -80,7 +80,7 @@ public function getCommand(string $name): Command throw new CommandNotFoundException(sprintf('Command "%s" does not exist.', $name)); } - return isset($this->commands[$name]) ? $this->commands[$name] : $this->aliases[$name]; + return $this->commands[$name] ?? $this->aliases[$name]; } private function inspectApplication() diff --git a/Descriptor/JsonDescriptor.php b/Descriptor/JsonDescriptor.php index 5ba588ee9..4c09e1267 100644 --- a/Descriptor/JsonDescriptor.php +++ b/Descriptor/JsonDescriptor.php @@ -63,7 +63,7 @@ protected function describeCommand(Command $command, array $options = []) */ protected function describeApplication(Application $application, array $options = []) { - $describedNamespace = isset($options['namespace']) ? $options['namespace'] : null; + $describedNamespace = $options['namespace'] ?? null; $description = new ApplicationDescription($application, $describedNamespace, true); $commands = []; @@ -95,7 +95,7 @@ protected function describeApplication(Application $application, array $options */ private function writeData(array $data, array $options) { - $flags = isset($options['json_encoding']) ? $options['json_encoding'] : 0; + $flags = $options['json_encoding'] ?? 0; $this->write(json_encode($data, $flags)); } diff --git a/Descriptor/MarkdownDescriptor.php b/Descriptor/MarkdownDescriptor.php index 02b8c3012..9a9d28075 100644 --- a/Descriptor/MarkdownDescriptor.php +++ b/Descriptor/MarkdownDescriptor.php @@ -143,7 +143,7 @@ protected function describeCommand(Command $command, array $options = []) */ protected function describeApplication(Application $application, array $options = []) { - $describedNamespace = isset($options['namespace']) ? $options['namespace'] : null; + $describedNamespace = $options['namespace'] ?? null; $description = new ApplicationDescription($application, $describedNamespace); $title = $this->getApplicationTitle($application); diff --git a/Descriptor/TextDescriptor.php b/Descriptor/TextDescriptor.php index 05a32443d..1db3686be 100644 --- a/Descriptor/TextDescriptor.php +++ b/Descriptor/TextDescriptor.php @@ -39,7 +39,7 @@ protected function describeInputArgument(InputArgument $argument, array $options $default = ''; } - $totalWidth = isset($options['total_width']) ? $options['total_width'] : Helper::strlen($argument->getName()); + $totalWidth = $options['total_width'] ?? Helper::strlen($argument->getName()); $spacingWidth = $totalWidth - \strlen($argument->getName()); $this->writeText(sprintf(' %s %s%s%s', @@ -71,7 +71,7 @@ protected function describeInputOption(InputOption $option, array $options = []) } } - $totalWidth = isset($options['total_width']) ? $options['total_width'] : $this->calculateTotalWidthForOptions([$option]); + $totalWidth = $options['total_width'] ?? $this->calculateTotalWidthForOptions([$option]); $synopsis = sprintf('%s%s', $option->getShortcut() ? sprintf('-%s, ', $option->getShortcut()) : ' ', sprintf('--%s%s', $option->getName(), $value) @@ -176,7 +176,7 @@ protected function describeCommand(Command $command, array $options = []) */ protected function describeApplication(Application $application, array $options = []) { - $describedNamespace = isset($options['namespace']) ? $options['namespace'] : null; + $describedNamespace = $options['namespace'] ?? null; $description = new ApplicationDescription($application, $describedNamespace); if (isset($options['raw_text']) && $options['raw_text']) { diff --git a/Descriptor/XmlDescriptor.php b/Descriptor/XmlDescriptor.php index 3d5dce1d6..a6288d44f 100644 --- a/Descriptor/XmlDescriptor.php +++ b/Descriptor/XmlDescriptor.php @@ -152,7 +152,7 @@ protected function describeCommand(Command $command, array $options = []) */ protected function describeApplication(Application $application, array $options = []) { - $this->writeDocument($this->getApplicationDocument($application, isset($options['namespace']) ? $options['namespace'] : null)); + $this->writeDocument($this->getApplicationDocument($application, $options['namespace'] ?? null)); } /** diff --git a/Formatter/OutputFormatter.php b/Formatter/OutputFormatter.php index 26288ce62..fa4189d04 100644 --- a/Formatter/OutputFormatter.php +++ b/Formatter/OutputFormatter.php @@ -163,7 +163,7 @@ public function formatAndWrap(string $message, int $width) if ($open = '/' != $text[1]) { $tag = $matches[1][$i][0]; } else { - $tag = isset($matches[3][$i][0]) ? $matches[3][$i][0] : ''; + $tag = $matches[3][$i][0] ?? ''; } if (!$open && !$tag) { diff --git a/Helper/ProgressBar.php b/Helper/ProgressBar.php index afabf7c52..4690cffbd 100644 --- a/Helper/ProgressBar.php +++ b/Helper/ProgressBar.php @@ -110,7 +110,7 @@ public static function getPlaceholderFormatterDefinition(string $name): ?callabl self::$formatters = self::initPlaceholderFormatters(); } - return isset(self::$formatters[$name]) ? self::$formatters[$name] : null; + return self::$formatters[$name] ?? null; } /** @@ -143,7 +143,7 @@ public static function getFormatDefinition(string $name): ?string self::$formats = self::initFormats(); } - return isset(self::$formats[$name]) ? self::$formats[$name] : null; + return self::$formats[$name] ?? null; } /** diff --git a/Helper/ProgressIndicator.php b/Helper/ProgressIndicator.php index 04db8f7c1..c189ba804 100644 --- a/Helper/ProgressIndicator.php +++ b/Helper/ProgressIndicator.php @@ -149,7 +149,7 @@ public static function getFormatDefinition($name) self::$formats = self::initFormats(); } - return isset(self::$formats[$name]) ? self::$formats[$name] : null; + return self::$formats[$name] ?? null; } /** @@ -182,7 +182,7 @@ public static function getPlaceholderFormatterDefinition($name) self::$formatters = self::initPlaceholderFormatters(); } - return isset(self::$formatters[$name]) ? self::$formatters[$name] : null; + return self::$formatters[$name] ?? null; } private function display() diff --git a/Helper/QuestionHelper.php b/Helper/QuestionHelper.php index 18a222db3..e7ea00555 100644 --- a/Helper/QuestionHelper.php +++ b/Helper/QuestionHelper.php @@ -170,13 +170,13 @@ private function getDefaultAnswer(Question $question) $choices = $question->getChoices(); if (!$question->isMultiselect()) { - return isset($choices[$default]) ? $choices[$default] : $default; + return $choices[$default] ?? $default; } $default = explode(',', $default); foreach ($default as $k => $v) { $v = $question->isTrimmable() ? trim($v) : $v; - $default[$k] = isset($choices[$v]) ? $choices[$v] : $v; + $default[$k] = $choices[$v] ?? $v; } } diff --git a/Helper/SymfonyQuestionHelper.php b/Helper/SymfonyQuestionHelper.php index e4e87b2f9..ace5e1868 100644 --- a/Helper/SymfonyQuestionHelper.php +++ b/Helper/SymfonyQuestionHelper.php @@ -58,7 +58,7 @@ protected function writePrompt(OutputInterface $output, Question $question) case $question instanceof ChoiceQuestion: $choices = $question->getChoices(); - $text = sprintf(' %s [%s]:', $text, OutputFormatter::escape(isset($choices[$default]) ? $choices[$default] : $default)); + $text = sprintf(' %s [%s]:', $text, OutputFormatter::escape($choices[$default] ?? $default)); break; diff --git a/Helper/Table.php b/Helper/Table.php index facffa683..e7a9b6ccb 100644 --- a/Helper/Table.php +++ b/Helper/Table.php @@ -503,7 +503,7 @@ private function renderRow(array $row, string $cellFormat, string $firstCellForm */ private function renderCell(array $row, int $column, string $cellFormat): string { - $cell = isset($row[$column]) ? $row[$column] : ''; + $cell = $row[$column] ?? ''; $width = $this->effectiveColumnWidths[$column]; if ($cell instanceof TableCell && $cell->getColspan() > 1) { // add the width of the following columns(numbers of colspan). @@ -637,7 +637,7 @@ private function fillNextRows(array $rows, int $line): array // create a two dimensional array (rowspan x colspan) $unmergedRows = array_replace_recursive(array_fill($line + 1, $nbLines, []), $unmergedRows); foreach ($unmergedRows as $unmergedRowKey => $unmergedRow) { - $value = isset($lines[$unmergedRowKey - $line]) ? $lines[$unmergedRowKey - $line] : ''; + $value = $lines[$unmergedRowKey - $line] ?? ''; $unmergedRows[$unmergedRowKey][$column] = new TableCell($value, ['colspan' => $cell->getColspan()]); if ($nbLines === $unmergedRowKey - $line) { break; @@ -775,7 +775,7 @@ private function getCellWidth(array $row, int $column): int $cellWidth = Helper::strlenWithoutDecoration($this->output->getFormatter(), $cell); } - $columnWidth = isset($this->columnWidths[$column]) ? $this->columnWidths[$column] : 0; + $columnWidth = $this->columnWidths[$column] ?? 0; $cellWidth = max($cellWidth, $columnWidth); return isset($this->columnMaxWidths[$column]) ? min($this->columnMaxWidths[$column], $cellWidth) : $cellWidth; diff --git a/Input/Input.php b/Input/Input.php index c1220316d..6e4c01e95 100644 --- a/Input/Input.php +++ b/Input/Input.php @@ -110,7 +110,7 @@ public function getArgument($name) throw new InvalidArgumentException(sprintf('The "%s" argument does not exist.', $name)); } - return isset($this->arguments[$name]) ? $this->arguments[$name] : $this->definition->getArgument($name)->getDefault(); + return $this->arguments[$name] ?? $this->definition->getArgument($name)->getDefault(); } /** diff --git a/Style/SymfonyStyle.php b/Style/SymfonyStyle.php index b247b357d..2056f04c9 100644 --- a/Style/SymfonyStyle.php +++ b/Style/SymfonyStyle.php @@ -295,7 +295,7 @@ public function choice($question, array $choices, $default = null) { if (null !== $default) { $values = array_flip($choices); - $default = isset($values[$default]) ? $values[$default] : $default; + $default = $values[$default] ?? $default; } return $this->askQuestion(new ChoiceQuestion($question, $choices, $default)); diff --git a/Tester/TesterTrait.php b/Tester/TesterTrait.php index 14b65ec00..27d598559 100644 --- a/Tester/TesterTrait.php +++ b/Tester/TesterTrait.php @@ -141,8 +141,8 @@ private function initOutput(array $options) } } else { $this->output = new ConsoleOutput( - isset($options['verbosity']) ? $options['verbosity'] : ConsoleOutput::VERBOSITY_NORMAL, - isset($options['decorated']) ? $options['decorated'] : null + $options['verbosity'] ?? ConsoleOutput::VERBOSITY_NORMAL, + $options['decorated'] ?? null ); $errorOutput = new StreamOutput(fopen('php://memory', 'w', false)); From bee31b39c227c424870c0d5b7a6361f82c98c6f7 Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Tue, 29 Dec 2020 08:39:20 +0100 Subject: [PATCH 02/15] Add reference link --- Command/Command.php | 1 + 1 file changed, 1 insertion(+) diff --git a/Command/Command.php b/Command/Command.php index bcb86cdfb..ab0312065 100644 --- a/Command/Command.php +++ b/Command/Command.php @@ -29,6 +29,7 @@ */ class Command { + // see https://tldp.org/LDP/abs/html/exitcodes.html public const SUCCESS = 0; public const FAILURE = 1; From 0a748fef38647053d3a622cb3d1aa7b285a3be68 Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Fri, 1 Jan 2021 10:24:35 +0100 Subject: [PATCH 03/15] Bump license year --- LICENSE | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/LICENSE b/LICENSE index 9e936ec04..9ff2d0d63 100644 --- a/LICENSE +++ b/LICENSE @@ -1,4 +1,4 @@ -Copyright (c) 2004-2020 Fabien Potencier +Copyright (c) 2004-2021 Fabien Potencier Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal From 9d2f11053a0e6acf3768f16ad033be92a0f7fba9 Mon Sep 17 00:00:00 2001 From: Christian Flothmann Date: Mon, 4 Jan 2021 16:44:05 +0100 Subject: [PATCH 04/15] fix code style --- Tests/Fixtures/DummyOutput.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Tests/Fixtures/DummyOutput.php b/Tests/Fixtures/DummyOutput.php index 96de7e718..44b39e30b 100644 --- a/Tests/Fixtures/DummyOutput.php +++ b/Tests/Fixtures/DummyOutput.php @@ -23,7 +23,7 @@ class DummyOutput extends BufferedOutput public function getLogs(): array { $logs = []; - foreach (explode(PHP_EOL, trim($this->fetch())) as $message) { + foreach (explode(\PHP_EOL, trim($this->fetch())) as $message) { preg_match('/^\[(.*)\] (.*)/', $message, $matches); $logs[] = sprintf('%s %s', $matches[1], $matches[2]); } From 410aab8acfdb7e233904e4d52b93f4e12fcec1b6 Mon Sep 17 00:00:00 2001 From: Christian Flothmann Date: Tue, 5 Jan 2021 10:01:01 +0100 Subject: [PATCH 05/15] fix code style --- Tests/SignalRegistry/SignalRegistryTest.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Tests/SignalRegistry/SignalRegistryTest.php b/Tests/SignalRegistry/SignalRegistryTest.php index 56f7d4444..f1ac7c690 100644 --- a/Tests/SignalRegistry/SignalRegistryTest.php +++ b/Tests/SignalRegistry/SignalRegistryTest.php @@ -26,7 +26,7 @@ protected function tearDown(): void pcntl_signal(\SIGUSR2, \SIG_DFL); } - public function testOneCallbackForASignal_signalIsHandled() + public function testOneCallbackForASignalSignalIsHandled() { $signalRegistry = new SignalRegistry(); @@ -40,7 +40,7 @@ public function testOneCallbackForASignal_signalIsHandled() $this->assertTrue($isHandled); } - public function testTwoCallbacksForASignal_bothCallbacksAreCalled() + public function testTwoCallbacksForASignalBothCallbacksAreCalled() { $signalRegistry = new SignalRegistry(); @@ -60,7 +60,7 @@ public function testTwoCallbacksForASignal_bothCallbacksAreCalled() $this->assertTrue($isHandled2); } - public function testTwoSignals_signalsAreHandled() + public function testTwoSignalsSignalsAreHandled() { $signalRegistry = new SignalRegistry(); @@ -85,7 +85,7 @@ public function testTwoSignals_signalsAreHandled() $this->assertTrue($isHandled2); } - public function testTwoCallbacksForASignal_previousAndRegisteredCallbacksWereCalled() + public function testTwoCallbacksForASignalPreviousAndRegisteredCallbacksWereCalled() { $signalRegistry = new SignalRegistry(); @@ -105,7 +105,7 @@ public function testTwoCallbacksForASignal_previousAndRegisteredCallbacksWereCal $this->assertTrue($isHandled2); } - public function testTwoCallbacksForASignal_previousCallbackFromAnotherRegistry() + public function testTwoCallbacksForASignalPreviousCallbackFromAnotherRegistry() { $signalRegistry1 = new SignalRegistry(); From 86b7a16658f526c4d9565bb0d03e5b8e2a5c98b7 Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Sun, 10 Jan 2021 09:16:05 +0100 Subject: [PATCH 06/15] Improve composer.json descriptions --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 3e51d14ab..5c573df2b 100644 --- a/composer.json +++ b/composer.json @@ -1,7 +1,7 @@ { "name": "symfony/console", "type": "library", - "description": "Symfony Console Component", + "description": "Eases the creation of beautiful and testable command line interfaces", "keywords": [], "homepage": "https://symfony.com/", "license": "MIT", From 7c54862f7b8823caec628f637094382cba7f0333 Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Sun, 10 Jan 2021 13:29:43 +0100 Subject: [PATCH 07/15] Use ::class keyword when possible --- Tests/ApplicationTest.php | 2 +- Tests/Formatter/OutputFormatterStyleTest.php | 4 ++-- Tests/Helper/HelperSetTest.php | 5 +++-- Tests/Helper/QuestionHelperTest.php | 3 ++- 4 files changed, 8 insertions(+), 6 deletions(-) diff --git a/Tests/ApplicationTest.php b/Tests/ApplicationTest.php index c62ac5b3e..8361635ae 100644 --- a/Tests/ApplicationTest.php +++ b/Tests/ApplicationTest.php @@ -777,7 +777,7 @@ public function testSetCatchExceptions() $tester->run(['command' => 'foo'], ['decorated' => false]); $this->fail('->setCatchExceptions() sets the catch exception flag'); } catch (\Exception $e) { - $this->assertInstanceOf('\Exception', $e, '->setCatchExceptions() sets the catch exception flag'); + $this->assertInstanceOf(\Exception::class, $e, '->setCatchExceptions() sets the catch exception flag'); $this->assertEquals('Command "foo" is not defined.', $e->getMessage(), '->setCatchExceptions() sets the catch exception flag'); } } diff --git a/Tests/Formatter/OutputFormatterStyleTest.php b/Tests/Formatter/OutputFormatterStyleTest.php index 2bcbe5194..7c1a42230 100644 --- a/Tests/Formatter/OutputFormatterStyleTest.php +++ b/Tests/Formatter/OutputFormatterStyleTest.php @@ -85,7 +85,7 @@ public function testOptions() $style->setOption('foo'); $this->fail('->setOption() throws an \InvalidArgumentException when the option does not exist in the available options'); } catch (\Exception $e) { - $this->assertInstanceOf('\InvalidArgumentException', $e, '->setOption() throws an \InvalidArgumentException when the option does not exist in the available options'); + $this->assertInstanceOf(\InvalidArgumentException::class, $e, '->setOption() throws an \InvalidArgumentException when the option does not exist in the available options'); $this->assertStringContainsString('Invalid option specified: "foo"', $e->getMessage(), '->setOption() throws an \InvalidArgumentException when the option does not exist in the available options'); } @@ -93,7 +93,7 @@ public function testOptions() $style->unsetOption('foo'); $this->fail('->unsetOption() throws an \InvalidArgumentException when the option does not exist in the available options'); } catch (\Exception $e) { - $this->assertInstanceOf('\InvalidArgumentException', $e, '->unsetOption() throws an \InvalidArgumentException when the option does not exist in the available options'); + $this->assertInstanceOf(\InvalidArgumentException::class, $e, '->unsetOption() throws an \InvalidArgumentException when the option does not exist in the available options'); $this->assertStringContainsString('Invalid option specified: "foo"', $e->getMessage(), '->unsetOption() throws an \InvalidArgumentException when the option does not exist in the available options'); } } diff --git a/Tests/Helper/HelperSetTest.php b/Tests/Helper/HelperSetTest.php index d608f7bfd..9a8ca07bc 100644 --- a/Tests/Helper/HelperSetTest.php +++ b/Tests/Helper/HelperSetTest.php @@ -13,6 +13,7 @@ use PHPUnit\Framework\TestCase; use Symfony\Component\Console\Command\Command; +use Symfony\Component\Console\Helper\HelperInterface; use Symfony\Component\Console\Helper\HelperSet; class HelperSetTest extends TestCase @@ -66,7 +67,7 @@ public function testGet() $helperset->get('foo'); $this->fail('->get() throws InvalidArgumentException when helper not found'); } catch (\Exception $e) { - $this->assertInstanceOf('\InvalidArgumentException', $e, '->get() throws InvalidArgumentException when helper not found'); + $this->assertInstanceOf(\InvalidArgumentException::class, $e, '->get() throws InvalidArgumentException when helper not found'); $this->assertInstanceOf('Symfony\Component\Console\Exception\ExceptionInterface', $e, '->get() throws domain specific exception when helper not found'); $this->assertStringContainsString('The helper "foo" is not defined.', $e->getMessage(), '->get() throws InvalidArgumentException when helper not found'); } @@ -111,7 +112,7 @@ public function testIteration() private function getGenericMockHelper($name, HelperSet $helperset = null) { - $mock_helper = $this->getMockBuilder('\Symfony\Component\Console\Helper\HelperInterface')->getMock(); + $mock_helper = $this->getMockBuilder(HelperInterface::class)->getMock(); $mock_helper->expects($this->any()) ->method('getName') ->willReturn($name); diff --git a/Tests/Helper/QuestionHelperTest.php b/Tests/Helper/QuestionHelperTest.php index 094559e8c..871524e44 100644 --- a/Tests/Helper/QuestionHelperTest.php +++ b/Tests/Helper/QuestionHelperTest.php @@ -17,6 +17,7 @@ use Symfony\Component\Console\Helper\FormatterHelper; use Symfony\Component\Console\Helper\HelperSet; use Symfony\Component\Console\Helper\QuestionHelper; +use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Output\StreamOutput; use Symfony\Component\Console\Question\ChoiceQuestion; use Symfony\Component\Console\Question\ConfirmationQuestion; @@ -684,7 +685,7 @@ public function testChoiceOutputFormattingQuestionForUtf8Keys() ' [żółw ] bar', ' [łabądź] baz', ]; - $output = $this->getMockBuilder('\Symfony\Component\Console\Output\OutputInterface')->getMock(); + $output = $this->getMockBuilder(OutputInterface::class)->getMock(); $output->method('getFormatter')->willReturn(new OutputFormatter()); $dialog = new QuestionHelper(); From 096c4d37e79f70bbac78424468b19878f96e987f Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Mon, 11 Jan 2021 09:47:58 +0100 Subject: [PATCH 08/15] Use ::class keyword when possible --- Tests/ApplicationTest.php | 114 +++++++++--------- Tests/Command/CommandTest.php | 12 +- .../ContainerCommandLoaderTest.php | 2 +- .../FactoryCommandLoaderTest.php | 2 +- .../AddConsoleCommandPassTest.php | 6 +- .../OutputFormatterStyleStackTest.php | 2 +- Tests/Formatter/OutputFormatterStyleTest.php | 4 +- Tests/Helper/HelperSetTest.php | 2 +- Tests/Helper/ProgressIndicatorTest.php | 8 +- Tests/Helper/QuestionHelperTest.php | 12 +- Tests/Helper/SymfonyQuestionHelperTest.php | 4 +- Tests/Helper/TableStyleTest.php | 2 +- Tests/Helper/TableTest.php | 8 +- Tests/Input/ArgvInputTest.php | 2 +- Tests/Input/ArrayInputTest.php | 2 +- Tests/Input/InputArgumentTest.php | 6 +- Tests/Input/InputDefinitionTest.php | 18 +-- Tests/Input/InputOptionTest.php | 14 +-- Tests/Input/InputTest.php | 12 +- Tests/Input/StringInputTest.php | 2 +- Tests/Logger/ConsoleLoggerTest.php | 4 +- Tests/Output/StreamOutputTest.php | 2 +- Tests/Tester/CommandTesterTest.php | 4 +- 23 files changed, 122 insertions(+), 122 deletions(-) diff --git a/Tests/ApplicationTest.php b/Tests/ApplicationTest.php index 8361635ae..004b40955 100644 --- a/Tests/ApplicationTest.php +++ b/Tests/ApplicationTest.php @@ -134,7 +134,7 @@ public function testAll() { $application = new Application(); $commands = $application->all(); - $this->assertInstanceOf('Symfony\\Component\\Console\\Command\\HelpCommand', $commands['help'], '->all() returns the registered commands'); + $this->assertInstanceOf(\Symfony\Component\Console\Command\HelpCommand::class, $commands['help'], '->all() returns the registered commands'); $application->add(new \FooCommand()); $commands = $application->all('foo'); @@ -145,7 +145,7 @@ public function testAllWithCommandLoader() { $application = new Application(); $commands = $application->all(); - $this->assertInstanceOf('Symfony\\Component\\Console\\Command\\HelpCommand', $commands['help'], '->all() returns the registered commands'); + $this->assertInstanceOf(\Symfony\Component\Console\Command\HelpCommand::class, $commands['help'], '->all() returns the registered commands'); $application->add(new \FooCommand()); $commands = $application->all('foo'); @@ -204,7 +204,7 @@ public function testAdd() public function testAddCommandWithEmptyConstructor() { - $this->expectException('LogicException'); + $this->expectException(\LogicException::class); $this->expectExceptionMessage('Command class "Foo5Command" is not correctly initialized. You probably forgot to call the parent constructor.'); $application = new Application(); $application->add(new \Foo5Command()); @@ -229,7 +229,7 @@ public function testHasGet() $p->setAccessible(true); $p->setValue($application, true); $command = $application->get('foo:bar'); - $this->assertInstanceOf('Symfony\Component\Console\Command\HelpCommand', $command, '->get() returns the help command if --help is provided as the input'); + $this->assertInstanceOf(\Symfony\Component\Console\Command\HelpCommand::class, $command, '->get() returns the help command if --help is provided as the input'); } public function testHasGetWithCommandLoader() @@ -270,7 +270,7 @@ public function testSilentHelp() public function testGetInvalidCommand() { - $this->expectException('Symfony\Component\Console\Exception\CommandNotFoundException'); + $this->expectException(CommandNotFoundException::class); $this->expectExceptionMessage('The command "foofoo" does not exist.'); $application = new Application(); $application->get('foofoo'); @@ -327,7 +327,7 @@ public function testFindNonAmbiguous() public function testFindInvalidNamespace() { - $this->expectException('Symfony\Component\Console\Exception\NamespaceNotFoundException'); + $this->expectException(NamespaceNotFoundException::class); $this->expectExceptionMessage('There are no commands defined in the "bar" namespace.'); $application = new Application(); $application->findNamespace('bar'); @@ -335,7 +335,7 @@ public function testFindInvalidNamespace() public function testFindUniqueNameButNamespaceName() { - $this->expectException('Symfony\Component\Console\Exception\CommandNotFoundException'); + $this->expectException(CommandNotFoundException::class); $this->expectExceptionMessage('Command "foo1" is not defined'); $application = new Application(); $application->add(new \FooCommand()); @@ -350,11 +350,11 @@ public function testFind() $application = new Application(); $application->add(new \FooCommand()); - $this->assertInstanceOf('FooCommand', $application->find('foo:bar'), '->find() returns a command if its name exists'); - $this->assertInstanceOf('Symfony\Component\Console\Command\HelpCommand', $application->find('h'), '->find() returns a command if its name exists'); - $this->assertInstanceOf('FooCommand', $application->find('f:bar'), '->find() returns a command if the abbreviation for the namespace exists'); - $this->assertInstanceOf('FooCommand', $application->find('f:b'), '->find() returns a command if the abbreviation for the namespace and the command name exist'); - $this->assertInstanceOf('FooCommand', $application->find('a'), '->find() returns a command if the abbreviation exists for an alias'); + $this->assertInstanceOf(\FooCommand::class, $application->find('foo:bar'), '->find() returns a command if its name exists'); + $this->assertInstanceOf(\Symfony\Component\Console\Command\HelpCommand::class, $application->find('h'), '->find() returns a command if its name exists'); + $this->assertInstanceOf(\FooCommand::class, $application->find('f:bar'), '->find() returns a command if the abbreviation for the namespace exists'); + $this->assertInstanceOf(\FooCommand::class, $application->find('f:b'), '->find() returns a command if the abbreviation for the namespace and the command name exist'); + $this->assertInstanceOf(\FooCommand::class, $application->find('a'), '->find() returns a command if the abbreviation exists for an alias'); } public function testFindCaseSensitiveFirst() @@ -363,10 +363,10 @@ public function testFindCaseSensitiveFirst() $application->add(new \FooSameCaseUppercaseCommand()); $application->add(new \FooSameCaseLowercaseCommand()); - $this->assertInstanceOf('FooSameCaseUppercaseCommand', $application->find('f:B'), '->find() returns a command if the abbreviation is the correct case'); - $this->assertInstanceOf('FooSameCaseUppercaseCommand', $application->find('f:BAR'), '->find() returns a command if the abbreviation is the correct case'); - $this->assertInstanceOf('FooSameCaseLowercaseCommand', $application->find('f:b'), '->find() returns a command if the abbreviation is the correct case'); - $this->assertInstanceOf('FooSameCaseLowercaseCommand', $application->find('f:bar'), '->find() returns a command if the abbreviation is the correct case'); + $this->assertInstanceOf(\FooSameCaseUppercaseCommand::class, $application->find('f:B'), '->find() returns a command if the abbreviation is the correct case'); + $this->assertInstanceOf(\FooSameCaseUppercaseCommand::class, $application->find('f:BAR'), '->find() returns a command if the abbreviation is the correct case'); + $this->assertInstanceOf(\FooSameCaseLowercaseCommand::class, $application->find('f:b'), '->find() returns a command if the abbreviation is the correct case'); + $this->assertInstanceOf(\FooSameCaseLowercaseCommand::class, $application->find('f:bar'), '->find() returns a command if the abbreviation is the correct case'); } public function testFindCaseInsensitiveAsFallback() @@ -374,20 +374,20 @@ public function testFindCaseInsensitiveAsFallback() $application = new Application(); $application->add(new \FooSameCaseLowercaseCommand()); - $this->assertInstanceOf('FooSameCaseLowercaseCommand', $application->find('f:b'), '->find() returns a command if the abbreviation is the correct case'); - $this->assertInstanceOf('FooSameCaseLowercaseCommand', $application->find('f:B'), '->find() will fallback to case insensitivity'); - $this->assertInstanceOf('FooSameCaseLowercaseCommand', $application->find('FoO:BaR'), '->find() will fallback to case insensitivity'); + $this->assertInstanceOf(\FooSameCaseLowercaseCommand::class, $application->find('f:b'), '->find() returns a command if the abbreviation is the correct case'); + $this->assertInstanceOf(\FooSameCaseLowercaseCommand::class, $application->find('f:B'), '->find() will fallback to case insensitivity'); + $this->assertInstanceOf(\FooSameCaseLowercaseCommand::class, $application->find('FoO:BaR'), '->find() will fallback to case insensitivity'); } public function testFindCaseInsensitiveSuggestions() { - $this->expectException('Symfony\Component\Console\Exception\CommandNotFoundException'); + $this->expectException(CommandNotFoundException::class); $this->expectExceptionMessage('Command "FoO:BaR" is ambiguous'); $application = new Application(); $application->add(new \FooSameCaseLowercaseCommand()); $application->add(new \FooSameCaseUppercaseCommand()); - $this->assertInstanceOf('FooSameCaseLowercaseCommand', $application->find('FoO:BaR'), '->find() will find two suggestions with case insensitivity'); + $this->assertInstanceOf(\FooSameCaseLowercaseCommand::class, $application->find('FoO:BaR'), '->find() will find two suggestions with case insensitivity'); } public function testFindWithCommandLoader() @@ -397,11 +397,11 @@ public function testFindWithCommandLoader() 'foo:bar' => $f = function () { return new \FooCommand(); }, ])); - $this->assertInstanceOf('FooCommand', $application->find('foo:bar'), '->find() returns a command if its name exists'); - $this->assertInstanceOf('Symfony\Component\Console\Command\HelpCommand', $application->find('h'), '->find() returns a command if its name exists'); - $this->assertInstanceOf('FooCommand', $application->find('f:bar'), '->find() returns a command if the abbreviation for the namespace exists'); - $this->assertInstanceOf('FooCommand', $application->find('f:b'), '->find() returns a command if the abbreviation for the namespace and the command name exist'); - $this->assertInstanceOf('FooCommand', $application->find('a'), '->find() returns a command if the abbreviation exists for an alias'); + $this->assertInstanceOf(\FooCommand::class, $application->find('foo:bar'), '->find() returns a command if its name exists'); + $this->assertInstanceOf(\Symfony\Component\Console\Command\HelpCommand::class, $application->find('h'), '->find() returns a command if its name exists'); + $this->assertInstanceOf(\FooCommand::class, $application->find('f:bar'), '->find() returns a command if the abbreviation for the namespace exists'); + $this->assertInstanceOf(\FooCommand::class, $application->find('f:b'), '->find() returns a command if the abbreviation for the namespace and the command name exist'); + $this->assertInstanceOf(\FooCommand::class, $application->find('a'), '->find() returns a command if the abbreviation exists for an alias'); } /** @@ -410,7 +410,7 @@ public function testFindWithCommandLoader() public function testFindWithAmbiguousAbbreviations($abbreviation, $expectedExceptionMessage) { putenv('COLUMNS=120'); - $this->expectException('Symfony\Component\Console\Exception\CommandNotFoundException'); + $this->expectException(CommandNotFoundException::class); $this->expectExceptionMessage($expectedExceptionMessage); $application = new Application(); @@ -449,7 +449,7 @@ public function testFindWithAmbiguousAbbreviationsFindsCommandIfAlternativesAreH $application->add(new \FooCommand()); $application->add(new \FooHiddenCommand()); - $this->assertInstanceOf('FooCommand', $application->find('foo:')); + $this->assertInstanceOf(\FooCommand::class, $application->find('foo:')); } public function testFindCommandEqualNamespace() @@ -458,8 +458,8 @@ public function testFindCommandEqualNamespace() $application->add(new \Foo3Command()); $application->add(new \Foo4Command()); - $this->assertInstanceOf('Foo3Command', $application->find('foo3:bar'), '->find() returns the good command even if a namespace has same name'); - $this->assertInstanceOf('Foo4Command', $application->find('foo3:bar:toh'), '->find() returns a command even if its namespace equals another command name'); + $this->assertInstanceOf(\Foo3Command::class, $application->find('foo3:bar'), '->find() returns the good command even if a namespace has same name'); + $this->assertInstanceOf(\Foo4Command::class, $application->find('foo3:bar:toh'), '->find() returns a command even if its namespace equals another command name'); } public function testFindCommandWithAmbiguousNamespacesButUniqueName() @@ -468,7 +468,7 @@ public function testFindCommandWithAmbiguousNamespacesButUniqueName() $application->add(new \FooCommand()); $application->add(new \FoobarCommand()); - $this->assertInstanceOf('FoobarCommand', $application->find('f:f')); + $this->assertInstanceOf(\FoobarCommand::class, $application->find('f:f')); } public function testFindCommandWithMissingNamespace() @@ -476,7 +476,7 @@ public function testFindCommandWithMissingNamespace() $application = new Application(); $application->add(new \Foo4Command()); - $this->assertInstanceOf('Foo4Command', $application->find('f::t')); + $this->assertInstanceOf(\Foo4Command::class, $application->find('f::t')); } /** @@ -484,7 +484,7 @@ public function testFindCommandWithMissingNamespace() */ public function testFindAlternativeExceptionMessageSingle($name) { - $this->expectException('Symfony\Component\Console\Exception\CommandNotFoundException'); + $this->expectException(CommandNotFoundException::class); $this->expectExceptionMessage('Did you mean this'); $application = new Application(); $application->add(new \Foo3Command()); @@ -558,7 +558,7 @@ public function testFindAlternativeExceptionMessageMultiple() $application->find('foo:baR'); $this->fail('->find() throws a CommandNotFoundException if command does not exist, with alternatives'); } catch (\Exception $e) { - $this->assertInstanceOf('Symfony\Component\Console\Exception\CommandNotFoundException', $e, '->find() throws a CommandNotFoundException if command does not exist, with alternatives'); + $this->assertInstanceOf(CommandNotFoundException::class, $e, '->find() throws a CommandNotFoundException if command does not exist, with alternatives'); $this->assertMatchesRegularExpression('/Did you mean one of these/', $e->getMessage(), '->find() throws a CommandNotFoundException if command does not exist, with alternatives'); $this->assertMatchesRegularExpression('/foo1:bar/', $e->getMessage()); $this->assertMatchesRegularExpression('/foo:bar/', $e->getMessage()); @@ -569,7 +569,7 @@ public function testFindAlternativeExceptionMessageMultiple() $application->find('foo2:bar'); $this->fail('->find() throws a CommandNotFoundException if command does not exist, with alternatives'); } catch (\Exception $e) { - $this->assertInstanceOf('Symfony\Component\Console\Exception\CommandNotFoundException', $e, '->find() throws a CommandNotFoundException if command does not exist, with alternatives'); + $this->assertInstanceOf(CommandNotFoundException::class, $e, '->find() throws a CommandNotFoundException if command does not exist, with alternatives'); $this->assertMatchesRegularExpression('/Did you mean one of these/', $e->getMessage(), '->find() throws a CommandNotFoundException if command does not exist, with alternatives'); $this->assertMatchesRegularExpression('/foo1/', $e->getMessage()); } @@ -582,7 +582,7 @@ public function testFindAlternativeExceptionMessageMultiple() $application->find('foo3:'); $this->fail('->find() should throw an Symfony\Component\Console\Exception\CommandNotFoundException if a command is ambiguous because of a subnamespace, with alternatives'); } catch (\Exception $e) { - $this->assertInstanceOf('Symfony\Component\Console\Exception\CommandNotFoundException', $e); + $this->assertInstanceOf(CommandNotFoundException::class, $e); $this->assertMatchesRegularExpression('/foo3:bar/', $e->getMessage()); $this->assertMatchesRegularExpression('/foo3:bar:toh/', $e->getMessage()); } @@ -600,7 +600,7 @@ public function testFindAlternativeCommands() $application->find($commandName = 'Unknown command'); $this->fail('->find() throws a CommandNotFoundException if command does not exist'); } catch (\Exception $e) { - $this->assertInstanceOf('Symfony\Component\Console\Exception\CommandNotFoundException', $e, '->find() throws a CommandNotFoundException if command does not exist'); + $this->assertInstanceOf(CommandNotFoundException::class, $e, '->find() throws a CommandNotFoundException if command does not exist'); $this->assertSame([], $e->getAlternatives()); $this->assertEquals(sprintf('Command "%s" is not defined.', $commandName), $e->getMessage(), '->find() throws a CommandNotFoundException if command does not exist, without alternatives'); } @@ -611,7 +611,7 @@ public function testFindAlternativeCommands() $application->find($commandName = 'bar1'); $this->fail('->find() throws a CommandNotFoundException if command does not exist'); } catch (\Exception $e) { - $this->assertInstanceOf('Symfony\Component\Console\Exception\CommandNotFoundException', $e, '->find() throws a CommandNotFoundException if command does not exist'); + $this->assertInstanceOf(CommandNotFoundException::class, $e, '->find() throws a CommandNotFoundException if command does not exist'); $this->assertSame(['afoobar1', 'foo:bar1'], $e->getAlternatives()); $this->assertMatchesRegularExpression(sprintf('/Command "%s" is not defined./', $commandName), $e->getMessage(), '->find() throws a CommandNotFoundException if command does not exist, with alternatives'); $this->assertMatchesRegularExpression('/afoobar1/', $e->getMessage(), '->find() throws a CommandNotFoundException if command does not exist, with alternative : "afoobar1"'); @@ -649,7 +649,7 @@ public function testFindAlternativeNamespace() $application->find('Unknown-namespace:Unknown-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(CommandNotFoundException::class, $e, '->find() throws a CommandNotFoundException if namespace does not exist'); $this->assertSame([], $e->getAlternatives()); $this->assertEquals('There are no commands defined in the "Unknown-namespace" namespace.', $e->getMessage(), '->find() throws a CommandNotFoundException if namespace does not exist, without alternatives'); } @@ -658,8 +658,8 @@ public function testFindAlternativeNamespace() $application->find('foo2:command'); $this->fail('->find() throws a CommandNotFoundException if namespace does not exist'); } catch (\Exception $e) { - $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->assertInstanceOf(NamespaceNotFoundException::class, $e, '->find() throws a NamespaceNotFoundException if namespace does not exist'); + $this->assertInstanceOf(CommandNotFoundException::class, $e, 'NamespaceNotFoundException extends from CommandNotFoundException'); $this->assertCount(3, $e->getAlternatives()); $this->assertContains('foo', $e->getAlternatives()); $this->assertContains('foo1', $e->getAlternatives()); @@ -695,7 +695,7 @@ public function testFindAlternativesOutput() $application->find('foo'); $this->fail('->find() throws a CommandNotFoundException if command is not defined'); } catch (\Exception $e) { - $this->assertInstanceOf('Symfony\Component\Console\Exception\CommandNotFoundException', $e, '->find() throws a CommandNotFoundException if command is not defined'); + $this->assertInstanceOf(CommandNotFoundException::class, $e, '->find() throws a CommandNotFoundException if command is not defined'); $this->assertSame($expectedAlternatives, $e->getAlternatives()); $this->assertMatchesRegularExpression('/Command "foo" is not defined\..*Did you mean one of these\?.*/Ums', $e->getMessage()); @@ -704,7 +704,7 @@ public function testFindAlternativesOutput() public function testFindNamespaceDoesNotFailOnDeepSimilarNamespaces() { - $application = $this->getMockBuilder('Symfony\Component\Console\Application')->setMethods(['getNamespaces'])->getMock(); + $application = $this->getMockBuilder(Application::class)->setMethods(['getNamespaces'])->getMock(); $application->expects($this->once()) ->method('getNamespaces') ->willReturn(['foo:sublong', 'bar:sub']); @@ -714,7 +714,7 @@ public function testFindNamespaceDoesNotFailOnDeepSimilarNamespaces() public function testFindWithDoubleColonInNameThrowsException() { - $this->expectException('Symfony\Component\Console\Exception\CommandNotFoundException'); + $this->expectException(CommandNotFoundException::class); $this->expectExceptionMessage('Command "foo::bar" is not defined.'); $application = new Application(); $application->add(new \FooCommand()); @@ -727,8 +727,8 @@ public function testFindHiddenWithExactName() $application = new Application(); $application->add(new \FooHiddenCommand()); - $this->assertInstanceOf('FooHiddenCommand', $application->find('foo:hidden')); - $this->assertInstanceOf('FooHiddenCommand', $application->find('afoohidden')); + $this->assertInstanceOf(\FooHiddenCommand::class, $application->find('foo:hidden')); + $this->assertInstanceOf(\FooHiddenCommand::class, $application->find('afoohidden')); } /** @@ -878,7 +878,7 @@ public function testRenderExceptionEscapesLines() public function testRenderExceptionLineBreaks() { - $application = $this->getMockBuilder('Symfony\Component\Console\Application')->setMethods(['getTerminalWidth'])->getMock(); + $application = $this->getMockBuilder(Application::class)->setMethods(['getTerminalWidth'])->getMock(); $application->setAutoExit(false); $application->expects($this->any()) ->method('getTerminalWidth') @@ -950,8 +950,8 @@ public function testRun() $application->run(); ob_end_clean(); - $this->assertInstanceOf('Symfony\Component\Console\Input\ArgvInput', $command->input, '->run() creates an ArgvInput by default if none is given'); - $this->assertInstanceOf('Symfony\Component\Console\Output\ConsoleOutput', $command->output, '->run() creates a ConsoleOutput by default if none is given'); + $this->assertInstanceOf(ArgvInput::class, $command->input, '->run() creates an ArgvInput by default if none is given'); + $this->assertInstanceOf(\Symfony\Component\Console\Output\ConsoleOutput::class, $command->output, '->run() creates a ConsoleOutput by default if none is given'); $application = new Application(); $application->setAutoExit(false); @@ -1076,7 +1076,7 @@ public function testRunReturnsIntegerExitCode() { $exception = new \Exception('', 4); - $application = $this->getMockBuilder('Symfony\Component\Console\Application')->setMethods(['doRun'])->getMock(); + $application = $this->getMockBuilder(Application::class)->setMethods(['doRun'])->getMock(); $application->setAutoExit(false); $application->expects($this->once()) ->method('doRun') @@ -1115,7 +1115,7 @@ public function testRunReturnsExitCodeOneForExceptionCodeZero() { $exception = new \Exception('', 0); - $application = $this->getMockBuilder('Symfony\Component\Console\Application')->setMethods(['doRun'])->getMock(); + $application = $this->getMockBuilder(Application::class)->setMethods(['doRun'])->getMock(); $application->setAutoExit(false); $application->expects($this->once()) ->method('doRun') @@ -1152,7 +1152,7 @@ public function testRunDispatchesExitCodeOneForExceptionCodeZero() public function testAddingOptionWithDuplicateShortcut() { - $this->expectException('LogicException'); + $this->expectException(\LogicException::class); $this->expectExceptionMessage('An option with shortcut "e" already exists.'); $dispatcher = new EventDispatcher(); $application = new Application(); @@ -1180,7 +1180,7 @@ public function testAddingOptionWithDuplicateShortcut() */ public function testAddingAlreadySetDefinitionElementData($def) { - $this->expectException('LogicException'); + $this->expectException(\LogicException::class); $application = new Application(); $application->setAutoExit(false); $application->setCatchExceptions(false); @@ -1331,7 +1331,7 @@ public function testRunWithDispatcher() public function testRunWithExceptionAndDispatcher() { - $this->expectException('LogicException'); + $this->expectException(\LogicException::class); $this->expectExceptionMessage('error'); $application = new Application(); $application->setDispatcher($this->getDispatcher()); @@ -1474,7 +1474,7 @@ public function testErrorIsRethrownIfNotHandledByConsoleErrorEvent() public function testRunWithErrorAndDispatcher() { - $this->expectException('LogicException'); + $this->expectException(\LogicException::class); $this->expectExceptionMessage('error'); $application = new Application(); $application->setDispatcher($this->getDispatcher()); @@ -1686,7 +1686,7 @@ public function testRunLazyCommandService() public function testGetDisabledLazyCommand() { - $this->expectException('Symfony\Component\Console\Exception\CommandNotFoundException'); + $this->expectException(CommandNotFoundException::class); $application = new Application(); $application->setCommandLoader(new FactoryCommandLoader(['disabled' => function () { return new DisabledCommand(); }])); $application->get('disabled'); @@ -1779,7 +1779,7 @@ public function testErrorIsRethrownIfNotHandledByConsoleErrorEventWithCatchingEn public function testThrowingErrorListener() { - $this->expectException('RuntimeException'); + $this->expectException(\RuntimeException::class); $this->expectExceptionMessage('foo'); $dispatcher = $this->getDispatcher(); $dispatcher->addListener('console.error', function (ConsoleErrorEvent $event) { diff --git a/Tests/Command/CommandTest.php b/Tests/Command/CommandTest.php index d82b0d03a..34156f7b5 100644 --- a/Tests/Command/CommandTest.php +++ b/Tests/Command/CommandTest.php @@ -42,7 +42,7 @@ public function testConstructor() public function testCommandNameCannotBeEmpty() { - $this->expectException('LogicException'); + $this->expectException(\LogicException::class); $this->expectExceptionMessage('The command defined in "Symfony\Component\Console\Command\Command" cannot have an empty name.'); (new Application())->add(new Command()); } @@ -115,7 +115,7 @@ public function testGetNamespaceGetNameSetName() */ public function testInvalidCommandNames($name) { - $this->expectException('InvalidArgumentException'); + $this->expectException(\InvalidArgumentException::class); $this->expectExceptionMessage(sprintf('Command name "%s" is invalid.', $name)); $command = new \TestCommand(); @@ -182,7 +182,7 @@ public function testGetSetAliases() public function testSetAliasesNull() { $command = new \TestCommand(); - $this->expectException('InvalidArgumentException'); + $this->expectException(\InvalidArgumentException::class); $command->setAliases(null); } @@ -214,7 +214,7 @@ public function testGetHelper() public function testGetHelperWithoutHelperSet() { - $this->expectException('LogicException'); + $this->expectException(\LogicException::class); $this->expectExceptionMessage('Cannot retrieve helper "formatter" because there is no HelperSet defined.'); $command = new \TestCommand(); $command->getHelper('formatter'); @@ -285,7 +285,7 @@ public function testRunNonInteractive() public function testExecuteMethodNeedsToBeOverridden() { - $this->expectException('LogicException'); + $this->expectException(\LogicException::class); $this->expectExceptionMessage('You must override the execute() method in the concrete command class.'); $command = new Command('foo'); $command->run(new StringInput(''), new NullOutput()); @@ -293,7 +293,7 @@ public function testExecuteMethodNeedsToBeOverridden() public function testRunWithInvalidOption() { - $this->expectException('Symfony\Component\Console\Exception\InvalidOptionException'); + $this->expectException(\Symfony\Component\Console\Exception\InvalidOptionException::class); $this->expectExceptionMessage('The "--bar" option does not exist.'); $command = new \TestCommand(); $tester = new CommandTester($command); diff --git a/Tests/CommandLoader/ContainerCommandLoaderTest.php b/Tests/CommandLoader/ContainerCommandLoaderTest.php index 50fe125a6..67b2d5cee 100644 --- a/Tests/CommandLoader/ContainerCommandLoaderTest.php +++ b/Tests/CommandLoader/ContainerCommandLoaderTest.php @@ -43,7 +43,7 @@ public function testGet() public function testGetUnknownCommandThrows() { - $this->expectException('Symfony\Component\Console\Exception\CommandNotFoundException'); + $this->expectException(\Symfony\Component\Console\Exception\CommandNotFoundException::class); (new ContainerCommandLoader(new ServiceLocator([]), []))->get('unknown'); } diff --git a/Tests/CommandLoader/FactoryCommandLoaderTest.php b/Tests/CommandLoader/FactoryCommandLoaderTest.php index a37ad18de..8546ae669 100644 --- a/Tests/CommandLoader/FactoryCommandLoaderTest.php +++ b/Tests/CommandLoader/FactoryCommandLoaderTest.php @@ -42,7 +42,7 @@ public function testGet() public function testGetUnknownCommandThrows() { - $this->expectException('Symfony\Component\Console\Exception\CommandNotFoundException'); + $this->expectException(\Symfony\Component\Console\Exception\CommandNotFoundException::class); (new FactoryCommandLoader([]))->get('unknown'); } diff --git a/Tests/DependencyInjection/AddConsoleCommandPassTest.php b/Tests/DependencyInjection/AddConsoleCommandPassTest.php index e80880826..5e59f8fab 100644 --- a/Tests/DependencyInjection/AddConsoleCommandPassTest.php +++ b/Tests/DependencyInjection/AddConsoleCommandPassTest.php @@ -120,7 +120,7 @@ public function visibilityProvider() public function testProcessThrowAnExceptionIfTheServiceIsAbstract() { - $this->expectException('InvalidArgumentException'); + $this->expectException(\InvalidArgumentException::class); $this->expectExceptionMessage('The service "my-command" tagged "console.command" must not be abstract.'); $container = new ContainerBuilder(); $container->setResourceTracking(false); @@ -136,7 +136,7 @@ public function testProcessThrowAnExceptionIfTheServiceIsAbstract() public function testProcessThrowAnExceptionIfTheServiceIsNotASubclassOfCommand() { - $this->expectException('InvalidArgumentException'); + $this->expectException(\InvalidArgumentException::class); $this->expectExceptionMessage('The service "my-command" tagged "console.command" must be a subclass of "Symfony\Component\Console\Command\Command".'); $container = new ContainerBuilder(); $container->setResourceTracking(false); @@ -221,7 +221,7 @@ public function testProcessOnChildDefinitionWithParentClass() public function testProcessOnChildDefinitionWithoutClass() { - $this->expectException('RuntimeException'); + $this->expectException(\RuntimeException::class); $this->expectExceptionMessage('The definition for "my-child-command" has no class.'); $container = new ContainerBuilder(); $container->addCompilerPass(new AddConsoleCommandPass(), PassConfig::TYPE_BEFORE_REMOVING); diff --git a/Tests/Formatter/OutputFormatterStyleStackTest.php b/Tests/Formatter/OutputFormatterStyleStackTest.php index d3020432e..7fbe4f415 100644 --- a/Tests/Formatter/OutputFormatterStyleStackTest.php +++ b/Tests/Formatter/OutputFormatterStyleStackTest.php @@ -61,7 +61,7 @@ public function testPopNotLast() public function testInvalidPop() { - $this->expectException('InvalidArgumentException'); + $this->expectException(\InvalidArgumentException::class); $stack = new OutputFormatterStyleStack(); $stack->push(new OutputFormatterStyle('white', 'black')); $stack->pop(new OutputFormatterStyle('yellow', 'blue')); diff --git a/Tests/Formatter/OutputFormatterStyleTest.php b/Tests/Formatter/OutputFormatterStyleTest.php index 7c1a42230..00dfa19c8 100644 --- a/Tests/Formatter/OutputFormatterStyleTest.php +++ b/Tests/Formatter/OutputFormatterStyleTest.php @@ -41,7 +41,7 @@ public function testForeground() $style->setForeground('default'); $this->assertEquals("\033[39mfoo\033[39m", $style->apply('foo')); - $this->expectException('InvalidArgumentException'); + $this->expectException(\InvalidArgumentException::class); $style->setForeground('undefined-color'); } @@ -58,7 +58,7 @@ public function testBackground() $style->setBackground('default'); $this->assertEquals("\033[49mfoo\033[49m", $style->apply('foo')); - $this->expectException('InvalidArgumentException'); + $this->expectException(\InvalidArgumentException::class); $style->setBackground('undefined-color'); } diff --git a/Tests/Helper/HelperSetTest.php b/Tests/Helper/HelperSetTest.php index 9a8ca07bc..707a190cf 100644 --- a/Tests/Helper/HelperSetTest.php +++ b/Tests/Helper/HelperSetTest.php @@ -68,7 +68,7 @@ public function testGet() $this->fail('->get() throws InvalidArgumentException when helper not found'); } catch (\Exception $e) { $this->assertInstanceOf(\InvalidArgumentException::class, $e, '->get() throws InvalidArgumentException when helper not found'); - $this->assertInstanceOf('Symfony\Component\Console\Exception\ExceptionInterface', $e, '->get() throws domain specific exception when helper not found'); + $this->assertInstanceOf(\Symfony\Component\Console\Exception\ExceptionInterface::class, $e, '->get() throws domain specific exception when helper not found'); $this->assertStringContainsString('The helper "foo" is not defined.', $e->getMessage(), '->get() throws InvalidArgumentException when helper not found'); } } diff --git a/Tests/Helper/ProgressIndicatorTest.php b/Tests/Helper/ProgressIndicatorTest.php index 986646794..bbbde217c 100644 --- a/Tests/Helper/ProgressIndicatorTest.php +++ b/Tests/Helper/ProgressIndicatorTest.php @@ -102,14 +102,14 @@ public function testCustomIndicatorValues() public function testCannotSetInvalidIndicatorCharacters() { - $this->expectException('InvalidArgumentException'); + $this->expectException(\InvalidArgumentException::class); $this->expectExceptionMessage('Must have at least 2 indicator value characters.'); new ProgressIndicator($this->getOutputStream(), null, 100, ['1']); } public function testCannotStartAlreadyStartedIndicator() { - $this->expectException('LogicException'); + $this->expectException(\LogicException::class); $this->expectExceptionMessage('Progress indicator already started.'); $bar = new ProgressIndicator($this->getOutputStream()); $bar->start('Starting...'); @@ -118,7 +118,7 @@ public function testCannotStartAlreadyStartedIndicator() public function testCannotAdvanceUnstartedIndicator() { - $this->expectException('LogicException'); + $this->expectException(\LogicException::class); $this->expectExceptionMessage('Progress indicator has not yet been started.'); $bar = new ProgressIndicator($this->getOutputStream()); $bar->advance(); @@ -126,7 +126,7 @@ public function testCannotAdvanceUnstartedIndicator() public function testCannotFinishUnstartedIndicator() { - $this->expectException('LogicException'); + $this->expectException(\LogicException::class); $this->expectExceptionMessage('Progress indicator has not yet been started.'); $bar = new ProgressIndicator($this->getOutputStream()); $bar->finish('Finished'); diff --git a/Tests/Helper/QuestionHelperTest.php b/Tests/Helper/QuestionHelperTest.php index 871524e44..5db0ded77 100644 --- a/Tests/Helper/QuestionHelperTest.php +++ b/Tests/Helper/QuestionHelperTest.php @@ -633,7 +633,7 @@ public function testSelectChoiceFromChoiceList($providedAnswer, $expectedValue) public function testAmbiguousChoiceFromChoicelist() { - $this->expectException('InvalidArgumentException'); + $this->expectException(\InvalidArgumentException::class); $this->expectExceptionMessage('The provided answer is ambiguous. Value should be one of "env_2" or "env_3".'); $possibleChoices = [ 'env_1' => 'My first environment', @@ -700,7 +700,7 @@ public function testChoiceOutputFormattingQuestionForUtf8Keys() public function testAskThrowsExceptionOnMissingInput() { - $this->expectException('Symfony\Component\Console\Exception\MissingInputException'); + $this->expectException(\Symfony\Component\Console\Exception\MissingInputException::class); $this->expectExceptionMessage('Aborted.'); $dialog = new QuestionHelper(); $dialog->ask($this->createStreamableInputInterfaceMock($this->getInputStream('')), $this->createOutputInterface(), new Question('What\'s your name?')); @@ -708,7 +708,7 @@ public function testAskThrowsExceptionOnMissingInput() public function testAskThrowsExceptionOnMissingInputForChoiceQuestion() { - $this->expectException('Symfony\Component\Console\Exception\MissingInputException'); + $this->expectException(\Symfony\Component\Console\Exception\MissingInputException::class); $this->expectExceptionMessage('Aborted.'); $dialog = new QuestionHelper(); $dialog->ask($this->createStreamableInputInterfaceMock($this->getInputStream('')), $this->createOutputInterface(), new ChoiceQuestion('Choice', ['a', 'b'])); @@ -716,7 +716,7 @@ public function testAskThrowsExceptionOnMissingInputForChoiceQuestion() public function testAskThrowsExceptionOnMissingInputWithValidator() { - $this->expectException('Symfony\Component\Console\Exception\MissingInputException'); + $this->expectException(\Symfony\Component\Console\Exception\MissingInputException::class); $this->expectExceptionMessage('Aborted.'); $dialog = new QuestionHelper(); @@ -764,7 +764,7 @@ public function testQuestionValidatorRepeatsThePrompt() public function testEmptyChoices() { - $this->expectException('LogicException'); + $this->expectException(\LogicException::class); $this->expectExceptionMessage('Choice question must have at least 1 choice available.'); new ChoiceQuestion('Question', [], 'irrelevant'); } @@ -878,7 +878,7 @@ protected function createOutputInterface() protected function createInputInterfaceMock($interactive = true) { - $mock = $this->getMockBuilder('Symfony\Component\Console\Input\InputInterface')->getMock(); + $mock = $this->getMockBuilder(\Symfony\Component\Console\Input\InputInterface::class)->getMock(); $mock->expects($this->any()) ->method('isInteractive') ->willReturn($interactive); diff --git a/Tests/Helper/SymfonyQuestionHelperTest.php b/Tests/Helper/SymfonyQuestionHelperTest.php index 06f20e2b1..d7fcf7ecf 100644 --- a/Tests/Helper/SymfonyQuestionHelperTest.php +++ b/Tests/Helper/SymfonyQuestionHelperTest.php @@ -124,7 +124,7 @@ public function testLabelTrailingBackslash() public function testAskThrowsExceptionOnMissingInput() { - $this->expectException('Symfony\Component\Console\Exception\RuntimeException'); + $this->expectException(\Symfony\Component\Console\Exception\RuntimeException::class); $this->expectExceptionMessage('Aborted.'); $dialog = new SymfonyQuestionHelper(); $dialog->ask($this->createStreamableInputInterfaceMock($this->getInputStream('')), $this->createOutputInterface(), new Question('What\'s your name?')); @@ -192,7 +192,7 @@ protected function createOutputInterface() protected function createInputInterfaceMock($interactive = true) { - $mock = $this->getMockBuilder('Symfony\Component\Console\Input\InputInterface')->getMock(); + $mock = $this->getMockBuilder(\Symfony\Component\Console\Input\InputInterface::class)->getMock(); $mock->expects($this->any()) ->method('isInteractive') ->willReturn($interactive); diff --git a/Tests/Helper/TableStyleTest.php b/Tests/Helper/TableStyleTest.php index 598019254..a2875852d 100644 --- a/Tests/Helper/TableStyleTest.php +++ b/Tests/Helper/TableStyleTest.php @@ -18,7 +18,7 @@ class TableStyleTest extends TestCase { public function testSetPadTypeWithInvalidType() { - $this->expectException('InvalidArgumentException'); + $this->expectException(\InvalidArgumentException::class); $this->expectExceptionMessage('Invalid padding type. Expected one of (STR_PAD_LEFT, STR_PAD_RIGHT, STR_PAD_BOTH).'); $style = new TableStyle(); $style->setPadType('TEST'); diff --git a/Tests/Helper/TableTest.php b/Tests/Helper/TableTest.php index dffaaf902..3ad71062c 100644 --- a/Tests/Helper/TableTest.php +++ b/Tests/Helper/TableTest.php @@ -808,7 +808,7 @@ public function testColumnStyle() public function testThrowsWhenTheCellInAnArray() { - $this->expectException('Symfony\Component\Console\Exception\InvalidArgumentException'); + $this->expectException(\Symfony\Component\Console\Exception\InvalidArgumentException::class); $this->expectExceptionMessage('A cell must be a TableCell, a scalar or an object implementing "__toString()", "array" given.'); $table = new Table($output = $this->getOutputStream()); $table @@ -983,7 +983,7 @@ public function testSectionOutputWithoutDecoration() public function testAppendRowWithoutSectionOutput() { - $this->expectException('Symfony\Component\Console\Exception\RuntimeException'); + $this->expectException(\Symfony\Component\Console\Exception\RuntimeException::class); $this->expectExceptionMessage('Output should be an instance of "Symfony\Component\Console\Output\ConsoleSectionOutput" when calling "Symfony\Component\Console\Helper\Table::appendRow".'); $table = new Table($this->getOutputStream()); @@ -1024,7 +1024,7 @@ public function testSectionOutputHandlesZeroRowsAfterRender() public function testIsNotDefinedStyleException() { - $this->expectException('Symfony\Component\Console\Exception\InvalidArgumentException'); + $this->expectException(\Symfony\Component\Console\Exception\InvalidArgumentException::class); $this->expectExceptionMessage('Style "absent" is not defined.'); $table = new Table($this->getOutputStream()); $table->setStyle('absent'); @@ -1032,7 +1032,7 @@ public function testIsNotDefinedStyleException() public function testGetStyleDefinition() { - $this->expectException('Symfony\Component\Console\Exception\InvalidArgumentException'); + $this->expectException(\Symfony\Component\Console\Exception\InvalidArgumentException::class); $this->expectExceptionMessage('Style "absent" is not defined.'); Table::getStyleDefinition('absent'); } diff --git a/Tests/Input/ArgvInputTest.php b/Tests/Input/ArgvInputTest.php index 51cc6e517..4e39f5e93 100644 --- a/Tests/Input/ArgvInputTest.php +++ b/Tests/Input/ArgvInputTest.php @@ -182,7 +182,7 @@ public function provideOptions() */ public function testInvalidInput($argv, $definition, $expectedExceptionMessage) { - $this->expectException('RuntimeException'); + $this->expectException(\RuntimeException::class); $this->expectExceptionMessage($expectedExceptionMessage); $input = new ArgvInput($argv); diff --git a/Tests/Input/ArrayInputTest.php b/Tests/Input/ArrayInputTest.php index 5e10223dd..f3eedb3a2 100644 --- a/Tests/Input/ArrayInputTest.php +++ b/Tests/Input/ArrayInputTest.php @@ -127,7 +127,7 @@ public function provideOptions() */ public function testParseInvalidInput($parameters, $definition, $expectedExceptionMessage) { - $this->expectException('InvalidArgumentException'); + $this->expectException(\InvalidArgumentException::class); $this->expectExceptionMessage($expectedExceptionMessage); new ArrayInput($parameters, $definition); diff --git a/Tests/Input/InputArgumentTest.php b/Tests/Input/InputArgumentTest.php index a4c951eea..4e583888a 100644 --- a/Tests/Input/InputArgumentTest.php +++ b/Tests/Input/InputArgumentTest.php @@ -39,7 +39,7 @@ public function testModes() public function testInvalidModes() { - $this->expectException('InvalidArgumentException'); + $this->expectException(\InvalidArgumentException::class); $this->expectExceptionMessage('Argument mode "-1" is not valid.'); new InputArgument('foo', '-1'); @@ -82,7 +82,7 @@ public function testSetDefault() public function testSetDefaultWithRequiredArgument() { - $this->expectException('LogicException'); + $this->expectException(\LogicException::class); $this->expectExceptionMessage('Cannot set a default value except for InputArgument::OPTIONAL mode.'); $argument = new InputArgument('foo', InputArgument::REQUIRED); $argument->setDefault('default'); @@ -90,7 +90,7 @@ public function testSetDefaultWithRequiredArgument() public function testSetDefaultWithArrayArgument() { - $this->expectException('LogicException'); + $this->expectException(\LogicException::class); $this->expectExceptionMessage('A default value for an array argument must be an array.'); $argument = new InputArgument('foo', InputArgument::IS_ARRAY); $argument->setDefault('default'); diff --git a/Tests/Input/InputDefinitionTest.php b/Tests/Input/InputDefinitionTest.php index 4b8f78a1c..e811a6658 100644 --- a/Tests/Input/InputDefinitionTest.php +++ b/Tests/Input/InputDefinitionTest.php @@ -89,7 +89,7 @@ public function testAddArgument() public function testArgumentsMustHaveDifferentNames() { - $this->expectException('LogicException'); + $this->expectException(\LogicException::class); $this->expectExceptionMessage('An argument with name "foo" already exists.'); $this->initializeArguments(); @@ -100,7 +100,7 @@ public function testArgumentsMustHaveDifferentNames() public function testArrayArgumentHasToBeLast() { - $this->expectException('LogicException'); + $this->expectException(\LogicException::class); $this->expectExceptionMessage('Cannot add an argument after an array argument.'); $this->initializeArguments(); @@ -111,7 +111,7 @@ public function testArrayArgumentHasToBeLast() public function testRequiredArgumentCannotFollowAnOptionalOne() { - $this->expectException('LogicException'); + $this->expectException(\LogicException::class); $this->expectExceptionMessage('Cannot add a required argument after an optional one.'); $this->initializeArguments(); @@ -131,7 +131,7 @@ public function testGetArgument() public function testGetInvalidArgument() { - $this->expectException('InvalidArgumentException'); + $this->expectException(\InvalidArgumentException::class); $this->expectExceptionMessage('The "bar" argument does not exist.'); $this->initializeArguments(); @@ -201,7 +201,7 @@ public function testSetOptions() public function testSetOptionsClearsOptions() { - $this->expectException('InvalidArgumentException'); + $this->expectException(\InvalidArgumentException::class); $this->expectExceptionMessage('The "-f" option does not exist.'); $this->initializeOptions(); @@ -233,7 +233,7 @@ public function testAddOption() public function testAddDuplicateOption() { - $this->expectException('LogicException'); + $this->expectException(\LogicException::class); $this->expectExceptionMessage('An option named "foo" already exists.'); $this->initializeOptions(); @@ -244,7 +244,7 @@ public function testAddDuplicateOption() public function testAddDuplicateShortcutOption() { - $this->expectException('LogicException'); + $this->expectException(\LogicException::class); $this->expectExceptionMessage('An option with shortcut "f" already exists.'); $this->initializeOptions(); @@ -263,7 +263,7 @@ public function testGetOption() public function testGetInvalidOption() { - $this->expectException('InvalidArgumentException'); + $this->expectException(\InvalidArgumentException::class); $this->expectExceptionMessage('The "--bar" option does not exist.'); $this->initializeOptions(); @@ -308,7 +308,7 @@ public function testGetOptionForMultiShortcut() public function testGetOptionForInvalidShortcut() { - $this->expectException('InvalidArgumentException'); + $this->expectException(\InvalidArgumentException::class); $this->expectExceptionMessage('The "-l" option does not exist.'); $this->initializeOptions(); diff --git a/Tests/Input/InputOptionTest.php b/Tests/Input/InputOptionTest.php index d9e2f1d31..8a5c8fc44 100644 --- a/Tests/Input/InputOptionTest.php +++ b/Tests/Input/InputOptionTest.php @@ -26,7 +26,7 @@ public function testConstructor() public function testArrayModeWithoutValue() { - $this->expectException('InvalidArgumentException'); + $this->expectException(\InvalidArgumentException::class); $this->expectExceptionMessage('Impossible to have an option mode VALUE_IS_ARRAY if the option does not accept a value.'); new InputOption('foo', 'f', InputOption::VALUE_IS_ARRAY); } @@ -73,7 +73,7 @@ public function testModes() public function testInvalidModes() { - $this->expectException('InvalidArgumentException'); + $this->expectException(\InvalidArgumentException::class); $this->expectExceptionMessage('Option mode "-1" is not valid.'); new InputOption('foo', 'f', '-1'); @@ -81,19 +81,19 @@ public function testInvalidModes() public function testEmptyNameIsInvalid() { - $this->expectException('InvalidArgumentException'); + $this->expectException(\InvalidArgumentException::class); new InputOption(''); } public function testDoubleDashNameIsInvalid() { - $this->expectException('InvalidArgumentException'); + $this->expectException(\InvalidArgumentException::class); new InputOption('--'); } public function testSingleDashOptionIsInvalid() { - $this->expectException('InvalidArgumentException'); + $this->expectException(\InvalidArgumentException::class); new InputOption('foo', '-'); } @@ -144,7 +144,7 @@ public function testSetDefault() public function testDefaultValueWithValueNoneMode() { - $this->expectException('LogicException'); + $this->expectException(\LogicException::class); $this->expectExceptionMessage('Cannot set a default value when using InputOption::VALUE_NONE mode.'); $option = new InputOption('foo', 'f', InputOption::VALUE_NONE); $option->setDefault('default'); @@ -152,7 +152,7 @@ public function testDefaultValueWithValueNoneMode() public function testDefaultValueWithIsArrayMode() { - $this->expectException('LogicException'); + $this->expectException(\LogicException::class); $this->expectExceptionMessage('A default value for an array option must be an array.'); $option = new InputOption('foo', 'f', InputOption::VALUE_OPTIONAL | InputOption::VALUE_IS_ARRAY); $option->setDefault('default'); diff --git a/Tests/Input/InputTest.php b/Tests/Input/InputTest.php index 060b750f4..48c287cd9 100644 --- a/Tests/Input/InputTest.php +++ b/Tests/Input/InputTest.php @@ -49,7 +49,7 @@ public function testOptions() public function testSetInvalidOption() { - $this->expectException('InvalidArgumentException'); + $this->expectException(\InvalidArgumentException::class); $this->expectExceptionMessage('The "foo" option does not exist.'); $input = new ArrayInput(['--name' => 'foo'], new InputDefinition([new InputOption('name'), new InputOption('bar', '', InputOption::VALUE_OPTIONAL, '', 'default')])); $input->setOption('foo', 'bar'); @@ -57,7 +57,7 @@ public function testSetInvalidOption() public function testGetInvalidOption() { - $this->expectException('InvalidArgumentException'); + $this->expectException(\InvalidArgumentException::class); $this->expectExceptionMessage('The "foo" option does not exist.'); $input = new ArrayInput(['--name' => 'foo'], new InputDefinition([new InputOption('name'), new InputOption('bar', '', InputOption::VALUE_OPTIONAL, '', 'default')])); $input->getOption('foo'); @@ -79,7 +79,7 @@ public function testArguments() public function testSetInvalidArgument() { - $this->expectException('InvalidArgumentException'); + $this->expectException(\InvalidArgumentException::class); $this->expectExceptionMessage('The "foo" argument does not exist.'); $input = new ArrayInput(['name' => 'foo'], new InputDefinition([new InputArgument('name'), new InputArgument('bar', InputArgument::OPTIONAL, '', 'default')])); $input->setArgument('foo', 'bar'); @@ -87,7 +87,7 @@ public function testSetInvalidArgument() public function testGetInvalidArgument() { - $this->expectException('InvalidArgumentException'); + $this->expectException(\InvalidArgumentException::class); $this->expectExceptionMessage('The "foo" argument does not exist.'); $input = new ArrayInput(['name' => 'foo'], new InputDefinition([new InputArgument('name'), new InputArgument('bar', InputArgument::OPTIONAL, '', 'default')])); $input->getArgument('foo'); @@ -95,7 +95,7 @@ public function testGetInvalidArgument() public function testValidateWithMissingArguments() { - $this->expectException('RuntimeException'); + $this->expectException(\RuntimeException::class); $this->expectExceptionMessage('Not enough arguments (missing: "name").'); $input = new ArrayInput([]); $input->bind(new InputDefinition([new InputArgument('name', InputArgument::REQUIRED)])); @@ -104,7 +104,7 @@ public function testValidateWithMissingArguments() public function testValidateWithMissingRequiredArguments() { - $this->expectException('RuntimeException'); + $this->expectException(\RuntimeException::class); $this->expectExceptionMessage('Not enough arguments (missing: "name").'); $input = new ArrayInput(['bar' => 'baz']); $input->bind(new InputDefinition([new InputArgument('name', InputArgument::REQUIRED), new InputArgument('bar', InputArgument::OPTIONAL)])); diff --git a/Tests/Input/StringInputTest.php b/Tests/Input/StringInputTest.php index 7f2189452..bcc43e431 100644 --- a/Tests/Input/StringInputTest.php +++ b/Tests/Input/StringInputTest.php @@ -24,7 +24,7 @@ class StringInputTest extends TestCase public function testTokenize($input, $tokens, $message) { $input = new StringInput($input); - $r = new \ReflectionClass('Symfony\Component\Console\Input\ArgvInput'); + $r = new \ReflectionClass(\Symfony\Component\Console\Input\ArgvInput::class); $p = $r->getProperty('tokens'); $p->setAccessible(true); $this->assertEquals($tokens, $p->getValue($input), $message); diff --git a/Tests/Logger/ConsoleLoggerTest.php b/Tests/Logger/ConsoleLoggerTest.php index 283eccaf2..5066c426f 100644 --- a/Tests/Logger/ConsoleLoggerTest.php +++ b/Tests/Logger/ConsoleLoggerTest.php @@ -105,7 +105,7 @@ public function testHasErrored() public function testImplements() { - $this->assertInstanceOf('Psr\Log\LoggerInterface', $this->getLogger()); + $this->assertInstanceOf(LoggerInterface::class, $this->getLogger()); } /** @@ -140,7 +140,7 @@ public function provideLevelsAndMessages() public function testThrowsOnInvalidLevel() { - $this->expectException('Psr\Log\InvalidArgumentException'); + $this->expectException(\Psr\Log\InvalidArgumentException::class); $logger = $this->getLogger(); $logger->log('invalid level', 'Foo'); } diff --git a/Tests/Output/StreamOutputTest.php b/Tests/Output/StreamOutputTest.php index a434fead4..89debf40c 100644 --- a/Tests/Output/StreamOutputTest.php +++ b/Tests/Output/StreamOutputTest.php @@ -38,7 +38,7 @@ public function testConstructor() public function testStreamIsRequired() { - $this->expectException('InvalidArgumentException'); + $this->expectException(\InvalidArgumentException::class); $this->expectExceptionMessage('The StreamOutput class needs a stream as its first argument.'); new StreamOutput('foo'); } diff --git a/Tests/Tester/CommandTesterTest.php b/Tests/Tester/CommandTesterTest.php index 11a4bfaf4..244a3f1d0 100644 --- a/Tests/Tester/CommandTesterTest.php +++ b/Tests/Tester/CommandTesterTest.php @@ -140,7 +140,7 @@ public function testCommandWithDefaultInputs() public function testCommandWithWrongInputsNumber() { - $this->expectException('RuntimeException'); + $this->expectException(\RuntimeException::class); $this->expectExceptionMessage('Aborted.'); $questions = [ 'What\'s your name?', @@ -165,7 +165,7 @@ public function testCommandWithWrongInputsNumber() public function testCommandWithQuestionsButNoInputs() { - $this->expectException('RuntimeException'); + $this->expectException(\RuntimeException::class); $this->expectExceptionMessage('Aborted.'); $questions = [ 'What\'s your name?', From 87833be29e5b88e8ad853769cb96da719c63683b Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Mon, 11 Jan 2021 11:11:08 +0100 Subject: [PATCH 09/15] Use ::class keyword when possible --- Tests/ApplicationTest.php | 2 +- Tests/Command/CommandTest.php | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/Tests/ApplicationTest.php b/Tests/ApplicationTest.php index bb8be5b33..ab3684e1b 100644 --- a/Tests/ApplicationTest.php +++ b/Tests/ApplicationTest.php @@ -738,7 +738,7 @@ public function testFindAmbiguousCommandsIfAllAlternativesAreHidden() $application->add(new \FooCommand()); $application->add(new \FooHiddenCommand()); - $this->assertInstanceOf('FooCommand', $application->find('foo:')); + $this->assertInstanceOf(\FooCommand::class, $application->find('foo:')); } public function testSetCatchExceptions() diff --git a/Tests/Command/CommandTest.php b/Tests/Command/CommandTest.php index c15555897..5128bd045 100644 --- a/Tests/Command/CommandTest.php +++ b/Tests/Command/CommandTest.php @@ -42,7 +42,7 @@ public function testConstructor() public function testCommandNameCannotBeEmpty() { - $this->expectException('LogicException'); + $this->expectException(\LogicException::class); $this->expectExceptionMessage('The command defined in "Symfony\Component\Console\Command\Command" cannot have an empty name.'); (new Application())->add(new Command()); } @@ -115,7 +115,7 @@ public function testGetNamespaceGetNameSetName() */ public function testInvalidCommandNames($name) { - $this->expectException('InvalidArgumentException'); + $this->expectException(\InvalidArgumentException::class); $this->expectExceptionMessage(sprintf('Command name "%s" is invalid.', $name)); $command = new \TestCommand(); @@ -207,7 +207,7 @@ public function testGetHelper() public function testGetHelperWithoutHelperSet() { - $this->expectException('LogicException'); + $this->expectException(\LogicException::class); $this->expectExceptionMessage('Cannot retrieve helper "formatter" because there is no HelperSet defined.'); $command = new \TestCommand(); $command->getHelper('formatter'); @@ -278,7 +278,7 @@ public function testRunNonInteractive() public function testExecuteMethodNeedsToBeOverridden() { - $this->expectException('LogicException'); + $this->expectException(\LogicException::class); $this->expectExceptionMessage('You must override the execute() method in the concrete command class.'); $command = new Command('foo'); $command->run(new StringInput(''), new NullOutput()); @@ -286,7 +286,7 @@ public function testExecuteMethodNeedsToBeOverridden() public function testRunWithInvalidOption() { - $this->expectException('Symfony\Component\Console\Exception\InvalidOptionException'); + $this->expectException(\Symfony\Component\Console\Exception\InvalidOptionException::class); $this->expectExceptionMessage('The "--bar" option does not exist.'); $command = new \TestCommand(); $tester = new CommandTester($command); From 7277fc7cd6fa28aff36169ebea2a6f871d3831cf Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Mon, 11 Jan 2021 11:45:43 +0100 Subject: [PATCH 10/15] Use ::class keyword when possible --- Tests/Helper/TableCellStyleTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Tests/Helper/TableCellStyleTest.php b/Tests/Helper/TableCellStyleTest.php index 23c4957f0..ac80750eb 100644 --- a/Tests/Helper/TableCellStyleTest.php +++ b/Tests/Helper/TableCellStyleTest.php @@ -21,7 +21,7 @@ public function testCreateTableCellStyle() $tableCellStyle = new TableCellStyle(['fg' => 'red']); $this->assertEquals('red', $tableCellStyle->getOptions()['fg']); - $this->expectException('Symfony\Component\Console\Exception\InvalidArgumentException'); + $this->expectException(\Symfony\Component\Console\Exception\InvalidArgumentException::class); new TableCellStyle(['wrong_key' => null]); } } From adb658b43abb668be457c1adb0e472c842dea6af Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Thu, 14 Jan 2021 16:08:15 +0100 Subject: [PATCH 11/15] CS fix --- Tests/Output/ConsoleSectionOutputTest.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Tests/Output/ConsoleSectionOutputTest.php b/Tests/Output/ConsoleSectionOutputTest.php index 6abe040b4..f5ea668f4 100644 --- a/Tests/Output/ConsoleSectionOutputTest.php +++ b/Tests/Output/ConsoleSectionOutputTest.php @@ -26,7 +26,7 @@ class ConsoleSectionOutputTest extends TestCase protected function setUp(): void { - $this->stream = fopen('php://memory', 'r+b', false); + $this->stream = fopen('php://memory', 'r+', false); } protected function tearDown(): void @@ -143,7 +143,7 @@ public function testMultipleSectionsOutput() public function testClearSectionContainingQuestion() { - $inputStream = fopen('php://memory', 'r+b', false); + $inputStream = fopen('php://memory', 'r+', false); fwrite($inputStream, "Batman & Robin\n"); rewind($inputStream); From ed39fc8a3af1fd9c692897e075026c6dbe27cea9 Mon Sep 17 00:00:00 2001 From: Oskar Stark Date: Fri, 22 Jan 2021 08:04:07 +0100 Subject: [PATCH 12/15] Use class const in test --- Tests/Logger/ConsoleLoggerTest.php | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/Tests/Logger/ConsoleLoggerTest.php b/Tests/Logger/ConsoleLoggerTest.php index 5066c426f..ebf2d7aa1 100644 --- a/Tests/Logger/ConsoleLoggerTest.php +++ b/Tests/Logger/ConsoleLoggerTest.php @@ -20,8 +20,6 @@ use Symfony\Component\Console\Tests\Fixtures\DummyOutput; /** - * Console logger test. - * * @author Kévin Dunglas * @author Jordi Boggiano */ @@ -157,9 +155,9 @@ public function testContextReplacement() public function testObjectCastToString() { if (method_exists($this, 'createPartialMock')) { - $dummy = $this->createPartialMock('Symfony\Component\Console\Tests\Logger\DummyTest', ['__toString']); + $dummy = $this->createPartialMock(DummyTest::class, ['__toString']); } else { - $dummy = $this->createPartialMock('Symfony\Component\Console\Tests\Logger\DummyTest', ['__toString']); + $dummy = $this->createPartialMock(DummyTest::class, ['__toString']); } $dummy->method('__toString')->willReturn('DUMMY'); From 30830feda35b90096d9ff835424eab568acb4a20 Mon Sep 17 00:00:00 2001 From: Thomas Calvet Date: Fri, 22 Jan 2021 09:23:15 +0100 Subject: [PATCH 13/15] [Console][Command] Fix Closure code binding when it is a static anonymous function --- Command/Command.php | 9 ++++++++- Tests/Command/CommandTest.php | 12 ++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/Command/Command.php b/Command/Command.php index c2b1f4c7e..71ad4a49e 100644 --- a/Command/Command.php +++ b/Command/Command.php @@ -281,7 +281,14 @@ public function setCode(callable $code) if ($code instanceof \Closure) { $r = new \ReflectionFunction($code); if (null === $r->getClosureThis()) { - $code = \Closure::bind($code, $this); + set_error_handler(static function () {}); + try { + if ($c = \Closure::bind($code, $this)) { + $code = $c; + } + } finally { + restore_error_handler(); + } } } diff --git a/Tests/Command/CommandTest.php b/Tests/Command/CommandTest.php index 34156f7b5..9e1ae05eb 100644 --- a/Tests/Command/CommandTest.php +++ b/Tests/Command/CommandTest.php @@ -398,6 +398,18 @@ public function callableMethodCommand(InputInterface $input, OutputInterface $ou { $output->writeln('from the code...'); } + + public function testSetCodeWithStaticAnonymousFunction() + { + $command = new \TestCommand(); + $command->setCode(static function (InputInterface $input, OutputInterface $output) { + $output->writeln(isset($this) ? 'bound' : 'not bound'); + }); + $tester = new CommandTester($command); + $tester->execute([]); + + $this->assertEquals('interact called'.\PHP_EOL.'not bound'.\PHP_EOL, $tester->getDisplay()); + } } // In order to get an unbound closure, we should create it outside a class From a6d92f8a455e96b479781f96516e5bf00a6d6d9f Mon Sep 17 00:00:00 2001 From: Steve Hyde Date: Mon, 25 Jan 2021 15:53:14 +0100 Subject: [PATCH 14/15] Update ConsoleEvents.php input and output can be handed to the command, handed off to the command, or can be handled by the command, but handled to the command doesn't work --- ConsoleEvents.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ConsoleEvents.php b/ConsoleEvents.php index f3c6cad5a..99b423c83 100644 --- a/ConsoleEvents.php +++ b/ConsoleEvents.php @@ -21,7 +21,7 @@ final class ConsoleEvents /** * The COMMAND event allows you to attach listeners before any command is * executed by the console. It also allows you to modify the command, input and output - * before they are handled to the command. + * before they are handed to the command. * * @Event("Symfony\Component\Console\Event\ConsoleCommandEvent") */ From 24026c44fc37099fa145707fecd43672831b837a Mon Sep 17 00:00:00 2001 From: Oskar Stark Date: Fri, 22 Jan 2021 13:09:22 +0100 Subject: [PATCH 15/15] Use createMock() and use import instead of FQCN --- Tests/ApplicationTest.php | 14 ++++++++------ Tests/Command/CommandTest.php | 3 ++- Tests/CommandLoader/ContainerCommandLoaderTest.php | 3 ++- Tests/CommandLoader/FactoryCommandLoaderTest.php | 3 ++- Tests/EventListener/ErrorListenerTest.php | 4 ++-- Tests/Helper/AbstractQuestionHelperTest.php | 2 +- Tests/Helper/DumperNativeFallbackTest.php | 2 +- Tests/Helper/DumperTest.php | 2 +- Tests/Helper/HelperSetTest.php | 5 +++-- Tests/Helper/QuestionHelperTest.php | 12 +++++++----- Tests/Helper/SymfonyQuestionHelperTest.php | 10 ++++++---- Tests/Helper/TableTest.php | 10 ++++++---- Tests/Input/StringInputTest.php | 3 ++- Tests/Logger/ConsoleLoggerTest.php | 3 ++- Tests/Output/ConsoleSectionOutputTest.php | 2 +- Tests/Style/SymfonyStyleTest.php | 10 +++++----- 16 files changed, 51 insertions(+), 37 deletions(-) diff --git a/Tests/ApplicationTest.php b/Tests/ApplicationTest.php index 004b40955..d293697d4 100644 --- a/Tests/ApplicationTest.php +++ b/Tests/ApplicationTest.php @@ -14,6 +14,7 @@ use PHPUnit\Framework\TestCase; use Symfony\Component\Console\Application; use Symfony\Component\Console\Command\Command; +use Symfony\Component\Console\Command\HelpCommand; use Symfony\Component\Console\CommandLoader\FactoryCommandLoader; use Symfony\Component\Console\DependencyInjection\AddConsoleCommandPass; use Symfony\Component\Console\Event\ConsoleCommandEvent; @@ -29,6 +30,7 @@ use Symfony\Component\Console\Input\InputDefinition; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputOption; +use Symfony\Component\Console\Output\ConsoleOutput; use Symfony\Component\Console\Output\NullOutput; use Symfony\Component\Console\Output\Output; use Symfony\Component\Console\Output\OutputInterface; @@ -134,7 +136,7 @@ public function testAll() { $application = new Application(); $commands = $application->all(); - $this->assertInstanceOf(\Symfony\Component\Console\Command\HelpCommand::class, $commands['help'], '->all() returns the registered commands'); + $this->assertInstanceOf(HelpCommand::class, $commands['help'], '->all() returns the registered commands'); $application->add(new \FooCommand()); $commands = $application->all('foo'); @@ -145,7 +147,7 @@ public function testAllWithCommandLoader() { $application = new Application(); $commands = $application->all(); - $this->assertInstanceOf(\Symfony\Component\Console\Command\HelpCommand::class, $commands['help'], '->all() returns the registered commands'); + $this->assertInstanceOf(HelpCommand::class, $commands['help'], '->all() returns the registered commands'); $application->add(new \FooCommand()); $commands = $application->all('foo'); @@ -229,7 +231,7 @@ public function testHasGet() $p->setAccessible(true); $p->setValue($application, true); $command = $application->get('foo:bar'); - $this->assertInstanceOf(\Symfony\Component\Console\Command\HelpCommand::class, $command, '->get() returns the help command if --help is provided as the input'); + $this->assertInstanceOf(HelpCommand::class, $command, '->get() returns the help command if --help is provided as the input'); } public function testHasGetWithCommandLoader() @@ -351,7 +353,7 @@ public function testFind() $application->add(new \FooCommand()); $this->assertInstanceOf(\FooCommand::class, $application->find('foo:bar'), '->find() returns a command if its name exists'); - $this->assertInstanceOf(\Symfony\Component\Console\Command\HelpCommand::class, $application->find('h'), '->find() returns a command if its name exists'); + $this->assertInstanceOf(HelpCommand::class, $application->find('h'), '->find() returns a command if its name exists'); $this->assertInstanceOf(\FooCommand::class, $application->find('f:bar'), '->find() returns a command if the abbreviation for the namespace exists'); $this->assertInstanceOf(\FooCommand::class, $application->find('f:b'), '->find() returns a command if the abbreviation for the namespace and the command name exist'); $this->assertInstanceOf(\FooCommand::class, $application->find('a'), '->find() returns a command if the abbreviation exists for an alias'); @@ -398,7 +400,7 @@ public function testFindWithCommandLoader() ])); $this->assertInstanceOf(\FooCommand::class, $application->find('foo:bar'), '->find() returns a command if its name exists'); - $this->assertInstanceOf(\Symfony\Component\Console\Command\HelpCommand::class, $application->find('h'), '->find() returns a command if its name exists'); + $this->assertInstanceOf(HelpCommand::class, $application->find('h'), '->find() returns a command if its name exists'); $this->assertInstanceOf(\FooCommand::class, $application->find('f:bar'), '->find() returns a command if the abbreviation for the namespace exists'); $this->assertInstanceOf(\FooCommand::class, $application->find('f:b'), '->find() returns a command if the abbreviation for the namespace and the command name exist'); $this->assertInstanceOf(\FooCommand::class, $application->find('a'), '->find() returns a command if the abbreviation exists for an alias'); @@ -951,7 +953,7 @@ public function testRun() ob_end_clean(); $this->assertInstanceOf(ArgvInput::class, $command->input, '->run() creates an ArgvInput by default if none is given'); - $this->assertInstanceOf(\Symfony\Component\Console\Output\ConsoleOutput::class, $command->output, '->run() creates a ConsoleOutput by default if none is given'); + $this->assertInstanceOf(ConsoleOutput::class, $command->output, '->run() creates a ConsoleOutput by default if none is given'); $application = new Application(); $application->setAutoExit(false); diff --git a/Tests/Command/CommandTest.php b/Tests/Command/CommandTest.php index 9e1ae05eb..10a476d19 100644 --- a/Tests/Command/CommandTest.php +++ b/Tests/Command/CommandTest.php @@ -14,6 +14,7 @@ use PHPUnit\Framework\TestCase; use Symfony\Component\Console\Application; use Symfony\Component\Console\Command\Command; +use Symfony\Component\Console\Exception\InvalidOptionException; use Symfony\Component\Console\Helper\FormatterHelper; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputDefinition; @@ -293,7 +294,7 @@ public function testExecuteMethodNeedsToBeOverridden() public function testRunWithInvalidOption() { - $this->expectException(\Symfony\Component\Console\Exception\InvalidOptionException::class); + $this->expectException(InvalidOptionException::class); $this->expectExceptionMessage('The "--bar" option does not exist.'); $command = new \TestCommand(); $tester = new CommandTester($command); diff --git a/Tests/CommandLoader/ContainerCommandLoaderTest.php b/Tests/CommandLoader/ContainerCommandLoaderTest.php index 67b2d5cee..e7f138933 100644 --- a/Tests/CommandLoader/ContainerCommandLoaderTest.php +++ b/Tests/CommandLoader/ContainerCommandLoaderTest.php @@ -14,6 +14,7 @@ use PHPUnit\Framework\TestCase; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\CommandLoader\ContainerCommandLoader; +use Symfony\Component\Console\Exception\CommandNotFoundException; use Symfony\Component\DependencyInjection\ServiceLocator; class ContainerCommandLoaderTest extends TestCase @@ -43,7 +44,7 @@ public function testGet() public function testGetUnknownCommandThrows() { - $this->expectException(\Symfony\Component\Console\Exception\CommandNotFoundException::class); + $this->expectException(CommandNotFoundException::class); (new ContainerCommandLoader(new ServiceLocator([]), []))->get('unknown'); } diff --git a/Tests/CommandLoader/FactoryCommandLoaderTest.php b/Tests/CommandLoader/FactoryCommandLoaderTest.php index 8546ae669..aebb429e6 100644 --- a/Tests/CommandLoader/FactoryCommandLoaderTest.php +++ b/Tests/CommandLoader/FactoryCommandLoaderTest.php @@ -14,6 +14,7 @@ use PHPUnit\Framework\TestCase; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\CommandLoader\FactoryCommandLoader; +use Symfony\Component\Console\Exception\CommandNotFoundException; class FactoryCommandLoaderTest extends TestCase { @@ -42,7 +43,7 @@ public function testGet() public function testGetUnknownCommandThrows() { - $this->expectException(\Symfony\Component\Console\Exception\CommandNotFoundException::class); + $this->expectException(CommandNotFoundException::class); (new FactoryCommandLoader([]))->get('unknown'); } diff --git a/Tests/EventListener/ErrorListenerTest.php b/Tests/EventListener/ErrorListenerTest.php index 68b4b3a3e..ce3df1a0e 100644 --- a/Tests/EventListener/ErrorListenerTest.php +++ b/Tests/EventListener/ErrorListenerTest.php @@ -117,7 +117,7 @@ public function testCommandNameIsDisplayedForNonStringableInput() ; $listener = new ErrorListener($logger); - $listener->onConsoleTerminate($this->getConsoleTerminateEvent($this->getMockBuilder(InputInterface::class)->getMock(), 255)); + $listener->onConsoleTerminate($this->getConsoleTerminateEvent($this->createMock(InputInterface::class), 255)); } private function getLogger() @@ -132,7 +132,7 @@ private function getConsoleTerminateEvent(InputInterface $input, $exitCode) private function getOutput() { - return $this->getMockBuilder(OutputInterface::class)->getMock(); + return $this->createMock(OutputInterface::class); } } diff --git a/Tests/Helper/AbstractQuestionHelperTest.php b/Tests/Helper/AbstractQuestionHelperTest.php index f12566ded..3da121624 100644 --- a/Tests/Helper/AbstractQuestionHelperTest.php +++ b/Tests/Helper/AbstractQuestionHelperTest.php @@ -18,7 +18,7 @@ abstract class AbstractQuestionHelperTest extends TestCase { protected function createStreamableInputInterfaceMock($stream = null, $interactive = true) { - $mock = $this->getMockBuilder(StreamableInputInterface::class)->getMock(); + $mock = $this->createMock(StreamableInputInterface::class); $mock->expects($this->any()) ->method('isInteractive') ->willReturn($interactive); diff --git a/Tests/Helper/DumperNativeFallbackTest.php b/Tests/Helper/DumperNativeFallbackTest.php index b0d13cc1b..906d322b6 100644 --- a/Tests/Helper/DumperNativeFallbackTest.php +++ b/Tests/Helper/DumperNativeFallbackTest.php @@ -37,7 +37,7 @@ public static function tearDownAfterClass(): void */ public function testInvoke($variable, $primitiveString) { - $dumper = new Dumper($this->getMockBuilder(OutputInterface::class)->getMock()); + $dumper = new Dumper($this->createMock(OutputInterface::class)); $this->assertSame($primitiveString, $dumper($variable)); } diff --git a/Tests/Helper/DumperTest.php b/Tests/Helper/DumperTest.php index 8791b08b9..e491422b0 100644 --- a/Tests/Helper/DumperTest.php +++ b/Tests/Helper/DumperTest.php @@ -37,7 +37,7 @@ public static function tearDownAfterClass(): void */ public function testInvoke($variable) { - $output = $this->getMockBuilder(OutputInterface::class)->getMock(); + $output = $this->createMock(OutputInterface::class); $output->method('isDecorated')->willReturn(false); $dumper = new Dumper($output); diff --git a/Tests/Helper/HelperSetTest.php b/Tests/Helper/HelperSetTest.php index 707a190cf..38cfc27a1 100644 --- a/Tests/Helper/HelperSetTest.php +++ b/Tests/Helper/HelperSetTest.php @@ -13,6 +13,7 @@ use PHPUnit\Framework\TestCase; use Symfony\Component\Console\Command\Command; +use Symfony\Component\Console\Exception\ExceptionInterface; use Symfony\Component\Console\Helper\HelperInterface; use Symfony\Component\Console\Helper\HelperSet; @@ -68,7 +69,7 @@ public function testGet() $this->fail('->get() throws InvalidArgumentException when helper not found'); } catch (\Exception $e) { $this->assertInstanceOf(\InvalidArgumentException::class, $e, '->get() throws InvalidArgumentException when helper not found'); - $this->assertInstanceOf(\Symfony\Component\Console\Exception\ExceptionInterface::class, $e, '->get() throws domain specific exception when helper not found'); + $this->assertInstanceOf(ExceptionInterface::class, $e, '->get() throws domain specific exception when helper not found'); $this->assertStringContainsString('The helper "foo" is not defined.', $e->getMessage(), '->get() throws InvalidArgumentException when helper not found'); } } @@ -112,7 +113,7 @@ public function testIteration() private function getGenericMockHelper($name, HelperSet $helperset = null) { - $mock_helper = $this->getMockBuilder(HelperInterface::class)->getMock(); + $mock_helper = $this->createMock(HelperInterface::class); $mock_helper->expects($this->any()) ->method('getName') ->willReturn($name); diff --git a/Tests/Helper/QuestionHelperTest.php b/Tests/Helper/QuestionHelperTest.php index 5db0ded77..bba71cc59 100644 --- a/Tests/Helper/QuestionHelperTest.php +++ b/Tests/Helper/QuestionHelperTest.php @@ -13,10 +13,12 @@ use Symfony\Component\Console\Application; use Symfony\Component\Console\Exception\InvalidArgumentException; +use Symfony\Component\Console\Exception\MissingInputException; use Symfony\Component\Console\Formatter\OutputFormatter; use Symfony\Component\Console\Helper\FormatterHelper; use Symfony\Component\Console\Helper\HelperSet; use Symfony\Component\Console\Helper\QuestionHelper; +use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Output\StreamOutput; use Symfony\Component\Console\Question\ChoiceQuestion; @@ -685,7 +687,7 @@ public function testChoiceOutputFormattingQuestionForUtf8Keys() ' [żółw ] bar', ' [łabądź] baz', ]; - $output = $this->getMockBuilder(OutputInterface::class)->getMock(); + $output = $this->createMock(OutputInterface::class); $output->method('getFormatter')->willReturn(new OutputFormatter()); $dialog = new QuestionHelper(); @@ -700,7 +702,7 @@ public function testChoiceOutputFormattingQuestionForUtf8Keys() public function testAskThrowsExceptionOnMissingInput() { - $this->expectException(\Symfony\Component\Console\Exception\MissingInputException::class); + $this->expectException(MissingInputException::class); $this->expectExceptionMessage('Aborted.'); $dialog = new QuestionHelper(); $dialog->ask($this->createStreamableInputInterfaceMock($this->getInputStream('')), $this->createOutputInterface(), new Question('What\'s your name?')); @@ -708,7 +710,7 @@ public function testAskThrowsExceptionOnMissingInput() public function testAskThrowsExceptionOnMissingInputForChoiceQuestion() { - $this->expectException(\Symfony\Component\Console\Exception\MissingInputException::class); + $this->expectException(MissingInputException::class); $this->expectExceptionMessage('Aborted.'); $dialog = new QuestionHelper(); $dialog->ask($this->createStreamableInputInterfaceMock($this->getInputStream('')), $this->createOutputInterface(), new ChoiceQuestion('Choice', ['a', 'b'])); @@ -716,7 +718,7 @@ public function testAskThrowsExceptionOnMissingInputForChoiceQuestion() public function testAskThrowsExceptionOnMissingInputWithValidator() { - $this->expectException(\Symfony\Component\Console\Exception\MissingInputException::class); + $this->expectException(MissingInputException::class); $this->expectExceptionMessage('Aborted.'); $dialog = new QuestionHelper(); @@ -878,7 +880,7 @@ protected function createOutputInterface() protected function createInputInterfaceMock($interactive = true) { - $mock = $this->getMockBuilder(\Symfony\Component\Console\Input\InputInterface::class)->getMock(); + $mock = $this->createMock(InputInterface::class); $mock->expects($this->any()) ->method('isInteractive') ->willReturn($interactive); diff --git a/Tests/Helper/SymfonyQuestionHelperTest.php b/Tests/Helper/SymfonyQuestionHelperTest.php index d7fcf7ecf..fd5442b7f 100644 --- a/Tests/Helper/SymfonyQuestionHelperTest.php +++ b/Tests/Helper/SymfonyQuestionHelperTest.php @@ -2,9 +2,11 @@ namespace Symfony\Component\Console\Tests\Helper; +use Symfony\Component\Console\Exception\RuntimeException; use Symfony\Component\Console\Helper\FormatterHelper; use Symfony\Component\Console\Helper\HelperSet; use Symfony\Component\Console\Helper\SymfonyQuestionHelper; +use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\StreamOutput; use Symfony\Component\Console\Question\ChoiceQuestion; use Symfony\Component\Console\Question\Question; @@ -124,7 +126,7 @@ public function testLabelTrailingBackslash() public function testAskThrowsExceptionOnMissingInput() { - $this->expectException(\Symfony\Component\Console\Exception\RuntimeException::class); + $this->expectException(RuntimeException::class); $this->expectExceptionMessage('Aborted.'); $dialog = new SymfonyQuestionHelper(); $dialog->ask($this->createStreamableInputInterfaceMock($this->getInputStream('')), $this->createOutputInterface(), new Question('What\'s your name?')); @@ -149,7 +151,7 @@ public function testChoiceQuestionPadding() [foo ] foo [żółw ] bar [łabądź] baz - > + > EOT , $output, true); } @@ -168,7 +170,7 @@ public function testChoiceQuestionCustomPrompt() $this->assertOutputContains(<<ccc> + >ccc> EOT , $output, true); } @@ -192,7 +194,7 @@ protected function createOutputInterface() protected function createInputInterfaceMock($interactive = true) { - $mock = $this->getMockBuilder(\Symfony\Component\Console\Input\InputInterface::class)->getMock(); + $mock = $this->createMock(InputInterface::class); $mock->expects($this->any()) ->method('isInteractive') ->willReturn($interactive); diff --git a/Tests/Helper/TableTest.php b/Tests/Helper/TableTest.php index 3ad71062c..d02d6ea42 100644 --- a/Tests/Helper/TableTest.php +++ b/Tests/Helper/TableTest.php @@ -12,6 +12,8 @@ namespace Symfony\Component\Console\Tests\Helper; use PHPUnit\Framework\TestCase; +use Symfony\Component\Console\Exception\InvalidArgumentException; +use Symfony\Component\Console\Exception\RuntimeException; use Symfony\Component\Console\Formatter\OutputFormatter; use Symfony\Component\Console\Helper\Table; use Symfony\Component\Console\Helper\TableCell; @@ -808,7 +810,7 @@ public function testColumnStyle() public function testThrowsWhenTheCellInAnArray() { - $this->expectException(\Symfony\Component\Console\Exception\InvalidArgumentException::class); + $this->expectException(InvalidArgumentException::class); $this->expectExceptionMessage('A cell must be a TableCell, a scalar or an object implementing "__toString()", "array" given.'); $table = new Table($output = $this->getOutputStream()); $table @@ -983,7 +985,7 @@ public function testSectionOutputWithoutDecoration() public function testAppendRowWithoutSectionOutput() { - $this->expectException(\Symfony\Component\Console\Exception\RuntimeException::class); + $this->expectException(RuntimeException::class); $this->expectExceptionMessage('Output should be an instance of "Symfony\Component\Console\Output\ConsoleSectionOutput" when calling "Symfony\Component\Console\Helper\Table::appendRow".'); $table = new Table($this->getOutputStream()); @@ -1024,7 +1026,7 @@ public function testSectionOutputHandlesZeroRowsAfterRender() public function testIsNotDefinedStyleException() { - $this->expectException(\Symfony\Component\Console\Exception\InvalidArgumentException::class); + $this->expectException(InvalidArgumentException::class); $this->expectExceptionMessage('Style "absent" is not defined.'); $table = new Table($this->getOutputStream()); $table->setStyle('absent'); @@ -1032,7 +1034,7 @@ public function testIsNotDefinedStyleException() public function testGetStyleDefinition() { - $this->expectException(\Symfony\Component\Console\Exception\InvalidArgumentException::class); + $this->expectException(InvalidArgumentException::class); $this->expectExceptionMessage('Style "absent" is not defined.'); Table::getStyleDefinition('absent'); } diff --git a/Tests/Input/StringInputTest.php b/Tests/Input/StringInputTest.php index bcc43e431..f781b7ccf 100644 --- a/Tests/Input/StringInputTest.php +++ b/Tests/Input/StringInputTest.php @@ -12,6 +12,7 @@ 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\InputOption; use Symfony\Component\Console\Input\StringInput; @@ -24,7 +25,7 @@ class StringInputTest extends TestCase public function testTokenize($input, $tokens, $message) { $input = new StringInput($input); - $r = new \ReflectionClass(\Symfony\Component\Console\Input\ArgvInput::class); + $r = new \ReflectionClass(ArgvInput::class); $p = $r->getProperty('tokens'); $p->setAccessible(true); $this->assertEquals($tokens, $p->getValue($input), $message); diff --git a/Tests/Logger/ConsoleLoggerTest.php b/Tests/Logger/ConsoleLoggerTest.php index ebf2d7aa1..3585bde63 100644 --- a/Tests/Logger/ConsoleLoggerTest.php +++ b/Tests/Logger/ConsoleLoggerTest.php @@ -12,6 +12,7 @@ namespace Symfony\Component\Console\Tests\Logger; use PHPUnit\Framework\TestCase; +use Psr\Log\InvalidArgumentException; use Psr\Log\LoggerInterface; use Psr\Log\LogLevel; use Symfony\Component\Console\Logger\ConsoleLogger; @@ -138,7 +139,7 @@ public function provideLevelsAndMessages() public function testThrowsOnInvalidLevel() { - $this->expectException(\Psr\Log\InvalidArgumentException::class); + $this->expectException(InvalidArgumentException::class); $logger = $this->getLogger(); $logger->log('invalid level', 'Foo'); } diff --git a/Tests/Output/ConsoleSectionOutputTest.php b/Tests/Output/ConsoleSectionOutputTest.php index f5ea668f4..206b201bc 100644 --- a/Tests/Output/ConsoleSectionOutputTest.php +++ b/Tests/Output/ConsoleSectionOutputTest.php @@ -147,7 +147,7 @@ public function testClearSectionContainingQuestion() fwrite($inputStream, "Batman & Robin\n"); rewind($inputStream); - $input = $this->getMockBuilder(StreamableInputInterface::class)->getMock(); + $input = $this->createMock(StreamableInputInterface::class); $input->expects($this->once())->method('isInteractive')->willReturn(true); $input->expects($this->once())->method('getStream')->willReturn($inputStream); diff --git a/Tests/Style/SymfonyStyleTest.php b/Tests/Style/SymfonyStyleTest.php index 2444d89ba..201da6474 100644 --- a/Tests/Style/SymfonyStyleTest.php +++ b/Tests/Style/SymfonyStyleTest.php @@ -83,9 +83,9 @@ public function inputCommandToOutputFilesProvider() public function testGetErrorStyle() { - $input = $this->getMockBuilder(InputInterface::class)->getMock(); + $input = $this->createMock(InputInterface::class); - $errorOutput = $this->getMockBuilder(OutputInterface::class)->getMock(); + $errorOutput = $this->createMock(OutputInterface::class); $errorOutput ->method('getFormatter') ->willReturn(new OutputFormatter()); @@ -93,7 +93,7 @@ public function testGetErrorStyle() ->expects($this->once()) ->method('write'); - $output = $this->getMockBuilder(ConsoleOutputInterface::class)->getMock(); + $output = $this->createMock(ConsoleOutputInterface::class); $output ->method('getFormatter') ->willReturn(new OutputFormatter()); @@ -108,12 +108,12 @@ public function testGetErrorStyle() public function testGetErrorStyleUsesTheCurrentOutputIfNoErrorOutputIsAvailable() { - $output = $this->getMockBuilder(OutputInterface::class)->getMock(); + $output = $this->createMock(OutputInterface::class); $output ->method('getFormatter') ->willReturn(new OutputFormatter()); - $style = new SymfonyStyle($this->getMockBuilder(InputInterface::class)->getMock(), $output); + $style = new SymfonyStyle($this->createMock(InputInterface::class), $output); $this->assertInstanceOf(SymfonyStyle::class, $style->getErrorStyle()); }