diff --git a/Application.php b/Application.php
index cdb5a81d2..4fba363b4 100644
--- a/Application.php
+++ b/Application.php
@@ -860,11 +860,11 @@ protected function doRenderThrowable(\Throwable $e, OutputInterface $output): vo
]);
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/Command/Command.php b/Command/Command.php
index e5d4cf18a..65f54f801 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;
@@ -281,7 +282,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/ConsoleEvents.php b/ConsoleEvents.php
index be6f435d3..6ae8f32b8 100644
--- a/ConsoleEvents.php
+++ b/ConsoleEvents.php
@@ -26,7 +26,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")
*/
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 8b2a27948..ec6ade386 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 483a8338d..3748335ea 100644
--- a/Descriptor/MarkdownDescriptor.php
+++ b/Descriptor/MarkdownDescriptor.php
@@ -147,7 +147,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 e73b8a99f..07aef2a31 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)
@@ -174,7 +174,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 24035f5a3..4931fba62 100644
--- a/Descriptor/XmlDescriptor.php
+++ b/Descriptor/XmlDescriptor.php
@@ -151,7 +151,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 4ad248868..52ca23273 100644
--- a/Formatter/OutputFormatter.php
+++ b/Formatter/OutputFormatter.php
@@ -161,7 +161,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 7b6b99e43..a3aa48097 100644
--- a/Helper/ProgressBar.php
+++ b/Helper/ProgressBar.php
@@ -113,7 +113,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;
}
/**
@@ -146,7 +146,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 81cb783ea..491a537eb 100644
--- a/Helper/ProgressIndicator.php
+++ b/Helper/ProgressIndicator.php
@@ -142,7 +142,7 @@ public static function getFormatDefinition(string $name)
self::$formats = self::initFormats();
}
- return isset(self::$formats[$name]) ? self::$formats[$name] : null;
+ return self::$formats[$name] ?? null;
}
/**
@@ -170,7 +170,7 @@ public static function getPlaceholderFormatterDefinition(string $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 643005f07..054c24192 100644
--- a/Helper/QuestionHelper.php
+++ b/Helper/QuestionHelper.php
@@ -172,13 +172,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 8b923bb13..fd9b703fc 100644
--- a/Helper/SymfonyQuestionHelper.php
+++ b/Helper/SymfonyQuestionHelper.php
@@ -62,7 +62,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 91d1688d0..041145403 100644
--- a/Helper/Table.php
+++ b/Helper/Table.php
@@ -491,7 +491,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).
@@ -648,7 +648,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(), 'style' => $cell->getStyle()]);
if ($nbLines === $unmergedRowKey - $line) {
break;
@@ -786,7 +786,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 ff5d3170f..dd7658094 100644
--- a/Input/Input.php
+++ b/Input/Input.php
@@ -110,7 +110,7 @@ public function getArgument(string $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/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
diff --git a/Style/SymfonyStyle.php b/Style/SymfonyStyle.php
index 96d73d42a..a1b019ca0 100644
--- a/Style/SymfonyStyle.php
+++ b/Style/SymfonyStyle.php
@@ -300,7 +300,7 @@ public function choice(string $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 69442b22d..358341b10 100644
--- a/Tester/TesterTrait.php
+++ b/Tester/TesterTrait.php
@@ -147,8 +147,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));
diff --git a/Tests/ApplicationTest.php b/Tests/ApplicationTest.php
index 414192096..4751ba1a2 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\Command\SignalableCommandInterface;
use Symfony\Component\Console\CommandLoader\FactoryCommandLoader;
use Symfony\Component\Console\DependencyInjection\AddConsoleCommandPass;
@@ -30,6 +31,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;
@@ -135,7 +137,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(HelpCommand::class, $commands['help'], '->all() returns the registered commands');
$application->add(new \FooCommand());
$commands = $application->all('foo');
@@ -146,7 +148,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(HelpCommand::class, $commands['help'], '->all() returns the registered commands');
$application->add(new \FooCommand());
$commands = $application->all('foo');
@@ -205,7 +207,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());
@@ -230,7 +232,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(HelpCommand::class, $command, '->get() returns the help command if --help is provided as the input');
}
public function testHasGetWithCommandLoader()
@@ -271,7 +273,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');
@@ -328,7 +330,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');
@@ -336,7 +338,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());
@@ -351,11 +353,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(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()
@@ -364,10 +366,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()
@@ -375,20 +377,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()
@@ -398,11 +400,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(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');
}
/**
@@ -411,7 +413,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();
@@ -450,7 +452,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()
@@ -459,8 +461,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()
@@ -469,7 +471,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()
@@ -477,7 +479,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'));
}
/**
@@ -485,7 +487,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());
@@ -559,7 +561,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());
@@ -570,7 +572,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());
}
@@ -583,7 +585,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());
}
@@ -601,7 +603,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');
}
@@ -612,7 +614,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"');
@@ -650,7 +652,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');
}
@@ -659,8 +661,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());
@@ -696,7 +698,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());
@@ -705,7 +707,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']);
@@ -715,7 +717,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());
@@ -728,8 +730,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'));
}
public function testFindAmbiguousCommandsIfAllAlternativesAreHidden()
@@ -739,7 +741,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()
@@ -764,7 +766,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');
}
}
@@ -865,7 +867,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')
@@ -937,8 +939,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(ConsoleOutput::class, $command->output, '->run() creates a ConsoleOutput by default if none is given');
$application = new Application();
$application->setAutoExit(false);
@@ -1069,7 +1071,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')
@@ -1108,7 +1110,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')
@@ -1145,7 +1147,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();
@@ -1173,7 +1175,7 @@ public function testAddingOptionWithDuplicateShortcut()
*/
public function testAddingAlreadySetDefinitionElementData($def)
{
- $this->expectException('LogicException');
+ $this->expectException(\LogicException::class);
$application = new Application();
$application->setAutoExit(false);
$application->setCatchExceptions(false);
@@ -1324,7 +1326,7 @@ public function testRunWithDispatcher()
public function testRunWithExceptionAndDispatcher()
{
- $this->expectException('LogicException');
+ $this->expectException(\LogicException::class);
$this->expectExceptionMessage('error');
$application = new Application();
$application->setDispatcher($this->getDispatcher());
@@ -1467,7 +1469,7 @@ public function testErrorIsRethrownIfNotHandledByConsoleErrorEvent()
public function testRunWithErrorAndDispatcher()
{
- $this->expectException('LogicException');
+ $this->expectException(\LogicException::class);
$this->expectExceptionMessage('error');
$application = new Application();
$application->setDispatcher($this->getDispatcher());
@@ -1679,7 +1681,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');
@@ -1772,7 +1774,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) {
@@ -1826,7 +1828,7 @@ public function testSignal()
$application = new Application();
$application->setAutoExit(false);
$application->setDispatcher($dispatcher);
- $application->setSignalsToDispatchEvent(SIGALRM);
+ $application->setSignalsToDispatchEvent(\SIGALRM);
$application->add($command);
$this->assertFalse($command->signaled);
@@ -1909,7 +1911,7 @@ class SignableCommand extends Command implements SignalableCommandInterface
public function getSubscribedSignals(): array
{
- return [SIGALRM];
+ return [\SIGALRM];
}
public function handleSignal(int $signal): void
diff --git a/Tests/Command/CommandTest.php b/Tests/Command/CommandTest.php
index e2947dc44..ead75ebd3 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;
@@ -42,7 +43,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 +116,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 +208,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 +279,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 +287,7 @@ public function testExecuteMethodNeedsToBeOverridden()
public function testRunWithInvalidOption()
{
- $this->expectException('Symfony\Component\Console\Exception\InvalidOptionException');
+ $this->expectException(InvalidOptionException::class);
$this->expectExceptionMessage('The "--bar" option does not exist.');
$command = new \TestCommand();
$tester = new CommandTester($command);
@@ -391,6 +392,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
diff --git a/Tests/CommandLoader/ContainerCommandLoaderTest.php b/Tests/CommandLoader/ContainerCommandLoaderTest.php
index 50fe125a6..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');
+ $this->expectException(CommandNotFoundException::class);
(new ContainerCommandLoader(new ServiceLocator([]), []))->get('unknown');
}
diff --git a/Tests/CommandLoader/FactoryCommandLoaderTest.php b/Tests/CommandLoader/FactoryCommandLoaderTest.php
index a37ad18de..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');
+ $this->expectException(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/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/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]);
}
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 862598be5..d6b44172a 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');
}
@@ -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');
}
}
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 d608f7bfd..38cfc27a1 100644
--- a/Tests/Helper/HelperSetTest.php
+++ b/Tests/Helper/HelperSetTest.php
@@ -13,6 +13,8 @@
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;
class HelperSetTest extends TestCase
@@ -66,8 +68,8 @@ 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('Symfony\Component\Console\Exception\ExceptionInterface', $e, '->get() throws domain specific exception when helper not found');
+ $this->assertInstanceOf(\InvalidArgumentException::class, $e, '->get() throws InvalidArgumentException 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');
}
}
@@ -111,7 +113,7 @@ public function testIteration()
private function getGenericMockHelper($name, HelperSet $helperset = null)
{
- $mock_helper = $this->getMockBuilder('\Symfony\Component\Console\Helper\HelperInterface')->getMock();
+ $mock_helper = $this->createMock(HelperInterface::class);
$mock_helper->expects($this->any())
->method('getName')
->willReturn($name);
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 4d1a0a271..4b098dc56 100644
--- a/Tests/Helper/QuestionHelperTest.php
+++ b/Tests/Helper/QuestionHelperTest.php
@@ -13,10 +13,13 @@
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;
use Symfony\Component\Console\Question\ConfirmationQuestion;
@@ -676,7 +679,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',
@@ -728,7 +731,7 @@ public function testChoiceOutputFormattingQuestionForUtf8Keys()
' [żółw ] bar',
' [łabądź] baz',
];
- $output = $this->getMockBuilder('\Symfony\Component\Console\Output\OutputInterface')->getMock();
+ $output = $this->createMock(OutputInterface::class);
$output->method('getFormatter')->willReturn(new OutputFormatter());
$dialog = new QuestionHelper();
@@ -743,7 +746,7 @@ public function testChoiceOutputFormattingQuestionForUtf8Keys()
public function testAskThrowsExceptionOnMissingInput()
{
- $this->expectException('Symfony\Component\Console\Exception\MissingInputException');
+ $this->expectException(MissingInputException::class);
$this->expectExceptionMessage('Aborted.');
$dialog = new QuestionHelper();
$dialog->ask($this->createStreamableInputInterfaceMock($this->getInputStream('')), $this->createOutputInterface(), new Question('What\'s your name?'));
@@ -751,7 +754,7 @@ public function testAskThrowsExceptionOnMissingInput()
public function testAskThrowsExceptionOnMissingInputForChoiceQuestion()
{
- $this->expectException('Symfony\Component\Console\Exception\MissingInputException');
+ $this->expectException(MissingInputException::class);
$this->expectExceptionMessage('Aborted.');
$dialog = new QuestionHelper();
$dialog->ask($this->createStreamableInputInterfaceMock($this->getInputStream('')), $this->createOutputInterface(), new ChoiceQuestion('Choice', ['a', 'b']));
@@ -759,7 +762,7 @@ public function testAskThrowsExceptionOnMissingInputForChoiceQuestion()
public function testAskThrowsExceptionOnMissingInputWithValidator()
{
- $this->expectException('Symfony\Component\Console\Exception\MissingInputException');
+ $this->expectException(MissingInputException::class);
$this->expectExceptionMessage('Aborted.');
$dialog = new QuestionHelper();
@@ -807,7 +810,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');
}
@@ -940,7 +943,7 @@ protected function createOutputInterface()
protected function createInputInterfaceMock($interactive = true)
{
- $mock = $this->getMockBuilder('Symfony\Component\Console\Input\InputInterface')->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 5d3ebe170..b57ac1d60 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');
+ $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')->getMock();
+ $mock = $this->createMock(InputInterface::class);
$mock->expects($this->any())
->method('isInteractive')
->willReturn($interactive);
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]);
}
}
diff --git a/Tests/Helper/TableStyleTest.php b/Tests/Helper/TableStyleTest.php
index 4aa2ac878..5ff28f19f 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(31);
diff --git a/Tests/Helper/TableTest.php b/Tests/Helper/TableTest.php
index 0337053e9..cc1d1ecde 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;
@@ -1015,7 +1017,7 @@ public function testColumnStyle()
public function testThrowsWhenTheCellInAnArray()
{
- $this->expectException('Symfony\Component\Console\Exception\InvalidArgumentException');
+ $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
@@ -1190,7 +1192,7 @@ public function testSectionOutputWithoutDecoration()
public function testAppendRowWithoutSectionOutput()
{
- $this->expectException('Symfony\Component\Console\Exception\RuntimeException');
+ $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());
@@ -1231,7 +1233,7 @@ public function testSectionOutputHandlesZeroRowsAfterRender()
public function testIsNotDefinedStyleException()
{
- $this->expectException('Symfony\Component\Console\Exception\InvalidArgumentException');
+ $this->expectException(InvalidArgumentException::class);
$this->expectExceptionMessage('Style "absent" is not defined.');
$table = new Table($this->getOutputStream());
$table->setStyle('absent');
@@ -1239,7 +1241,7 @@ public function testIsNotDefinedStyleException()
public function testGetStyleDefinition()
{
- $this->expectException('Symfony\Component\Console\Exception\InvalidArgumentException');
+ $this->expectException(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 57a561091..6c4af6fb7 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..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');
+ $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 283eccaf2..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;
@@ -20,8 +21,6 @@
use Symfony\Component\Console\Tests\Fixtures\DummyOutput;
/**
- * Console logger test.
- *
* @author Kévin Dunglas
* @author Jordi Boggiano
*/
@@ -105,7 +104,7 @@ public function testHasErrored()
public function testImplements()
{
- $this->assertInstanceOf('Psr\Log\LoggerInterface', $this->getLogger());
+ $this->assertInstanceOf(LoggerInterface::class, $this->getLogger());
}
/**
@@ -140,7 +139,7 @@ public function provideLevelsAndMessages()
public function testThrowsOnInvalidLevel()
{
- $this->expectException('Psr\Log\InvalidArgumentException');
+ $this->expectException(InvalidArgumentException::class);
$logger = $this->getLogger();
$logger->log('invalid level', 'Foo');
}
@@ -157,9 +156,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');
diff --git a/Tests/Output/ConsoleSectionOutputTest.php b/Tests/Output/ConsoleSectionOutputTest.php
index 6abe040b4..206b201bc 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,11 +143,11 @@ 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);
- $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/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/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();
diff --git a/Tests/Style/SymfonyStyleTest.php b/Tests/Style/SymfonyStyleTest.php
index 16bb2baec..60ac39c15 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());
}
diff --git a/Tests/Tester/CommandTesterTest.php b/Tests/Tester/CommandTesterTest.php
index a7c4b5710..8a31b676b 100644
--- a/Tests/Tester/CommandTesterTest.php
+++ b/Tests/Tester/CommandTesterTest.php
@@ -160,7 +160,7 @@ public function testCommandWithDefaultInputs()
public function testCommandWithWrongInputsNumber()
{
- $this->expectException('RuntimeException');
+ $this->expectException(\RuntimeException::class);
$this->expectExceptionMessage('Aborted.');
$questions = [
'What\'s your name?',
@@ -185,7 +185,7 @@ public function testCommandWithWrongInputsNumber()
public function testCommandWithQuestionsButNoInputs()
{
- $this->expectException('RuntimeException');
+ $this->expectException(\RuntimeException::class);
$this->expectExceptionMessage('Aborted.');
$questions = [
'What\'s your name?',
diff --git a/composer.json b/composer.json
index 998626028..6d051f186 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": ["console", "cli", "command line", "terminal"],
"homepage": "https://symfony.com/",
"license": "MIT",