Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion composer.json
Expand Up @@ -118,7 +118,7 @@
"psr/http-client": "^1.0",
"psr/simple-cache": "^1.0",
"egulias/email-validator": "~1.2,>=1.2.8|~2.0",
"symfony/phpunit-bridge": "^3.4.31|^4.3.4|~5.0",
"symfony/phpunit-bridge": "^5.0.8",
"symfony/security-acl": "~2.8|~3.0",
"phpdocumentor/reflection-docblock": "^3.0|^4.0",
"twig/cssinliner-extra": "^2.12",
Expand Down
10 changes: 10 additions & 0 deletions src/Symfony/Bridge/PhpUnit/Legacy/PolyfillTestCaseTrait.php
Expand Up @@ -95,6 +95,16 @@ public function expectExceptionMessage($message)
$property->setValue($this, $message);
}

/**
* @param string $messageRegExp
*
* @return void
*/
public function expectExceptionMessageMatches($messageRegExp)
{
$this->expectExceptionMessageRegExp($messageRegExp);
}

/**
* @param string $messageRegExp
*
Expand Down
Expand Up @@ -101,7 +101,7 @@ public function testTwigErrorIfLocatorReturnsFalse()
public function testTwigErrorIfTemplateDoesNotExist()
{
$this->expectException('Twig\Error\LoaderError');
$this->expectExceptionMessageRegExp('/Unable to find template "name\.format\.engine" \(looked into: .*Tests.Loader.\.\..DependencyInjection.Fixtures.templates\)/');
$this->expectExceptionMessageMatches('/Unable to find template "name\.format\.engine" \(looked into: .*Tests.Loader.\.\..DependencyInjection.Fixtures.templates\)/');
$parser = $this->getMockBuilder('Symfony\Component\Templating\TemplateNameParserInterface')->getMock();
$locator = $this->getMockBuilder('Symfony\Component\Config\FileLocatorInterface')->getMock();

Expand Down
Expand Up @@ -66,7 +66,7 @@ public function testGetPattern()
public function testResourceDoesNotExist()
{
$this->expectException('InvalidArgumentException');
$this->expectExceptionMessageRegExp('/The directory ".*" does not exist./');
$this->expectExceptionMessageMatches('/The directory ".*" does not exist./');
new DirectoryResource('/____foo/foobar'.mt_rand(1, 999999));
}

Expand Down
Expand Up @@ -56,7 +56,7 @@ public function testToString()
public function testResourceDoesNotExist()
{
$this->expectException('InvalidArgumentException');
$this->expectExceptionMessageRegExp('/The file ".*" does not exist./');
$this->expectExceptionMessageMatches('/The file ".*" does not exist./');
new FileResource('/____foo/foobar'.mt_rand(1, 999999));
}

Expand Down
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
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
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
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
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
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 @@ -384,15 +384,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 @@ -493,7 +493,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 @@ -621,7 +621,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 @@ -711,7 +711,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 @@ -720,7 +720,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 @@ -739,7 +739,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 @@ -748,7 +748,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 @@ -757,7 +757,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 @@ -766,7 +766,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
Expand Up @@ -231,7 +231,7 @@ public function testRegisterAfterEval($registerCallback)
public function testCallBadCallable()
{
$this->expectException('RuntimeException');
$this->expectExceptionMessageRegExp('/Unable to call method "\w+" of object "\w+"./');
$this->expectExceptionMessageMatches('/Unable to call method "\w+" of object "\w+"./');
$el = new ExpressionLanguage();
$el->evaluate('foo.myfunction()', ['foo' => new \stdClass()]);
}
Expand Down
Expand Up @@ -197,7 +197,7 @@ public function provideCustomFalseValues()
public function testDontAllowNonArrayFalseValues()
{
$this->expectException('Symfony\Component\OptionsResolver\Exception\InvalidOptionsException');
$this->expectExceptionMessageRegExp('/"false_values" with value "invalid" is expected to be of type "array"/');
$this->expectExceptionMessageMatches('/"false_values" with value "invalid" is expected to be of type "array"/');
$this->factory->create(static::TESTED_TYPE, null, [
'false_values' => 'invalid',
]);
Expand Down
Expand Up @@ -19,7 +19,7 @@ class SocketStreamTest extends TestCase
public function testSocketErrorNoConnection()
{
$this->expectException('Symfony\Component\Mailer\Exception\TransportException');
$this->expectExceptionMessageRegExp('/Connection refused|unable to connect/');
$this->expectExceptionMessageMatches('/Connection refused|unable to connect/');
$s = new SocketStream();
$s->setTimeout(0.1);
$s->setPort(9999);
Expand All @@ -29,7 +29,7 @@ public function testSocketErrorNoConnection()
public function testSocketErrorBeforeConnectError()
{
$this->expectException('Symfony\Component\Mailer\Exception\TransportException');
$this->expectExceptionMessageRegExp('/no valid certs found cafile stream|Unable to find the socket transport "ssl"/');
$this->expectExceptionMessageMatches('/no valid certs found cafile stream|Unable to find the socket transport "ssl"/');
$s = new SocketStream();
$s->setStreamOptions([
'ssl' => [
Expand Down
Expand Up @@ -44,7 +44,7 @@ public function testDecodingFailsWithMissingBodyKey()
public function testDecodingFailsWithBadFormat()
{
$this->expectException(MessageDecodingFailedException::class);
$this->expectExceptionMessageRegExp('/Could not decode/');
$this->expectExceptionMessageMatches('/Could not decode/');

$serializer = new PhpSerializer();

Expand All @@ -56,7 +56,7 @@ public function testDecodingFailsWithBadFormat()
public function testDecodingFailsWithBadClass()
{
$this->expectException(MessageDecodingFailedException::class);
$this->expectExceptionMessageRegExp('/class "ReceivedSt0mp" not found/');
$this->expectExceptionMessageMatches('/class "ReceivedSt0mp" not found/');

$serializer = new PhpSerializer();

Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Component/Process/Tests/ProcessTest.php
Expand Up @@ -50,7 +50,7 @@ protected function tearDown(): void
public function testInvalidCwd()
{
$this->expectException('Symfony\Component\Process\Exception\RuntimeException');
$this->expectExceptionMessageRegExp('/The provided cwd ".*" does not exist\./');
$this->expectExceptionMessageMatches('/The provided cwd ".*" does not exist\./');
try {
// Check that it works fine if the CWD exists
$cmd = new Process(['echo', 'test'], __DIR__);
Expand Down
Expand Up @@ -149,7 +149,7 @@ public function testSetValueCallsAdderAndRemoverForNestedCollections()
public function testSetValueFailsIfNoAdderNorRemoverFound()
{
$this->expectException('Symfony\Component\PropertyAccess\Exception\NoSuchPropertyException');
$this->expectExceptionMessageRegExp('/Could not determine access type for property "axes" in class "Mock_PropertyAccessorCollectionTest_CarNoAdderAndRemover_[^"]*"./');
$this->expectExceptionMessageMatches('/Could not determine access type for property "axes" in class "Mock_PropertyAccessorCollectionTest_CarNoAdderAndRemover_[^"]*"./');
$car = $this->getMockBuilder(__CLASS__.'_CarNoAdderAndRemover')->getMock();
$axesBefore = $this->getContainer([1 => 'second', 3 => 'fourth']);
$axesAfter = $this->getContainer([0 => 'first', 1 => 'second', 2 => 'third']);
Expand Down Expand Up @@ -188,7 +188,7 @@ public function testIsWritableReturnsFalseIfNoAdderNorRemoverExists()
public function testSetValueFailsIfAdderAndRemoverExistButValueIsNotTraversable()
{
$this->expectException('Symfony\Component\PropertyAccess\Exception\NoSuchPropertyException');
$this->expectExceptionMessageRegExp('/Could not determine access type for property "axes" in class "Symfony\\\\Component\\\\PropertyAccess\\\\Tests\\\\PropertyAccessorCollectionTest_Car[^"]*": The property "axes" in class "Symfony\\\\Component\\\\PropertyAccess\\\\Tests\\\\PropertyAccessorCollectionTest_Car[^"]*" can be defined with the methods "addAxis\(\)", "removeAxis\(\)" but the new value must be an array or an instance of \\\\Traversable, "string" given./');
$this->expectExceptionMessageMatches('/Could not determine access type for property "axes" in class "Symfony\\\\Component\\\\PropertyAccess\\\\Tests\\\\PropertyAccessorCollectionTest_Car[^"]*": The property "axes" in class "Symfony\\\\Component\\\\PropertyAccess\\\\Tests\\\\PropertyAccessorCollectionTest_Car[^"]*" can be defined with the methods "addAxis\(\)", "removeAxis\(\)" but the new value must be an array or an instance of \\\\Traversable, "string" given./');
$car = new PropertyAccessorCollectionTest_Car();

$this->propertyAccessor->setValue($car, 'axes', 'Not an array or Traversable');
Expand Down