Skip to content

Commit d62ec79

Browse files
Merge branch '5.1' into 5.2
* 5.1: Use createMock() and use import instead of FQCN
2 parents a5dbec2 + d9a267b commit d62ec79

16 files changed

+51
-37
lines changed

Tests/ApplicationTest.php

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use PHPUnit\Framework\TestCase;
1515
use Symfony\Component\Console\Application;
1616
use Symfony\Component\Console\Command\Command;
17+
use Symfony\Component\Console\Command\HelpCommand;
1718
use Symfony\Component\Console\Command\SignalableCommandInterface;
1819
use Symfony\Component\Console\CommandLoader\FactoryCommandLoader;
1920
use Symfony\Component\Console\DependencyInjection\AddConsoleCommandPass;
@@ -30,6 +31,7 @@
3031
use Symfony\Component\Console\Input\InputDefinition;
3132
use Symfony\Component\Console\Input\InputInterface;
3233
use Symfony\Component\Console\Input\InputOption;
34+
use Symfony\Component\Console\Output\ConsoleOutput;
3335
use Symfony\Component\Console\Output\NullOutput;
3436
use Symfony\Component\Console\Output\Output;
3537
use Symfony\Component\Console\Output\OutputInterface;
@@ -135,7 +137,7 @@ public function testAll()
135137
{
136138
$application = new Application();
137139
$commands = $application->all();
138-
$this->assertInstanceOf(\Symfony\Component\Console\Command\HelpCommand::class, $commands['help'], '->all() returns the registered commands');
140+
$this->assertInstanceOf(HelpCommand::class, $commands['help'], '->all() returns the registered commands');
139141

140142
$application->add(new \FooCommand());
141143
$commands = $application->all('foo');
@@ -146,7 +148,7 @@ public function testAllWithCommandLoader()
146148
{
147149
$application = new Application();
148150
$commands = $application->all();
149-
$this->assertInstanceOf(\Symfony\Component\Console\Command\HelpCommand::class, $commands['help'], '->all() returns the registered commands');
151+
$this->assertInstanceOf(HelpCommand::class, $commands['help'], '->all() returns the registered commands');
150152

151153
$application->add(new \FooCommand());
152154
$commands = $application->all('foo');
@@ -230,7 +232,7 @@ public function testHasGet()
230232
$p->setAccessible(true);
231233
$p->setValue($application, true);
232234
$command = $application->get('foo:bar');
233-
$this->assertInstanceOf(\Symfony\Component\Console\Command\HelpCommand::class, $command, '->get() returns the help command if --help is provided as the input');
235+
$this->assertInstanceOf(HelpCommand::class, $command, '->get() returns the help command if --help is provided as the input');
234236
}
235237

236238
public function testHasGetWithCommandLoader()
@@ -352,7 +354,7 @@ public function testFind()
352354
$application->add(new \FooCommand());
353355

354356
$this->assertInstanceOf(\FooCommand::class, $application->find('foo:bar'), '->find() returns a command if its name exists');
355-
$this->assertInstanceOf(\Symfony\Component\Console\Command\HelpCommand::class, $application->find('h'), '->find() returns a command if its name exists');
357+
$this->assertInstanceOf(HelpCommand::class, $application->find('h'), '->find() returns a command if its name exists');
356358
$this->assertInstanceOf(\FooCommand::class, $application->find('f:bar'), '->find() returns a command if the abbreviation for the namespace exists');
357359
$this->assertInstanceOf(\FooCommand::class, $application->find('f:b'), '->find() returns a command if the abbreviation for the namespace and the command name exist');
358360
$this->assertInstanceOf(\FooCommand::class, $application->find('a'), '->find() returns a command if the abbreviation exists for an alias');
@@ -399,7 +401,7 @@ public function testFindWithCommandLoader()
399401
]));
400402

401403
$this->assertInstanceOf(\FooCommand::class, $application->find('foo:bar'), '->find() returns a command if its name exists');
402-
$this->assertInstanceOf(\Symfony\Component\Console\Command\HelpCommand::class, $application->find('h'), '->find() returns a command if its name exists');
404+
$this->assertInstanceOf(HelpCommand::class, $application->find('h'), '->find() returns a command if its name exists');
403405
$this->assertInstanceOf(\FooCommand::class, $application->find('f:bar'), '->find() returns a command if the abbreviation for the namespace exists');
404406
$this->assertInstanceOf(\FooCommand::class, $application->find('f:b'), '->find() returns a command if the abbreviation for the namespace and the command name exist');
405407
$this->assertInstanceOf(\FooCommand::class, $application->find('a'), '->find() returns a command if the abbreviation exists for an alias');
@@ -938,7 +940,7 @@ public function testRun()
938940
ob_end_clean();
939941

