Skip to content

Commit 6ceb165

Browse files
committed
minor #37773 Modernized deprecated PHPUnit assertion calls (derrabus)
This PR was squashed before being merged into the 3.4 branch. Discussion ---------- Modernized deprecated PHPUnit assertion calls | Q | A | ------------- | --- | Branch? | 3.4 | Bug fix? | yes | New feature? | no | Deprecations? | no | Tickets | Part of #37564 | License | MIT | Doc PR | N/A Some assertions have been renamed in PHPUnit 9. PhpUnitBridge should already have polyfills in place for those methods, so it should be save to use them. Commits ------- ab417f7040 Modernized deprecated PHPUnit assertion calls
2 parents 32e3fbc + 6367c31 commit 6ceb165

File tree

2 files changed

+21
-21
lines changed

2 files changed

+21
-21
lines changed

Tests/ApplicationTest.php

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -501,9 +501,9 @@ public function testFindAlternativeExceptionMessageMultiple()
501501
$this->fail('->find() throws a CommandNotFoundException if command does not exist, with alternatives');
502502
} catch (\Exception $e) {
503503
$this->assertInstanceOf('Symfony\Component\Console\Exception\CommandNotFoundException', $e, '->find() throws a CommandNotFoundException if command does not exist, with alternatives');
504-
$this->assertRegExp('/Did you mean one of these/', $e->getMessage(), '->find() throws a CommandNotFoundException if command does not exist, with alternatives');
505-
$this->assertRegExp('/foo1:bar/', $e->getMessage());
506-
$this->assertRegExp('/foo:bar/', $e->getMessage());
504+
$this->assertMatchesRegularExpression('/Did you mean one of these/', $e->getMessage(), '->find() throws a CommandNotFoundException if command does not exist, with alternatives');
505+
$this->assertMatchesRegularExpression('/foo1:bar/', $e->getMessage());
506+
$this->assertMatchesRegularExpression('/foo:bar/', $e->getMessage());
507507
}
508508

509509
// Namespace + plural
@@ -512,8 +512,8 @@ public function testFindAlternativeExceptionMessageMultiple()
512512
$this->fail('->find() throws a CommandNotFoundException if command does not exist, with alternatives');
513513
} catch (\Exception $e) {
514514
$this->assertInstanceOf('Symfony\Component\Console\Exception\CommandNotFoundException', $e, '->find() throws a CommandNotFoundException if command does not exist, with alternatives');
515-
$this->assertRegExp('/Did you mean one of these/', $e->getMessage(), '->find() throws a CommandNotFoundException if command does not exist, with alternatives');
516-
$this->assertRegExp('/foo1/', $e->getMessage());
515+
$this->assertMatchesRegularExpression('/Did you mean one of these/', $e->getMessage(), '->find() throws a CommandNotFoundException if command does not exist, with alternatives');
516+
$this->assertMatchesRegularExpression('/foo1/', $e->getMessage());
517517
}
518518

519519
$application->add(new \Foo3Command());
@@ -525,8 +525,8 @@ public function testFindAlternativeExceptionMessageMultiple()
525525
$this->fail('->find() should throw an Symfony\Component\Console\Exception\CommandNotFoundException if a command is ambiguous because of a subnamespace, with alternatives');
526526
} catch (\Exception $e) {
527527
$this->assertInstanceOf('Symfony\Component\Console\Exception\CommandNotFoundException', $e);
528-
$this->assertRegExp('/foo3:bar/', $e->getMessage());
529-
$this->assertRegExp('/foo3:bar:toh/', $e->getMessage());
528+
$this->assertMatchesRegularExpression('/foo3:bar/', $e->getMessage());
529+
$this->assertMatchesRegularExpression('/foo3:bar:toh/', $e->getMessage());
530530
}
531531
}
532532

@@ -555,10 +555,10 @@ public function testFindAlternativeCommands()
555555
} catch (\Exception $e) {
556556
$this->assertInstanceOf('Symfony\Component\Console\Exception\CommandNotFoundException', $e, '->find() throws a CommandNotFoundException if command does not exist');
557557
$this->assertSame(['afoobar1', 'foo:bar1'], $e->getAlternatives());
558-
$this->assertRegExp(sprintf('/Command "%s" is not defined./', $commandName), $e->getMessage(), '->find() throws a CommandNotFoundException if command does not exist, with alternatives');
559-
$this->assertRegExp('/afoobar1/', $e->getMessage(), '->find() throws a CommandNotFoundException if command does not exist, with alternative : "afoobar1"');
560-
$this->assertRegExp('/foo:bar1/', $e->getMessage(), '->find() throws a CommandNotFoundException if command does not exist, with alternative : "foo:bar1"');
561-
$this->assertNotRegExp('/foo:bar(?!1)/', $e->getMessage(), '->find() throws a CommandNotFoundException if command does not exist, without "foo:bar" alternative');
558+
$this->assertMatchesRegularExpression(sprintf('/Command "%s" is not defined./', $commandName), $e->getMessage(), '->find() throws a CommandNotFoundException if command does not exist, with alternatives');
559+
$this->assertMatchesRegularExpression('/afoobar1/', $e->getMessage(), '->find() throws a CommandNotFoundException if command does not exist, with alternative : "afoobar1"');
560+
$this->assertMatchesRegularExpression('/foo:bar1/', $e->getMessage(), '->find() throws a CommandNotFoundException if command does not exist, with alternative : "foo:bar1"');
561+
$this->assertDoesNotMatchRegularExpression('/foo:bar(?!1)/', $e->getMessage(), '->find() throws a CommandNotFoundException if command does not exist, without "foo:bar" alternative');
562562
}
563563
}
564564

