Skip to content

Commit

Permalink
bug #36408 [PhpUnitBridge] add PolyfillTestCaseTrait::expectException…
Browse files Browse the repository at this point in the history
…MessageMatches to provide FC with recent phpunit versions (soyuka)

This PR was squashed before being merged into the 4.4 branch.

Discussion
----------

[PhpUnitBridge] add PolyfillTestCaseTrait::expectExceptionMessageMatches to provide FC with recent phpunit versions

| Q             | A
| ------------- | ---
| Branch?       | 4.4
| Bug fix?      | yes
| New feature?  | no <!-- please update src/**/CHANGELOG.md files -->
| Deprecations? | no <!-- please update UPGRADE-*.md and src/**/CHANGELOG.md files -->
| Tickets       | na
| License       | MIT
| Doc PR        | na

expectExceptionMessageRegExp is deprecated coming phpunit 8.5.3  see sebastianbergmann/phpunit#4133

Not sure if I need to add something else lmk.

Commits
-------

cfd5a29eaf [PhpUnitBridge] add PolyfillTestCaseTrait::expectExceptionMessageMatches to provide FC with recent phpunit versions
  • Loading branch information
nicolas-grekas committed Apr 15, 2020
2 parents 8ff02d3 + 2ed631d commit 2e02a27
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 17 deletions.
2 changes: 1 addition & 1 deletion Tests/Compiler/ResolveChildDefinitionsPassTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,7 @@ protected function process(ContainerBuilder $container)
public function testProcessDetectsChildDefinitionIndirectCircularReference()
{
$this->expectException('Symfony\Component\DependencyInjection\Exception\ServiceCircularReferenceException');
$this->expectExceptionMessageRegExp('/^Circular reference detected for service "c", path: "c -> b -> a -> c"./');
$this->expectExceptionMessageMatches('/^Circular reference detected for service "c", path: "c -> b -> a -> c"./');
$container = new ContainerBuilder();

$container->register('a');
Expand Down
2 changes: 1 addition & 1 deletion Tests/Compiler/ResolveInstanceofConditionalsPassTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ public function testProcessForAutoconfiguredCalls()
public function testProcessThrowsExceptionForArguments()
{
$this->expectException('Symfony\Component\DependencyInjection\Exception\InvalidArgumentException');
$this->expectExceptionMessageRegExp('/Autoconfigured instanceof for type "PHPUnit[\\\\_]Framework[\\\\_]TestCase" defines arguments but these are not supported and should be removed\./');
$this->expectExceptionMessageMatches('/Autoconfigured instanceof for type "PHPUnit[\\\\_]Framework[\\\\_]TestCase" defines arguments but these are not supported and should be removed\./');
$container = new ContainerBuilder();
$container->registerForAutoconfiguration(parent::class)
->addArgument('bar');
Expand Down
2 changes: 1 addition & 1 deletion Tests/Compiler/ValidateEnvPlaceholdersPassTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ public function testInvalidEnvInConfig()
public function testNulledEnvInConfig()
{
$this->expectException('Symfony\Component\Config\Definition\Exception\InvalidTypeException');
$this->expectExceptionMessageRegexp('/^Invalid type for path "env_extension\.int_node"\. Expected "?int"?, but got (NULL|"null")\.$/');
$this->expectExceptionMessageMatches('/^Invalid type for path "env_extension\.int_node"\. Expected "?int"?, but got (NULL|"null")\.$/');
$container = new ContainerBuilder();
$container->setParameter('env(NULLED)', null);
$container->registerExtension(new EnvExtension());
Expand Down
2 changes: 1 addition & 1 deletion Tests/Loader/FileLoaderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ public function testMissingParentClass()
public function testRegisterClassesWithBadPrefix()
{
$this->expectException('Symfony\Component\DependencyInjection\Exception\InvalidArgumentException');
$this->expectExceptionMessageRegExp('/Expected to find class "Symfony\\\Component\\\DependencyInjection\\\Tests\\\Fixtures\\\Prototype\\\Bar" in file ".+" while importing services from resource "Prototype\/Sub\/\*", but it was not found\! Check the namespace prefix used with the resource/');
$this->expectExceptionMessageMatches('/Expected to find class "Symfony\\\Component\\\DependencyInjection\\\Tests\\\Fixtures\\\Prototype\\\Bar" in file ".+" while importing services from resource "Prototype\/Sub\/\*", but it was not found\! Check the namespace prefix used with the resource/');
$container = new ContainerBuilder();
$loader = new TestFileLoader($container, new FileLocator(self::$fixturesPath.'/Fixtures'));

Expand Down
2 changes: 1 addition & 1 deletion Tests/Loader/XmlFileLoaderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,7 @@ public function testParseTagsWithoutNameThrowsException()
public function testParseTagWithEmptyNameThrowsException()
{
$this->expectException('Symfony\Component\DependencyInjection\Exception\InvalidArgumentException');
$this->expectExceptionMessageRegExp('/The tag name for service ".+" in .* must be a non-empty string/');
$this->expectExceptionMessageMatches('/The tag name for service ".+" in .* must be a non-empty string/');
$container = new ContainerBuilder();
$loader = new XmlFileLoader($container, new FileLocator(self::$fixturesPath.'/xml'));
$loader->load('tag_with_empty_name.xml');
Expand Down
24 changes: 12 additions & 12 deletions Tests/Loader/YamlFileLoaderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public static function setUpBeforeClass(): void
public function testLoadUnExistFile()
{
$this->expectException('Symfony\Component\DependencyInjection\Exception\InvalidArgumentException');
$this->expectExceptionMessageRegExp('/The file ".+" does not exist./');
$this->expectExceptionMessageMatches('/The file ".+" does not exist./');
$loader = new YamlFileLoader(new ContainerBuilder(), new FileLocator(self::$fixturesPath.'/ini'));
$r = new \ReflectionObject($loader);
$m = $r->getMethod('loadFile');
Expand All @@ -62,7 +62,7 @@ public function testLoadUnExistFile()
public function testLoadInvalidYamlFile()
{
$this->expectException('Symfony\Component\DependencyInjection\Exception\InvalidArgumentException');
$this->expectExceptionMessageRegExp('/The file ".+" does not contain valid YAML./');
$this->expectExceptionMessageMatches('/The file ".+" does not contain valid YAML./');
$path = self::$fixturesPath.'/ini';
$loader = new YamlFileLoader(new ContainerBuilder(), new FileLocator($path));
$r = new \ReflectionObject($loader);
Expand Down Expand Up @@ -395,15 +395,15 @@ public function testLoadYamlOnlyWithKeys()
public function testTagWithEmptyNameThrowsException()
{
$this->expectException('Symfony\Component\DependencyInjection\Exception\InvalidArgumentException');
$this->expectExceptionMessageRegExp('/The tag name for service ".+" in .+ must be a non-empty string/');
$this->expectExceptionMessageMatches('/The tag name for service ".+" in .+ must be a non-empty string/');
$loader = new YamlFileLoader(new ContainerBuilder(), new FileLocator(self::$fixturesPath.'/yaml'));
$loader->load('tag_name_empty_string.yml');
}

public function testTagWithNonStringNameThrowsException()
{
$this->expectException('Symfony\Component\DependencyInjection\Exception\InvalidArgumentException');
$this->expectExceptionMessageRegExp('/The tag name for service ".+" in .+ must be a non-empty string/');
$this->expectExceptionMessageMatches('/The tag name for service ".+" in .+ must be a non-empty string/');
$loader = new YamlFileLoader(new ContainerBuilder(), new FileLocator(self::$fixturesPath.'/yaml'));
$loader->load('tag_name_no_string.yml');
}
Expand Down Expand Up @@ -504,7 +504,7 @@ public function testPrototypeWithNamespace()
public function testPrototypeWithNamespaceAndNoResource()
{
$this->expectException('Symfony\Component\DependencyInjection\Exception\InvalidArgumentException');
$this->expectExceptionMessageRegExp('/A "resource" attribute must be set when the "namespace" attribute is set for service ".+" in .+/');
$this->expectExceptionMessageMatches('/A "resource" attribute must be set when the "namespace" attribute is set for service ".+" in .+/');
$container = new ContainerBuilder();
$loader = new YamlFileLoader($container, new FileLocator(self::$fixturesPath.'/yaml'));
$loader->load('services_prototype_namespace_without_resource.yml');
Expand Down Expand Up @@ -632,7 +632,7 @@ public function testDecoratedServicesWithWrongOnInvalidSyntaxThrowsException()
public function testInvalidTagsWithDefaults()
{
$this->expectException('Symfony\Component\DependencyInjection\Exception\InvalidArgumentException');
$this->expectExceptionMessageRegExp('/Parameter "tags" must be an array for service "Foo\\\Bar" in ".+services31_invalid_tags\.yml"\. Check your YAML syntax./');
$this->expectExceptionMessageMatches('/Parameter "tags" must be an array for service "Foo\\\Bar" in ".+services31_invalid_tags\.yml"\. Check your YAML syntax./');
$loader = new YamlFileLoader(new ContainerBuilder(), new FileLocator(self::$fixturesPath.'/yaml'));
$loader->load('services31_invalid_tags.yml');
}
Expand Down Expand Up @@ -722,7 +722,7 @@ public function testAnonymousServicesInInstanceof()
public function testAnonymousServicesWithAliases()
{
$this->expectException('Symfony\Component\DependencyInjection\Exception\InvalidArgumentException');
$this->expectExceptionMessageRegExp('/Creating an alias using the tag "!service" is not allowed in ".+anonymous_services_alias\.yml"\./');
$this->expectExceptionMessageMatches('/Creating an alias using the tag "!service" is not allowed in ".+anonymous_services_alias\.yml"\./');
$container = new ContainerBuilder();
$loader = new YamlFileLoader($container, new FileLocator(self::$fixturesPath.'/yaml'));
$loader->load('anonymous_services_alias.yml');
Expand All @@ -731,7 +731,7 @@ public function testAnonymousServicesWithAliases()
public function testAnonymousServicesInParameters()
{
$this->expectException('Symfony\Component\DependencyInjection\Exception\InvalidArgumentException');
$this->expectExceptionMessageRegExp('/Using an anonymous service in a parameter is not allowed in ".+anonymous_services_in_parameters\.yml"\./');
$this->expectExceptionMessageMatches('/Using an anonymous service in a parameter is not allowed in ".+anonymous_services_in_parameters\.yml"\./');
$container = new ContainerBuilder();
$loader = new YamlFileLoader($container, new FileLocator(self::$fixturesPath.'/yaml'));
$loader->load('anonymous_services_in_parameters.yml');
Expand All @@ -750,7 +750,7 @@ public function testAutoConfigureInstanceof()
public function testEmptyDefaultsThrowsClearException()
{
$this->expectException('Symfony\Component\DependencyInjection\Exception\InvalidArgumentException');
$this->expectExceptionMessageRegExp('/Service "_defaults" key must be an array, "NULL" given in ".+bad_empty_defaults\.yml"\./');
$this->expectExceptionMessageMatches('/Service "_defaults" key must be an array, "NULL" given in ".+bad_empty_defaults\.yml"\./');
$container = new ContainerBuilder();
$loader = new YamlFileLoader($container, new FileLocator(self::$fixturesPath.'/yaml'));
$loader->load('bad_empty_defaults.yml');
Expand All @@ -759,7 +759,7 @@ public function testEmptyDefaultsThrowsClearException()
public function testEmptyInstanceofThrowsClearException()
{
$this->expectException('Symfony\Component\DependencyInjection\Exception\InvalidArgumentException');
$this->expectExceptionMessageRegExp('/Service "_instanceof" key must be an array, "NULL" given in ".+bad_empty_instanceof\.yml"\./');
$this->expectExceptionMessageMatches('/Service "_instanceof" key must be an array, "NULL" given in ".+bad_empty_instanceof\.yml"\./');
$container = new ContainerBuilder();
$loader = new YamlFileLoader($container, new FileLocator(self::$fixturesPath.'/yaml'));
$loader->load('bad_empty_instanceof.yml');
Expand All @@ -768,7 +768,7 @@ public function testEmptyInstanceofThrowsClearException()
public function testUnsupportedKeywordThrowsException()
{
$this->expectException('Symfony\Component\DependencyInjection\Exception\InvalidArgumentException');
$this->expectExceptionMessageRegExp('/^The configuration key "private" is unsupported for definition "bar"/');
$this->expectExceptionMessageMatches('/^The configuration key "private" is unsupported for definition "bar"/');
$container = new ContainerBuilder();
$loader = new YamlFileLoader($container, new FileLocator(self::$fixturesPath.'/yaml'));
$loader->load('bad_keyword.yml');
Expand All @@ -777,7 +777,7 @@ public function testUnsupportedKeywordThrowsException()
public function testUnsupportedKeywordInServiceAliasThrowsException()
{
$this->expectException('Symfony\Component\DependencyInjection\Exception\InvalidArgumentException');
$this->expectExceptionMessageRegExp('/^The configuration key "calls" is unsupported for the service "bar" which is defined as an alias/');
$this->expectExceptionMessageMatches('/^The configuration key "calls" is unsupported for the service "bar" which is defined as an alias/');
$container = new ContainerBuilder();
$loader = new YamlFileLoader($container, new FileLocator(self::$fixturesPath.'/yaml'));
$loader->load('bad_alias.yml');
Expand Down

0 comments on commit 2e02a27

Please sign in to comment.