940942
$this->assertInstanceOf(ArgvInput::class, $command->input, '->run() creates an ArgvInput by default if none is given');
941-
$this->assertInstanceOf(\Symfony\Component\Console\Output\ConsoleOutput::class, $command->output, '->run() creates a ConsoleOutput by default if none is given');
943+
$this->assertInstanceOf(ConsoleOutput::class, $command->output, '->run() creates a ConsoleOutput by default if none is given');
942944

943945
$application = new Application();
944946
$application->setAutoExit(false);

Tests/Command/CommandTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use PHPUnit\Framework\TestCase;
1515
use Symfony\Component\Console\Application;
1616
use Symfony\Component\Console\Command\Command;
17+
use Symfony\Component\Console\Exception\InvalidOptionException;
1718
use Symfony\Component\Console\Helper\FormatterHelper;
1819
use Symfony\Component\Console\Input\InputArgument;
1920
use Symfony\Component\Console\Input\InputDefinition;
@@ -286,7 +287,7 @@ public function testExecuteMethodNeedsToBeOverridden()
286287

287288
public function testRunWithInvalidOption()
288289
{
289-
$this->expectException(\Symfony\Component\Console\Exception\InvalidOptionException::class);
290+
$this->expectException(InvalidOptionException::class);
290291
$this->expectExceptionMessage('The "--bar" option does not exist.');
291292
$command = new \TestCommand();
292293
$tester = new CommandTester($command);

Tests/CommandLoader/ContainerCommandLoaderTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use PHPUnit\Framework\TestCase;
1515
use Symfony\Component\Console\Command\Command;
1616
use Symfony\Component\Console\CommandLoader\ContainerCommandLoader;
17+
use Symfony\Component\Console\Exception\CommandNotFoundException;
1718
use Symfony\Component\DependencyInjection\ServiceLocator;
1819

1920
class ContainerCommandLoaderTest extends TestCase
@@ -43,7 +44,7 @@ public function testGet()
4344

4445
public function testGetUnknownCommandThrows()
4546
{
46-
$this->expectException(\Symfony\Component\Console\Exception\CommandNotFoundException::class);
47+
$this->expectException(CommandNotFoundException::class);
4748
(new ContainerCommandLoader(new ServiceLocator([]), []))->get('unknown');
4849
}
4950

Tests/CommandLoader/FactoryCommandLoaderTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use PHPUnit\Framework\TestCase;
1515
use Symfony\Component\Console\Command\Command;
1616
use Symfony\Component\Console\CommandLoader\FactoryCommandLoader;
17+
use Symfony\Component\Console\Exception\CommandNotFoundException;
1718

1819
class FactoryCommandLoaderTest extends TestCase
1920
{
@@ -42,7 +43,7 @@ public function testGet()
4243

4344
public function testGetUnknownCommandThrows()
4445
{
45-
$this->expectException(\Symfony\Component\Console\Exception\CommandNotFoundException::class);
46+
$this->expectException(CommandNotFoundException::class);
4647
(new FactoryCommandLoader([]))->get('unknown');
4748
}
4849

Tests/EventListener/ErrorListenerTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ public function testCommandNameIsDisplayedForNonStringableInput()
117117
;
118118

119119
$listener = new ErrorListener($logger);
120-
$listener->onConsoleTerminate($this->getConsoleTerminateEvent($this->getMockBuilder(InputInterface::class)->getMock(), 255));
120+
$listener->onConsoleTerminate($this->getConsoleTerminateEvent($this->createMock(InputInterface::class), 255));
121121
}
122122

123123
private function getLogger()
@@ -132,7 +132,7 @@ private function getConsoleTerminateEvent(InputInterface $input, $exitCode)
132132

133133
private function getOutput()
134134
{
135-
return $this->getMockBuilder(OutputInterface::class)->getMock();
135+
return $this->createMock(OutputInterface::class);
136136
}
137137
}
138138