@@ -605,10 +605,10 @@ public function testFindAlternativeNamespace()
605605
$this->assertContains('foo', $e->getAlternatives());
606606
$this->assertContains('foo1', $e->getAlternatives());
607607
$this->assertContains('foo3', $e->getAlternatives());
608-
$this->assertRegExp('/There are no commands defined in the "foo2" namespace./', $e->getMessage(), '->find() throws a CommandNotFoundException if namespace does not exist, with alternative');
609-
$this->assertRegExp('/foo/', $e->getMessage(), '->find() throws a CommandNotFoundException if namespace does not exist, with alternative : "foo"');
610-
$this->assertRegExp('/foo1/', $e->getMessage(), '->find() throws a CommandNotFoundException if namespace does not exist, with alternative : "foo1"');
611-
$this->assertRegExp('/foo3/', $e->getMessage(), '->find() throws a CommandNotFoundException if namespace does not exist, with alternative : "foo3"');
608+
$this->assertMatchesRegularExpression('/There are no commands defined in the "foo2" namespace./', $e->getMessage(), '->find() throws a CommandNotFoundException if namespace does not exist, with alternative');
609+
$this->assertMatchesRegularExpression('/foo/', $e->getMessage(), '->find() throws a CommandNotFoundException if namespace does not exist, with alternative : "foo"');
610+
$this->assertMatchesRegularExpression('/foo1/', $e->getMessage(), '->find() throws a CommandNotFoundException if namespace does not exist, with alternative : "foo1"');
611+
$this->assertMatchesRegularExpression('/foo3/', $e->getMessage(), '->find() throws a CommandNotFoundException if namespace does not exist, with alternative : "foo3"');
612612
}
613613
}
614614

@@ -639,7 +639,7 @@ public function testFindAlternativesOutput()
639639
$this->assertInstanceOf('Symfony\Component\Console\Exception\CommandNotFoundException', $e, '->find() throws a CommandNotFoundException if command is not defined');
640640
$this->assertSame($expectedAlternatives, $e->getAlternatives());
641641

642-
$this->assertRegExp('/Command "foo" is not defined\..*Did you mean one of these\?.*/Ums', $e->getMessage());
642+
$this->assertMatchesRegularExpression('/Command "foo" is not defined\..*Did you mean one of these\?.*/Ums', $e->getMessage());
643643
}
644644
}
645645

@@ -721,9 +721,9 @@ public function testRenderException()
721721
$this->assertStringEqualsFile(self::$fixturesPath.'/application_renderexception3.txt', $tester->getErrorOutput(true), '->renderException() renders a pretty exceptions with previous exceptions');
722722

723723
$tester->run(['command' => 'foo3:bar'], ['decorated' => false, 'verbosity' => Output::VERBOSITY_VERBOSE]);
724-
$this->assertRegExp('/\[Exception\]\s*First exception/', $tester->getDisplay(), '->renderException() renders a pretty exception without code exception when code exception is default and verbosity is verbose');
725-
$this->assertRegExp('/\[Exception\]\s*Second exception/', $tester->getDisplay(), '->renderException() renders a pretty exception without code exception when code exception is 0 and verbosity is verbose');
726-
$this->assertRegExp('/\[Exception \(404\)\]\s*Third exception/', $tester->getDisplay(), '->renderException() renders a pretty exception with code exception when code exception is 404 and verbosity is verbose');
724+
$this->assertMatchesRegularExpression('/\[Exception\]\s*First exception/', $tester->getDisplay(), '->renderException() renders a pretty exception without code exception when code exception is default and verbosity is verbose');
725+
$this->assertMatchesRegularExpression('/\[Exception\]\s*Second exception/', $tester->getDisplay(), '->renderException() renders a pretty exception without code exception when code exception is 0 and verbosity is verbose');
726+
$this->assertMatchesRegularExpression('/\[Exception \(404\)\]\s*Third exception/', $tester->getDisplay(), '->renderException() renders a pretty exception with code exception when code exception is 404 and verbosity is verbose');
727727

728728
$tester->run(['command' => 'foo3:bar'], ['decorated' => true]);
729729
$this->assertStringEqualsFile(self::$fixturesPath.'/application_renderexception3decorated.txt', $tester->getDisplay(true), '->renderException() renders a pretty exceptions with previous exceptions');

Tests/Command/ListCommandTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,15 @@ public function testExecuteListsCommands()
2323
$commandTester = new CommandTester($command = $application->get('list'));
2424
$commandTester->execute(['command' => $command->getName()], ['decorated' => false]);
2525

26-
$this->assertRegExp('/help\s{2,}Displays help for a command/', $commandTester->getDisplay(), '->execute() returns a list of available commands');
26+
$this->assertMatchesRegularExpression('/help\s{2,}Displays help for a command/', $commandTester->getDisplay(), '->execute() returns a list of available commands');
2727
}
2828

2929
public function testExecuteListsCommandsWithXmlOption()
3030
{
3131
$application = new Application();
3232
$commandTester = new CommandTester($command = $application->get('list'));
3333
$commandTester->execute(['command' => $command->getName(), '--format' => 'xml']);
34-
$this->assertRegExp('/<command id="list" name="list" hidden="0">/', $commandTester->getDisplay(), '->execute() returns a list of available commands in XML if --xml is passed');
34+
$this->assertMatchesRegularExpression('/<command id="list" name="list" hidden="0">/', $commandTester->getDisplay(), '->execute() returns a list of available commands in XML if --xml is passed');
3535
}
3636

3737
public function testExecuteListsCommandsWithRawOption()

0 commit comments

Comments
 (0)