diff --git a/Tests/ApplicationTest.php b/Tests/ApplicationTest.php index ab3684e1b..7df8dfb57 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'); @@ -937,7 +939,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 1b57c2070..2b5384ab1 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; @@ -286,7 +287,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 e0bc6968b..10c9c792e 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(); @@ -897,7 +899,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 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()); }