8000 [PhpUnitBridge] add PolyfillTestCaseTrait::expectExceptionMessageMatc… · symfony/symfony@cfd5a29 · GitHub
[go: up one dir, main page]

Skip to content

Commit cfd5a29

Browse files
soyukanicolas-grekas
authored andcommitted
[PhpUnitBridge] add PolyfillTestCaseTrait::expectExceptionMessageMatches to provide FC with recent phpunit versions
1 parent 0506f8c commit cfd5a29

File tree

25 files changed

+59
-49
lines changed

25 files changed

+59
-49
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@
118118
"psr/http-client": "^1.0",
119119
"psr/simple-cache": "^1.0",
120120
"egulias/email-validator": "~1.2,>=1.2.8|~2.0",
121-
"symfony/phpunit-bridge": "^3.4.31|^4.3.4|~5.0",
121+
"symfony/phpunit-bridge": "^5.0.8",
122122
"symfony/security-acl": "~2.8|~3.0",
123123
"phpdocumentor/reflection-docblock": "^3.0|^4.0",
124124
"twig/cssinliner-extra": "^2.12",

src/Symfony/Bridge/PhpUnit/Legacy/PolyfillTestCaseTrait.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,16 @@ public function expectExceptionMessage($message)
9595
$property->setValue($this, $message);
9696
}
9797