Tests/Helper/AbstractQuestionHelperTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ abstract class AbstractQuestionHelperTest extends TestCase
1818
{
1919
protected function createStreamableInputInterfaceMock($stream = null, $interactive = true)
2020
{
21-
$mock = $this->getMockBuilder(StreamableInputInterface::class)->getMock();
21+
$mock = $this->createMock(StreamableInputInterface::class);
2222
$mock->expects($this->any())
2323
->method('isInteractive')
2424
->willReturn($interactive);

Tests/Helper/DumperNativeFallbackTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public static function tearDownAfterClass(): void
3737
*/
3838
public function testInvoke($variable, $primitiveString)
3939
{
40-
$dumper = new Dumper($this->getMockBuilder(OutputInterface::class)->getMock());
40+
$dumper = new Dumper($this->createMock(OutputInterface::class));
4141

4242
$this->assertSame($primitiveString, $dumper($variable));
4343
}

Tests/Helper/DumperTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public static function tearDownAfterClass(): void
3737
*/
3838
public function testInvoke($variable)
3939
{
40-
$output = $this->getMockBuilder(OutputInterface::class)->getMock();
40+
$output = $this->createMock(OutputInterface::class);
4141
$output->method('isDecorated')->willReturn(false);
4242

4343
$dumper = new Dumper($output);

Tests/Helper/HelperSetTest.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
use PHPUnit\Framework\TestCase;
1515
use Symfony\Component\Console\Command\Command;
16+
use Symfony\Component\Console\Exception\ExceptionInterface;
1617
use Symfony\Component\Console\Helper\HelperInterface;
1718
use Symfony\Component\Console\Helper\HelperSet;
1819

@@ -68,7 +69,7 @@ public function testGet()
6869
$this->fail('->get() throws InvalidArgumentException when helper not found');
6970
} catch (\Exception $e) {
7071
$this->assertInstanceOf(\InvalidArgumentException::class, $e, '->get() throws InvalidArgumentException when helper not found');
71-
$this->assertInstanceOf(\Symfony\Component\Console\Exception\ExceptionInterface::class, $e, '->get() throws domain specific exception when helper not found');
72+
$this->assertInstanceOf(ExceptionInterface::class, $e, '->get() throws domain specific exception when helper not found');
7273
$this->assertStringContainsString('The helper "foo" is not defined.', $e->getMessage(), '->get() throws InvalidArgumentException when helper not found');
7374
}
7475
}
@@ -112,7 +113,7 @@ public function testIteration()
112113

113114
private function getGenericMockHelper($name, HelperSet $helperset = null)
114115
{
115-
$mock_helper = $this->getMockBuilder(HelperInterface::class)->getMock();
116+
$mock_helper = $this->createMock(HelperInterface::class);
116117
$mock_helper->expects($this->any())
117118
->method('getName')
118119
->willReturn($name);

Tests/Helper/QuestionHelperTest.php

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,12 @@
1313

1414
use Symfony\Component\Console\Application;
1515
use Symfony\Component\Console\Exception\InvalidArgumentException;
16+
use Symfony\Component\Console\Exception\MissingInputException;
1617
use Symfony\Component\Console\Formatter\OutputFormatter;
1718
use Symfony\Component\Console\Helper\FormatterHelper;
1819
use Symfony\Component\Console\Helper\HelperSet;
1920
use Symfony\Component\Console\Helper\QuestionHelper;
21+
use Symfony\Component\Console\Input\InputInterface;
2022
use Symfony\Component\Console\Output\OutputInterface;
2123
use Symfony\Component\Console\Output\StreamOutput;
2224
use Symfony\Component\Console\Question\ChoiceQuestion;
@@ -729,7 +731,7 @@ public function testChoiceOutputFormattingQuestionForUtf8Keys()
729731
' [<info>żółw </info>] bar',
730732
' [<info>łabądź</info>] baz',
731733
];
732-
$output = $this->getMockBuilder(OutputInterface::class)->getMock();
734+
$output = $this->createMock(OutputInterface::class);
733735
$output->method('getFormatter')->willReturn(new OutputFormatter());
734736

735737
$dialog = new QuestionHelper();
@@ -744,23 +746,23 @@ public function testChoiceOutputFormattingQuestionForUtf8Keys()
744746

745747
public function testAskThrowsExceptionOnMissingInput()
746748
{
747-
$this->expectException(\Symfony\Component\Console\Exception\MissingInputException::class);
749+
$this->expectException(MissingInputException::class);
748750
$this->expectExceptionMessage('Aborted.');
749751
$dialog = new QuestionHelper();
750752
$dialog->ask($this->createStreamableInputInterfaceMock($this->getInputStream('')), $this->createOutputInterface(), new Question('What\'s your name?'));
751753
}
752754

753755
public function testAskThrowsExceptionOnMissingInputForChoiceQuestion()
754756
{
755-
$this->expectException(\Symfony\Component\Console\Exception\MissingInputException::class);
757+
$this->expectException(MissingInputException::class);
756758
$this->expectExceptionMessage('Aborted.');
757759
$dialog = new QuestionHelper();
758760
$dialog->ask($this->createStreamableInputInterfaceMock($this->getInputStream('')), $this->createOutputInterface(), new ChoiceQuestion('Choice', ['a', 'b']));
759761
}
760762

761763
public function testAskThrowsExceptionOnMissingInputWithValidator()
762764
{
763-
$this->expectException(\Symfony\Component\Console\Exception\MissingInputException::class);
765+
$this->expectException(MissingInputException::class);
764766
$this->expectExceptionMessage('Aborted.');
765767
$dialog = new QuestionHelper();
766768

@@ -941,7 +943,7 @@ protected function createOutputInterface()
941943

942944
protected function createInputInterfaceMock($interactive = true)
943945
{
944-
$mock = $this->getMockBuilder(\Symfony\Component\Console\Input\InputInterface::class)->getMock();
946+
$mock = $this->createMock(InputInterface::class);
945947
$mock->expects($this->any())
946948
->method('isInteractive')
947949
->willReturn($interactive);

0 commit comments

Comments
 (0)