98+
/**
99+
* @param string $messageRegExp
100+
*
101+
* @return void
102+
*/
103+
public function expectExceptionMessageMatches($messageRegExp)
104+
{
105+
$this->expectExceptionMessageRegExp($messageRegExp);
106+
}
107+
98108
/**
99109
* @param string $messageRegExp
100110
*

src/Symfony/Bundle/TwigBundle/Tests/Loader/FilesystemLoaderTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ public function testTwigErrorIfLocatorReturnsFalse()
101101
public function testTwigErrorIfTemplateDoesNotExist()
102102
{
103103
$this->expectException('Twig\Error\LoaderError');
104-
$this->expectExceptionMessageRegExp('/Unable to find template "name\.format\.engine" \(looked into: .*Tests.Loader.\.\..DependencyInjection.Fixtures.templates\)/');
104+
$this->expectExceptionMessageMatches('/Unable to find template "name\.format\.engine" \(looked into: .*Tests.Loader.\.\..DependencyInjection.Fixtures.templates\)/');
105105
$parser = $this->getMockBuilder('Symfony\Component\Templating\TemplateNameParserInterface')->getMock();
106106
$locator = $this->getMockBuilder('Symfony\Component\Config\FileLocatorInterface')->getMock();
107107

src/Symfony/Component/Config/Tests/Resource/DirectoryResourceTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ public function testGetPattern()
6666
public function testResourceDoesNotExist()
6767
{
6868
$this->expectException('InvalidArgumentException');
69-
$this->expectExceptionMessageRegExp('/The directory ".*" does not exist./');
69+
$this->expectExceptionMessageMatches('/The directory ".*" does not exist./');
7070
new DirectoryResource('/____foo/foobar'.mt_rand(1, 999999));
7171
}
7272

src/Symfony/Component/Config/Tests/Resource/FileResourceTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public function testToString()
5656
public function testResourceDoesNotExist()
5757
{
5858
$this->expectException('InvalidArgumentException');
59-
$this->expectExceptionMessageRegExp('/The file ".*" does not exist./');
59+
$this->expectExceptionMessageMatches('/The file ".*" does not exist./');
6060
new FileResource('/____foo/foobar'.mt_rand(1, 999999));
6161
}
6262

src/Symfony/Component/DependencyInjection/Tests/Compiler/ResolveChildDefinitionsPassTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -400,7 +400,7 @@ protected function process(ContainerBuilder $container)
400400
public function testProcessDetectsChildDefinitionIndirectCircularReference()
401401
{
402402
$this->expectException('Symfony\Component\DependencyInjection\Exception\ServiceCircularReferenceException');
403-
$this->expectExceptionMessageRegExp('/^Circular reference detected for service "c", path: "c -> b -> a -> c"./');
403+
$this->expectExceptionMessageMatches('/^Circular reference detected for service "c", path: "c -> b -> a -> c"./');
404404
$container = new ContainerBuilder();
405405

406406
$container->register('a');

src/Symfony/Component/DependencyInjection/Tests/Compiler/ResolveInstanceofConditionalsPassTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ public function testProcessForAutoconfiguredCalls()
233233
public function testProcessThrowsExceptionForArguments()
234234
{
235235
$this->expectException('Symfony\Component\DependencyInjection\Exception\InvalidArgumentException');
236-
$this->expectExceptionMessageRegExp('/Autoconfigured instanceof for type "PHPUnit[\\\\_]Framework[\\\\_]TestCase" defines arguments but these are not supported and should be removed\./');
236+
$this->expectExceptionMessageMatches('/Autoconfigured instanceof for type "PHPUnit[\\\\_]Framework[\\\\_]TestCase" defines arguments but these are not supported and should be removed\./');
237237
$container = new ContainerBuilder();
238238
$container->registerForAutoconfiguration(parent::class)
239239
->addArgument('bar');

src/Symfony/Component/DependencyInjection/Tests/Compiler/ValidateEnvPlaceholdersPassTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ public function testInvalidEnvInConfig()
105105
public function testNulledEnvInConfig()
106106
{
107107
$this->expectException('Symfony\Component\Config\Definition\Exception\InvalidTypeException');
108-
$this->expectExceptionMessageRegexp('/^Invalid type for path "env_extension\.int_node"\. Expected "?int"?, but got (NULL|"null")\.$/');
108+
$this->expectExceptionMessageMatches('/^Invalid type for path "env_extension\.int_node"\. Expected "?int"?, but got (NULL|"null")\.$/');
109109
$container = new ContainerBuilder();
110110
$container->setParameter('env(NULLED)', null);
111111
$container->registerExtension(new EnvExtension());

src/Symfony/Component/DependencyInjection/Tests/Loader/FileLoaderTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ public function testMissingParentClass()
216216
public function testRegisterClassesWithBadPrefix()
217217
{
218218
$this->expectException('Symfony\Component\DependencyInjection\Exception\InvalidArgumentException');
219-
$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/');
219+
$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/');
220220
$container = new ContainerBuilder();
221221
$loader = new TestFileLoader($container, new FileLocator(self::$fixturesPath.'/Fixtures'));
222222

src/Symfony/Component/DependencyInjection/Tests/Loader/XmlFileLoaderTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -378,7 +378,7 @@ public function testParseTagsWithoutNameThrowsException()
378378
public function testParseTagWithEmptyNameThrowsException()
379379
{
380380
$this->expectException('Symfony\Component\DependencyInjection\Exception\InvalidArgumentException');
381-
$this->expectExceptionMessageRegExp('/The tag name for service ".+" in .* must be a non-empty string/');
381+
$this->expectExceptionMessageMatches('/The tag name for service ".+" in .* must be a non-empty string/');
382382
$container = new ContainerBuilder();
383383
$loader = new XmlFileLoader($container, new FileLocator(self::$fixturesPath.'/xml'));
384384
$loader->load('tag_with_empty_name.xml');

src/Symfony/Component/DependencyInjection/Tests/Loader/YamlFileLoaderTest.php

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public static function setUpBeforeClass(): void
5050
public function testLoadUnExistFile()
5151
{
5252
$this->expectException('Symfony\Component\DependencyInjection\Exception\InvalidArgumentException');
53-
$this->expectExceptionMessageRegExp('/The file ".+" does not exist./');
53+
$this->expectExceptionMessageMatches('/The file ".+" does not exist./');
5454
$loader = new YamlFileLoader(new ContainerBuilder(), new FileLocator(self::$fixturesPath.'/ini'));
5555
$r = new \ReflectionObject($loader);
5656
$m = $r->getMethod('loadFile');
@@ -62,7 +62,7 @@ public function testLoadUnExistFile()
6262
public function testLoadInvalidYamlFile()
6363
{
6464
$this->expectException('Symfony\Component\DependencyInjection\Exception\InvalidArgumentException');
65-
$this->expectExceptionMessageRegExp('/The file ".+" does not contain valid YAML./');
65+
$this->expectExceptionMessageMatches('/The file ".+" does not contain valid YAML./');
6666
$path = self::$fixturesPath.'/ini';
6767
$loader = new YamlFileLoader(new ContainerBuilder(), new FileLocator($path));
6868
$r = new \ReflectionObject($loader);
@@ -384,15 +384,15 @@ public function testLoadYamlOnlyWithKeys()
384384
public function testTagWithEmptyNameThrowsException()
385385
{
386386
$this->expectException('Symfony\Component\DependencyInjection\Exception\InvalidArgumentException');
387-
$this->expectExceptionMessageRegExp('/The tag name for service ".+" in .+ must be a non-empty string/');
387+
$this->expectExceptionMessageMatches('/The tag name for service ".+" in .+ must be a non-empty string/');
388388
$loader = new YamlFileLoader(new ContainerBuilder(), new FileLocator(self::$fixturesPath.'/yaml'));
389389
$loader->load('tag_name_empty_string.yml');
390390
}
391391

392392
public function testTagWithNonStringNameThrowsException()
393393
{
394394
$this->expectException('Symfony\Component\DependencyInjection\Exception\InvalidArgumentException');
395-
$this->expectExceptionMessageRegExp('/The tag name for service ".+" in .+ must be a non-empty string/');
395+
$this->expectExceptionMessageMatches('/The tag name for service ".+" in .+ must be a non-empty string/');
396396
$loader = new YamlFileLoader(new ContainerBuilder(), new FileLocator(self::$fixturesPath.'/yaml'));
397397
$loader->load('tag_name_no_string.yml');
398398
}
@@ -493,7 +493,7 @@ public function testPrototypeWithNamespace()
493493
public function testPrototypeWithNamespaceAndNoResource()
494494
{
495495
$this->expectException('Symfony\Component\DependencyInjection\Exception\InvalidArgumentException');
496-
$this->expectExceptionMessageRegExp('/A "resource" attribute must be set when the "namespace" attribute is set for service ".+" in .+/');
496+
$this->expectExceptionMessageMatches('/A "resource" attribute must be set when the "namespace" attribute is set for service ".+" in .+/');
497497
$container = new ContainerBuilder();
498498
$loader = new YamlFileLoader($container, new FileLocator(self::$fixturesPath.'/yaml'));
499499
$loader->load('services_prototype_namespace_without_resource.yml');
@@ -621,7 +621,7 @@ public function testDecoratedServicesWithWrongOnInvalidSyntaxThrowsException()
621621
public function testInvalidTagsWithDefaults()
622622
{
623623
$this->expectException('Symfony\Component\DependencyInjection\Exception\InvalidArgumentException');
624-
$this->expectExceptionMessageRegExp('/Parameter "tags" must be an array for service "Foo\\\Bar" in ".+services31_invalid_tags\.yml"\. Check your YAML syntax./');
624+
$this->expectExceptionMessageMatches('/Parameter "tags" must be an array for service "Foo\\\Bar" in ".+services31_invalid_tags\.yml"\. Check your YAML syntax./');
625625
$loader = new YamlFileLoader(new ContainerBuilder(), new FileLocator(self::$fixturesPath.'/yaml'));
626626
$loader->load('services31_invalid_tags.yml');
627627
}
@@ -711,7 +711,7 @@ public function testAnonymousServicesInInstanceof()
711711
public function testAnonymousServicesWithAliases()
712712
{
713713
$this->expectException('Symfony\Component\DependencyInjection\Exception\InvalidArgumentException');
714-
$this->expectExceptionMessageRegExp('/Creating an alias using the tag "!service" is not allowed in ".+anonymous_services_alias\.yml"\./');
714+
$this->expectExceptionMessageMatches('/Creating an alias using the tag "!service" is not allowed in ".+anonymous_services_alias\.yml"\./');
715715
$container = new ContainerBuilder();
716716
$loader = new YamlFileLoader($container, new FileLocator(self::$fixturesPath.'/yaml'));
717717
$loader->load('anonymous_services_alias.yml');
@@ -720,7 +720,7 @@ public function testAnonymousServicesWithAliases()
720720
public function testAnonymousServicesInParameters()
721721
{
722722
$this->expectException('Symfony\Component\DependencyInjection\Exception\InvalidArgumentException');
723-
$this->expectExceptionMessageRegExp('/Using an anonymous service in a parameter is not allowed in ".+anonymous_services_in_parameters\.yml"\./');
723+
$this->expectExceptionMessageMatches('/Using an anonymous service in a parameter is not allowed in ".+anonymous_services_in_parameters\.yml"\./');
724724
$container = new ContainerBuilder();
725725
$loader = new YamlFileLoader($container, new FileLocator(self::$fixturesPath.'/yaml'));
726726
$loader->load('anonymous_services_in_parameters.yml');
@@ -739,7 +739,7 @@ public function testAutoConfigureInstanceof()
739739
public function testEmptyDefaultsThrowsClearException()
740740
{
741741
$this->expectException('Symfony\Component\DependencyInjection\Exception\InvalidArgumentException');
742-
$this->expectExceptionMessageRegExp('/Service "_defaults" key must be an array, "NULL" given in ".+bad_empty_defaults\.yml"\./');
742+
$this->expectExceptionMessageMatches('/Service "_defaults" key must be an array, "NULL" given in ".+bad_empty_defaults\.yml"\./');
743743
$container = new ContainerBuilder();
744744
$loader = new YamlFileLoader($container, new FileLocator(self::$fixturesPath.'/yaml'));
745745
$loader->load('bad_empty_defaults.yml');
@@ -748,7 +748,7 @@ public function testEmptyDefaultsThrowsClearException()
748748
public function testEmptyInstanceofThrowsClearException()
749749
{
750750
$this->expectException('Symfony\Component\DependencyInjection\Exception\InvalidArgumentException');
751-
$this->expectExceptionMessageRegExp('/Service "_instanceof" key must be an array, "NULL" given in ".+bad_empty_instanceof\.yml"\./');
751+
$this->expectExceptionMessageMatches('/Service "_instanceof" key must be an array, "NULL" given in ".+bad_empty_instanceof\.yml"\./');
752752
$container = new ContainerBuilder();
753753
$loader = new YamlFileLoader($container, new FileLocator(self::$fixturesPath.'/yaml'));
754754
$loader->load('bad_empty_instanceof.yml');
@@ -757,7 +757,7 @@ public function testEmptyInstanceofThrowsClearException()
757757
public function testUnsupportedKeywordThrowsException()
758758
{
759759
$this->expectException('Symfony\Component\DependencyInjection\Exception\InvalidArgumentException');
760-
$this->expectExceptionMessageRegExp('/^The configuration key "private" is unsupported for definition "bar"/');
760+
$this->expectExceptionMessageMatches('/^The configuration key "private" is unsupported for definition "bar"/');
761761
$container = new ContainerBuilder();
762762
$loader = new YamlFileLoader($container, new FileLocator(self::$fixturesPath.'/yaml'));
763763
$loader->load('bad_keyword.yml');
@@ -766,7 +766,7 @@ public function testUnsupportedKeywordThrowsException()
766766
public function testUnsupportedKeywordInServiceAliasThrowsException()
767767
{
768768
$this->expectException('Symfony\Component\DependencyInjection\Exception\InvalidArgumentException');
769-
$this->expectExceptionMessageRegExp('/^The configuration key "calls" is unsupported for the service "bar" which is defined as an alias/');
76 10000 9+
$this->expectExceptionMessageMatches('/^The configuration key "calls" is unsupported for the service "bar" which is defined as an alias/');
770770
$container = new ContainerBuilder();
771771
$loader = new YamlFileLoader($container, new FileLocator(self::$fixturesPath.'/yaml'));
772772
$loader->load('bad_alias.yml');

src/Symfony/Component/ExpressionLanguage/Tests/ExpressionLanguageTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ public function testRegisterAfterEval($registerCallback)
231231
public function testCallBadCallable()
232232
{
233233
$this->expectException('RuntimeException');
234-
$this->expectExceptionMessageRegExp('/Unable to call method "\w+" of object "\w+"./');
234+
$this->expectExceptionMessageMatches('/Unable to call method "\w+" of object "\w+"./');
235235
$el = new ExpressionLanguage();
236236
$el->evaluate('foo.myfunction()', ['foo' => new \stdClass()]);
237237
}

src/Symfony/Component/Form/Tests/Extension/Core/Type/CheckboxTypeTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ public function provideCustomFalseValues()
197197
public function testDontAllowNonArrayFalseValues()
198198
{
199199
$this->expectException('Symfony\Component\OptionsResolver\Exception\InvalidOptionsException');
200-
$this->expectExceptionMessageRegExp('/"false_values" with value "invalid" is expected to be of type "array"/');
200+
$this->expectExceptionMessageMatches('/"false_values" with value "invalid" is expected to be of type "array"/');
201201
$this->factory->create(static::TESTED_TYPE, null, [
202202
'false_values' => 'invalid',
203203
]);

src/Symfony/Component/Mailer/Tests/Transport/Smtp/Stream/SocketStreamTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ class SocketStreamTest extends TestCase
1919
public function testSocketErrorNoConnection()
2020
{
2121
$this->expectException('Symfony\Component\Mailer\Exception\TransportException');
22-
$this->expectExceptionMessageRegExp('/Connection refused|unable to connect/');
22+
$this->expectExceptionMessageMatches('/Connection refused|unable to connect/');
2323
$s = new SocketStream();
2424
$s->setTimeout(0.1);
2525
$s->setPort(9999);
@@ -29,7 +29,7 @@ public function testSocketErrorNoConnection()
2929
public function testSocketErrorBeforeConnectError()
3030
{
3131
$this->expectException('Symfony\Component\Mailer\Exception\TransportException');
32-
$this->expectExceptionMessageRegExp('/no valid certs found cafile stream|Unable to find the socket transport "ssl"/');
32+
$this->expectExceptionMessageMatches('/no valid certs found cafile stream|Unable to find the socket transport "ssl"/');
3333
$s = new SocketStream();
3434
$s->setStreamOptions([
3535
'ssl' => [

src/Symfony/Component/Messenger/Tests/Transport/Serialization/PhpSerializerTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public function testDecodingFailsWithMissingBodyKey()
4444
public function testDecodingFailsWithBadFormat()
4545
{
4646
$this->expectException(MessageDecodingFailedException::class);
47-
$this->expectExceptionMessageRegExp('/Could not decode/');
47+
$this->expectExceptionMessageMatches('/Could not decode/');
4848

4949
$serializer = new PhpSerializer();
5050

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

6161
$serializer = new PhpSerializer();
6262

src/Symfony/Component/Process/Tests/ProcessTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ protected function tearDown(): void
5050
public function testInvalidCwd()
5151
{
5252
$this->expectException('Symfony\Component\Process\Exception\RuntimeException');
53-
$this->expectExceptionMessageRegExp('/The provided cwd ".*" does not exist\./');
53+
$this->expectExceptionMessageMatches('/The provided cwd ".*" does not exist\./');
5454
try {
5555
// Check that it works fine if the CWD exists
5656
$cmd = new Process(['echo', 'test'], __DIR__);

src/Symfony/Component/PropertyAccess/Tests/PropertyAccessorCollectionTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ public function testSetValueCallsAdderAndRemoverForNestedCollections()
149149
public function testSetValueFailsIfNoAdderNorRemoverFound()
150150
{
151151
$this->expectException('Symfony\Component\PropertyAccess\Exception\NoSuchPropertyException');
152-
$this->expectExceptionMessageRegExp('/Could not determine access type for property "axes" in class "Mock_PropertyAccessorCollectionTest_CarNoAdderAndRemover_[^"]*"./');
152+
$this->expectExceptionMessageMatches('/Could not determine access type for property "axes" in class "Mock_PropertyAccessorCollectionTest_CarNoAdderAndRemover_[^"]*"./');
153153
$car = $this->getMockBuilder(__CLASS__.'_CarNoAdderAndRemover')->getMock();
154154
$axesBefore = $this->getContainer([1 => 'second', 3 => 'fourth']);
155155
$axesAfter = $this->getContainer([0 => 'first', 1 => 'second', 2 => 'third']);
@@ -188,7 +188,7 @@ public function testIsWritableReturnsFalseIfNoAdderNorRemoverExists()
188188
public function testSetValueFailsIfAdderAndRemoverExistButValueIsNotTraversable()
189189
{
190190
$this->expectException('Symfony\Component\PropertyAccess\Exception\NoSuchPropertyException');
191-
$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./');
191+
$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./');
192192
$car = new PropertyAccessorCollectionTest_Car();
193193

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

0 commit comments

Comments
 (0)
0