From d10e43d0851b0c673ce7d71c360cbae70688b69f Mon Sep 17 00:00:00 2001 From: HypeMC Date: Mon, 13 Jul 2020 20:19:17 +0200 Subject: [PATCH 1/4] Allow same middleware to be used multiple times with different arguments --- .../DependencyInjection/MessengerPass.php | 2 +- .../DependencyInjection/MessengerPassTest.php | 25 +++++++++++++++---- 2 files changed, 21 insertions(+), 6 deletions(-) diff --git a/src/Symfony/Component/Messenger/DependencyInjection/MessengerPass.php b/src/Symfony/Component/Messenger/DependencyInjection/MessengerPass.php index 888155dea9..da342e8c31 100644 --- a/src/Symfony/Component/Messenger/DependencyInjection/MessengerPass.php +++ b/src/Symfony/Component/Messenger/DependencyInjection/MessengerPass.php @@ -339,7 +339,7 @@ class MessengerPass implements CompilerPassInterface if ($container->findDefinition($messengerMiddlewareId)->isAbstract()) { $childDefinition = new ChildDefinition($messengerMiddlewareId); $childDefinition->setArguments($arguments); - $container->setDefinition($messengerMiddlewareId = $busId.'.middleware.'.$id, $childDefinition); + $container->setDefinition($messengerMiddlewareId = $busId.'.middleware.'.$id.'.'.ContainerBuilder::hash($arguments), $childDefinition); } elseif ($arguments) { throw new RuntimeException(sprintf('Invalid middleware factory "%s": a middleware factory must be an abstract definition.', $id)); } diff --git a/src/Symfony/Component/Messenger/Tests/DependencyInjection/MessengerPassTest.php b/src/Symfony/Component/Messenger/Tests/DependencyInjection/MessengerPassTest.php index 3ec352970a..0644982c64 100644 --- a/src/Symfony/Component/Messenger/Tests/DependencyInjection/MessengerPassTest.php +++ b/src/Symfony/Component/Messenger/Tests/DependencyInjection/MessengerPassTest.php @@ -508,21 +508,35 @@ class MessengerPassTest extends TestCase $container->setParameter($middlewareParameter = $fooBusId.'.middleware', [ ['id' => UselessMiddleware::class], - ['id' => 'middleware_with_factory', 'arguments' => ['index_0' => 'foo', 'bar']], + ['id' => 'middleware_with_factory', 'arguments' => $factoryChildMiddlewareArgs1 = ['index_0' => 'foo', 'bar']], + ['id' => 'middleware_with_factory', 'arguments' => $factoryChildMiddlewareArgs2 = ['index_0' => 'baz']], ['id' => 'middleware_with_factory_using_default'], ]); (new MessengerPass())->process($container); (new ResolveChildDefinitionsPass())->process($container); - $this->assertTrue($container->hasDefinition($factoryChildMiddlewareId = $fooBusId.'.middleware.middleware_with_factory')); + $this->assertTrue($container->hasDefinition( + $factoryChildMiddlewareArgs1Id = $fooBusId.'.middleware.middleware_with_factory.'.ContainerBuilder::hash($factoryChildMiddlewareArgs1) + )); $this->assertEquals( ['foo', 'bar'], - $container->getDefinition($factoryChildMiddlewareId)->getArguments(), + $container->getDefinition($factoryChildMiddlewareArgs1Id)->getArguments(), 'parent default argument is overridden, and next ones appended' ); - $this->assertTrue($container->hasDefinition($factoryWithDefaultChildMiddlewareId = $fooBusId.'.middleware.middleware_with_factory_using_default')); + $this->assertTrue($container->hasDefinition( + $factoryChildMiddlewareArgs2Id = $fooBusId.'.middleware.middleware_with_factory.'.ContainerBuilder::hash($factoryChildMiddlewareArgs2) + )); + $this->assertEquals( + ['baz'], + $container->getDefinition($factoryChildMiddlewareArgs2Id)->getArguments(), + 'parent default argument is overridden, and next ones appended' + ); + + $this->assertTrue($container->hasDefinition( + $factoryWithDefaultChildMiddlewareId = $fooBusId.'.middleware.middleware_with_factory_using_default.'.ContainerBuilder::hash([]) + )); $this->assertEquals( ['some_default'], $container->getDefinition($factoryWithDefaultChildMiddlewareId)->getArguments(), @@ -531,7 +545,8 @@ class MessengerPassTest extends TestCase $this->assertEquals([ new Reference(UselessMiddleware::class), - new Reference($factoryChildMiddlewareId), + new Reference($factoryChildMiddlewareArgs1Id), + new Reference($factoryChildMiddlewareArgs2Id), new Reference($factoryWithDefaultChildMiddlewareId), ], $container->getDefinition($fooBusId)->getArgument(0)->getValues()); $this->assertFalse($container->hasParameter($middlewareParameter)); From 8a3f50746daea247a4ed21f4d9b0e7fc42fc0ad1 Mon Sep 17 00:00:00 2001 From: Evert Harmeling Date: Wed, 15 Jul 2020 14:13:19 +0200 Subject: [PATCH 2/4] Fix EmailHeaderSame to make use of decoded value Fixes #35062 --- .../Mime/Test/Constraint/EmailHeaderSame.php | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/Symfony/Component/Mime/Test/Constraint/EmailHeaderSame.php b/src/Symfony/Component/Mime/Test/Constraint/EmailHeaderSame.php index bc7e330e05..74bdc63c79 100644 --- a/src/Symfony/Component/Mime/Test/Constraint/EmailHeaderSame.php +++ b/src/Symfony/Component/Mime/Test/Constraint/EmailHeaderSame.php @@ -12,6 +12,7 @@ namespace Symfony\Component\Mime\Test\Constraint; use PHPUnit\Framework\Constraint\Constraint; +use Symfony\Component\Mime\Header\UnstructuredHeader; use Symfony\Component\Mime\RawMessage; final class EmailHeaderSame extends Constraint @@ -44,7 +45,7 @@ final class EmailHeaderSame extends Constraint throw new \LogicException('Unable to test a message header on a RawMessage instance.'); } - return $this->expectedValue === $message->getHeaders()->get($this->headerName)->getBodyAsString(); + return $this->expectedValue === $this->getHeaderValue($message); } /** @@ -54,6 +55,13 @@ final class EmailHeaderSame extends Constraint */ protected function failureDescription($message): string { - return sprintf('the Email %s (value is %s)', $this->toString(), $message->getHeaders()->get($this->headerName)->getBodyAsString()); + return sprintf('the Email %s (value is %s)', $this->toString(), $this->getHeaderValue($message)); + } + + private function getHeaderValue($message): string + { + $header = $message->getHeaders()->get($this->headerName); + + return $header instanceof UnstructuredHeader ? $header->getValue() : $header->getBodyAsString(); } } From ec525e6e04280335007365a270dc0563bdcf34e3 Mon Sep 17 00:00:00 2001 From: "Alexander M. Turek" Date: Mon, 13 Jul 2020 00:27:19 +0200 Subject: [PATCH 3/4] Fix PHPUnit 8.5 deprecations. --- .../Tests/Loader/FilesystemLoaderTest.php | 2 +- .../Tests/Resource/DirectoryResourceTest.php | 2 +- .../Tests/Resource/FileResourceTest.php | 2 +- .../Tests/Compiler/AutowirePassTest.php | 2 +- .../Compiler/ResolveBindingsPassTest.php | 2 +- .../ResolveChildDefinitionsPassTest.php | 2 +- .../ResolveInstanceofConditionalsPassTest.php | 4 ++-- .../Tests/Loader/FileLoaderTest.php | 2 +- .../Tests/Loader/XmlFileLoaderTest.php | 2 +- .../Tests/Loader/YamlFileLoaderTest.php | 20 +++++++++---------- .../Tests/ExpressionLanguageTest.php | 2 +- .../Storage/Proxy/SessionHandlerProxyTest.php | 8 ++++++-- .../ContainerControllerResolverTest.php | 2 +- .../Tests/PropertyAccessorCollectionTest.php | 2 +- .../Tests/Loader/XmlFileLoaderTest.php | 4 ++-- .../Tests/Loader/YamlFileLoaderTest.php | 4 ++-- .../GuardAuthenticationProviderTest.php | 2 +- .../Component/Yaml/Tests/InlineTest.php | 4 ++-- .../Component/Yaml/Tests/ParserTest.php | 8 ++++---- 19 files changed, 40 insertions(+), 36 deletions(-) diff --git a/src/Symfony/Bundle/TwigBundle/Tests/Loader/FilesystemLoaderTest.php b/src/Symfony/Bundle/TwigBundle/Tests/Loader/FilesystemLoaderTest.php index 7fa8dd2b42..c8958670af 100644 --- a/src/Symfony/Bundle/TwigBundle/Tests/Loader/FilesystemLoaderTest.php +++ b/src/Symfony/Bundle/TwigBundle/Tests/Loader/FilesystemLoaderTest.php @@ -98,7 +98,7 @@ class FilesystemLoaderTest extends TestCase public function testTwigErrorIfTemplateDoesNotExist() { $this->expectException('Twig\Error\LoaderError'); - $this->expectExceptionMessageRegExp('/Unable to find template "name\.format\.engine" \(looked into: .*Tests.Loader.\.\..DependencyInjection.Fixtures.Resources.views\)/'); + $this->expectExceptionMessageMatches('/Unable to find template "name\.format\.engine" \(looked into: .*Tests.Loader.\.\..DependencyInjection.Fixtures.Resources.views\)/'); $parser = $this->getMockBuilder('Symfony\Component\Templating\TemplateNameParserInterface')->getMock(); $locator = $this->getMockBuilder('Symfony\Component\Config\FileLocatorInterface')->getMock(); diff --git a/src/Symfony/Component/Config/Tests/Resource/DirectoryResourceTest.php b/src/Symfony/Component/Config/Tests/Resource/DirectoryResourceTest.php index 40b1790101..700df45658 100644 --- a/src/Symfony/Component/Config/Tests/Resource/DirectoryResourceTest.php +++ b/src/Symfony/Component/Config/Tests/Resource/DirectoryResourceTest.php @@ -66,7 +66,7 @@ class DirectoryResourceTest extends TestCase 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)); } diff --git a/src/Symfony/Component/Config/Tests/Resource/FileResourceTest.php b/src/Symfony/Component/Config/Tests/Resource/FileResourceTest.php index 968c7e9266..5b789700ad 100644 --- a/src/Symfony/Component/Config/Tests/Resource/FileResourceTest.php +++ b/src/Symfony/Component/Config/Tests/Resource/FileResourceTest.php @@ -56,7 +56,7 @@ class FileResourceTest extends TestCase 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)); } diff --git a/src/Symfony/Component/DependencyInjection/Tests/Compiler/AutowirePassTest.php b/src/Symfony/Component/DependencyInjection/Tests/Compiler/AutowirePassTest.php index 2482db6314..6c11a94c53 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Compiler/AutowirePassTest.php +++ b/src/Symfony/Component/DependencyInjection/Tests/Compiler/AutowirePassTest.php @@ -434,7 +434,7 @@ class AutowirePassTest extends TestCase public function testParentClassNotFoundThrowsException() { $this->expectException('Symfony\Component\DependencyInjection\Exception\AutowiringFailedException'); - $this->expectExceptionMessageRegExp('{^Cannot autowire service "a": argument "\$r" of method "(Symfony\\\\Component\\\\DependencyInjection\\\\Tests\\\\Compiler\\\\)BadParentTypeHintedArgument::__construct\(\)" has type "\1OptionalServiceClass" but this class is missing a parent class \(Class "?Symfony\\\\Bug\\\\NotExistClass"? not found}'); + $this->expectExceptionMessageMatches('{^Cannot autowire service "a": argument "\$r" of method "(Symfony\\\\Component\\\\DependencyInjection\\\\Tests\\\\Compiler\\\\)BadParentTypeHintedArgument::__construct\(\)" has type "\1OptionalServiceClass" but this class is missing a parent class \(Class "?Symfony\\\\Bug\\\\NotExistClass"? not found}'); $container = new ContainerBuilder(); diff --git a/src/Symfony/Component/DependencyInjection/Tests/Compiler/ResolveBindingsPassTest.php b/src/Symfony/Component/DependencyInjection/Tests/Compiler/ResolveBindingsPassTest.php index bfd3d67238..7e5994af86 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Compiler/ResolveBindingsPassTest.php +++ b/src/Symfony/Component/DependencyInjection/Tests/Compiler/ResolveBindingsPassTest.php @@ -65,7 +65,7 @@ class ResolveBindingsPassTest extends TestCase public function testMissingParent() { $this->expectException('Symfony\Component\DependencyInjection\Exception\InvalidArgumentException'); - $this->expectExceptionMessageRegExp('/Unused binding "\$quz" in service [\s\S]+/'); + $this->expectExceptionMessageMatches('/Unused binding "\$quz" in service [\s\S]+/'); $container = new ContainerBuilder(); diff --git a/src/Symfony/Component/DependencyInjection/Tests/Compiler/ResolveChildDefinitionsPassTest.php b/src/Symfony/Component/DependencyInjection/Tests/Compiler/ResolveChildDefinitionsPassTest.php index eee4cf730c..f3cd9fa1c6 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Compiler/ResolveChildDefinitionsPassTest.php +++ b/src/Symfony/Component/DependencyInjection/Tests/Compiler/ResolveChildDefinitionsPassTest.php @@ -435,7 +435,7 @@ class ResolveChildDefinitionsPassTest extends TestCase 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'); diff --git a/src/Symfony/Component/DependencyInjection/Tests/Compiler/ResolveInstanceofConditionalsPassTest.php b/src/Symfony/Component/DependencyInjection/Tests/Compiler/ResolveInstanceofConditionalsPassTest.php index 83be84bd0c..0d81cdf3d7 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Compiler/ResolveInstanceofConditionalsPassTest.php +++ b/src/Symfony/Component/DependencyInjection/Tests/Compiler/ResolveInstanceofConditionalsPassTest.php @@ -201,7 +201,7 @@ class ResolveInstanceofConditionalsPassTest extends TestCase public function testProcessThrowsExceptionForAutoconfiguredCalls() { $this->expectException('Symfony\Component\DependencyInjection\Exception\InvalidArgumentException'); - $this->expectExceptionMessageRegExp('/Autoconfigured instanceof for type "PHPUnit[\\\\_]Framework[\\\\_]TestCase" defines method calls but these are not supported and should be removed\./'); + $this->expectExceptionMessageMatches('/Autoconfigured instanceof for type "PHPUnit[\\\\_]Framework[\\\\_]TestCase" defines method calls but these are not supported and should be removed\./'); $container = new ContainerBuilder(); $container->registerForAutoconfiguration(parent::class) ->addMethodCall('setFoo'); @@ -212,7 +212,7 @@ class ResolveInstanceofConditionalsPassTest extends TestCase 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'); diff --git a/src/Symfony/Component/DependencyInjection/Tests/Loader/FileLoaderTest.php b/src/Symfony/Component/DependencyInjection/Tests/Loader/FileLoaderTest.php index 9fe075d8f1..d2850fcc05 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Loader/FileLoaderTest.php +++ b/src/Symfony/Component/DependencyInjection/Tests/Loader/FileLoaderTest.php @@ -194,7 +194,7 @@ class FileLoaderTest extends TestCase 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')); diff --git a/src/Symfony/Component/DependencyInjection/Tests/Loader/XmlFileLoaderTest.php b/src/Symfony/Component/DependencyInjection/Tests/Loader/XmlFileLoaderTest.php index 2b963968d8..5fbb387bf9 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Loader/XmlFileLoaderTest.php +++ b/src/Symfony/Component/DependencyInjection/Tests/Loader/XmlFileLoaderTest.php @@ -336,7 +336,7 @@ class XmlFileLoaderTest extends TestCase 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'); diff --git a/src/Symfony/Component/DependencyInjection/Tests/Loader/YamlFileLoaderTest.php b/src/Symfony/Component/DependencyInjection/Tests/Loader/YamlFileLoaderTest.php index 3059dd4d6c..7280357a2d 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Loader/YamlFileLoaderTest.php +++ b/src/Symfony/Component/DependencyInjection/Tests/Loader/YamlFileLoaderTest.php @@ -45,7 +45,7 @@ class YamlFileLoaderTest extends TestCase 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'); @@ -57,7 +57,7 @@ class YamlFileLoaderTest extends TestCase 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); @@ -300,7 +300,7 @@ class YamlFileLoaderTest extends TestCase 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'); } @@ -308,7 +308,7 @@ class YamlFileLoaderTest extends TestCase 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'); } @@ -424,7 +424,7 @@ class YamlFileLoaderTest extends TestCase 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'); @@ -536,7 +536,7 @@ class YamlFileLoaderTest extends TestCase 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'); } @@ -628,7 +628,7 @@ class YamlFileLoaderTest extends TestCase 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'); @@ -637,7 +637,7 @@ class YamlFileLoaderTest extends TestCase 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'); @@ -656,7 +656,7 @@ class YamlFileLoaderTest extends TestCase 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'); @@ -665,7 +665,7 @@ class YamlFileLoaderTest extends TestCase 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'); diff --git a/src/Symfony/Component/ExpressionLanguage/Tests/ExpressionLanguageTest.php b/src/Symfony/Component/ExpressionLanguage/Tests/ExpressionLanguageTest.php index 6c7a8025b1..5ee5c6e76c 100644 --- a/src/Symfony/Component/ExpressionLanguage/Tests/ExpressionLanguageTest.php +++ b/src/Symfony/Component/ExpressionLanguage/Tests/ExpressionLanguageTest.php @@ -269,7 +269,7 @@ class ExpressionLanguageTest extends TestCase 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()]); } diff --git a/src/Symfony/Component/HttpFoundation/Tests/Session/Storage/Proxy/SessionHandlerProxyTest.php b/src/Symfony/Component/HttpFoundation/Tests/Session/Storage/Proxy/SessionHandlerProxyTest.php index 1457ebd70d..3310cf9cb2 100644 --- a/src/Symfony/Component/HttpFoundation/Tests/Session/Storage/Proxy/SessionHandlerProxyTest.php +++ b/src/Symfony/Component/HttpFoundation/Tests/Session/Storage/Proxy/SessionHandlerProxyTest.php @@ -127,7 +127,7 @@ class SessionHandlerProxyTest extends TestCase */ public function testValidateId() { - $mock = $this->getMockBuilder(['SessionHandlerInterface', 'SessionUpdateTimestampHandlerInterface'])->getMock(); + $mock = $this->getMockBuilder(TestSessionHandler::class)->getMock(); $mock->expects($this->once()) ->method('validateId'); @@ -142,7 +142,7 @@ class SessionHandlerProxyTest extends TestCase */ public function testUpdateTimestamp() { - $mock = $this->getMockBuilder(['SessionHandlerInterface', 'SessionUpdateTimestampHandlerInterface'])->getMock(); + $mock = $this->getMockBuilder(TestSessionHandler::class)->getMock(); $mock->expects($this->once()) ->method('updateTimestamp') ->willReturn(false); @@ -156,3 +156,7 @@ class SessionHandlerProxyTest extends TestCase $this->proxy->updateTimestamp('id', 'data'); } } + +abstract class TestSessionHandler implements \SessionHandlerInterface, \SessionUpdateTimestampHandlerInterface +{ +} diff --git a/src/Symfony/Component/HttpKernel/Tests/Controller/ContainerControllerResolverTest.php b/src/Symfony/Component/HttpKernel/Tests/Controller/ContainerControllerResolverTest.php index 4c4abf5aa4..ef1c82638b 100644 --- a/src/Symfony/Component/HttpKernel/Tests/Controller/ContainerControllerResolverTest.php +++ b/src/Symfony/Component/HttpKernel/Tests/Controller/ContainerControllerResolverTest.php @@ -232,7 +232,7 @@ class ContainerControllerResolverTest extends ControllerResolverTest // All this logic needs to be duplicated, since calling parent::testGetControllerOnNonUndefinedFunction will override the expected exception and not use the regex $resolver = $this->createControllerResolver(); $this->expectException($exceptionName); - $this->expectExceptionMessageRegExp($exceptionMessage); + $this->expectExceptionMessageMatches($exceptionMessage); $request = Request::create('/'); $request->attributes->set('_controller', $controller); diff --git a/src/Symfony/Component/PropertyAccess/Tests/PropertyAccessorCollectionTest.php b/src/Symfony/Component/PropertyAccess/Tests/PropertyAccessorCollectionTest.php index 34173b4e5e..bf35b2c195 100644 --- a/src/Symfony/Component/PropertyAccess/Tests/PropertyAccessorCollectionTest.php +++ b/src/Symfony/Component/PropertyAccess/Tests/PropertyAccessorCollectionTest.php @@ -149,7 +149,7 @@ abstract class PropertyAccessorCollectionTest extends PropertyAccessorArrayAcces 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']); diff --git a/src/Symfony/Component/Routing/Tests/Loader/XmlFileLoaderTest.php b/src/Symfony/Component/Routing/Tests/Loader/XmlFileLoaderTest.php index 128bb54fb0..57d7697dd8 100644 --- a/src/Symfony/Component/Routing/Tests/Loader/XmlFileLoaderTest.php +++ b/src/Symfony/Component/Routing/Tests/Loader/XmlFileLoaderTest.php @@ -339,7 +339,7 @@ class XmlFileLoaderTest extends TestCase public function testOverrideControllerInDefaults() { $this->expectException('InvalidArgumentException'); - $this->expectExceptionMessageRegExp('/The routing file "[^"]*" must not specify both the "controller" attribute and the defaults key "_controller" for "app_blog"/'); + $this->expectExceptionMessageMatches('/The routing file "[^"]*" must not specify both the "controller" attribute and the defaults key "_controller" for "app_blog"/'); $loader = new XmlFileLoader(new FileLocator([__DIR__.'/../Fixtures/controller'])); $loader->load('override_defaults.xml'); } @@ -371,7 +371,7 @@ class XmlFileLoaderTest extends TestCase public function testImportWithOverriddenController() { $this->expectException('InvalidArgumentException'); - $this->expectExceptionMessageRegExp('/The routing file "[^"]*" must not specify both the "controller" attribute and the defaults key "_controller" for the "import" tag/'); + $this->expectExceptionMessageMatches('/The routing file "[^"]*" must not specify both the "controller" attribute and the defaults key "_controller" for the "import" tag/'); $loader = new XmlFileLoader(new FileLocator([__DIR__.'/../Fixtures/controller'])); $loader->load('import_override_defaults.xml'); } diff --git a/src/Symfony/Component/Routing/Tests/Loader/YamlFileLoaderTest.php b/src/Symfony/Component/Routing/Tests/Loader/YamlFileLoaderTest.php index 2e3261a1ca..5c8b52493d 100644 --- a/src/Symfony/Component/Routing/Tests/Loader/YamlFileLoaderTest.php +++ b/src/Symfony/Component/Routing/Tests/Loader/YamlFileLoaderTest.php @@ -142,7 +142,7 @@ class YamlFileLoaderTest extends TestCase public function testOverrideControllerInDefaults() { $this->expectException('InvalidArgumentException'); - $this->expectExceptionMessageRegExp('/The routing file "[^"]*" must not specify both the "controller" key and the defaults key "_controller" for "app_blog"/'); + $this->expectExceptionMessageMatches('/The routing file "[^"]*" must not specify both the "controller" key and the defaults key "_controller" for "app_blog"/'); $loader = new YamlFileLoader(new FileLocator([__DIR__.'/../Fixtures/controller'])); $loader->load('override_defaults.yml'); } @@ -174,7 +174,7 @@ class YamlFileLoaderTest extends TestCase public function testImportWithOverriddenController() { $this->expectException('InvalidArgumentException'); - $this->expectExceptionMessageRegExp('/The routing file "[^"]*" must not specify both the "controller" key and the defaults key "_controller" for "_static"/'); + $this->expectExceptionMessageMatches('/The routing file "[^"]*" must not specify both the "controller" key and the defaults key "_controller" for "_static"/'); $loader = new YamlFileLoader(new FileLocator([__DIR__.'/../Fixtures/controller'])); $loader->load('import_override_defaults.yml'); } diff --git a/src/Symfony/Component/Security/Guard/Tests/Provider/GuardAuthenticationProviderTest.php b/src/Symfony/Component/Security/Guard/Tests/Provider/GuardAuthenticationProviderTest.php index c2c1dde623..4f9c8fdc73 100644 --- a/src/Symfony/Component/Security/Guard/Tests/Provider/GuardAuthenticationProviderTest.php +++ b/src/Symfony/Component/Security/Guard/Tests/Provider/GuardAuthenticationProviderTest.php @@ -216,7 +216,7 @@ class GuardAuthenticationProviderTest extends TestCase public function testAuthenticateFailsOnNonOriginatingToken() { $this->expectException('Symfony\Component\Security\Core\Exception\AuthenticationException'); - $this->expectExceptionMessageRegExp('/second_firewall_0/'); + $this->expectExceptionMessageMatches('/second_firewall_0/'); $authenticatorA = $this->getMockBuilder(AuthenticatorInterface::class)->getMock(); $authenticators = [$authenticatorA]; diff --git a/src/Symfony/Component/Yaml/Tests/InlineTest.php b/src/Symfony/Component/Yaml/Tests/InlineTest.php index 0c6d509381..362421ff8e 100644 --- a/src/Symfony/Component/Yaml/Tests/InlineTest.php +++ b/src/Symfony/Component/Yaml/Tests/InlineTest.php @@ -73,7 +73,7 @@ class InlineTest extends TestCase public function testParsePhpConstantThrowsExceptionOnInvalidType() { $this->expectException('Symfony\Component\Yaml\Exception\ParseException'); - $this->expectExceptionMessageRegExp('#The string "!php/const PHP_INT_MAX" could not be parsed as a constant.*#'); + $this->expectExceptionMessageMatches('#The string "!php/const PHP_INT_MAX" could not be parsed as a constant.*#'); Inline::parse('!php/const PHP_INT_MAX', Yaml::PARSE_EXCEPTION_ON_INVALID_TYPE); } @@ -675,7 +675,7 @@ class InlineTest extends TestCase public function testParseInvalidBinaryData($data, $expectedMessage) { $this->expectException('Symfony\Component\Yaml\Exception\ParseException'); - $this->expectExceptionMessageRegExp($expectedMessage); + $this->expectExceptionMessageMatches($expectedMessage); Inline::parse($data); } diff --git a/src/Symfony/Component/Yaml/Tests/ParserTest.php b/src/Symfony/Component/Yaml/Tests/ParserTest.php index 6393b321fc..b6cdb6a9aa 100644 --- a/src/Symfony/Component/Yaml/Tests/ParserTest.php +++ b/src/Symfony/Component/Yaml/Tests/ParserTest.php @@ -706,7 +706,7 @@ EOF; public function testMultipleDocumentsNotSupportedException() { $this->expectException('Symfony\Component\Yaml\Exception\ParseException'); - $this->expectExceptionMessageRegExp('/^Multiple documents are not supported.+/'); + $this->expectExceptionMessageMatches('/^Multiple documents are not supported.+/'); Yaml::parse(<<<'EOL' # Ranking of 1998 home runs --- @@ -1468,7 +1468,7 @@ EOT public function testParseInvalidBinaryData($data, $expectedMessage) { $this->expectException('Symfony\Component\Yaml\Exception\ParseException'); - $this->expectExceptionMessageRegExp($expectedMessage); + $this->expectExceptionMessageMatches($expectedMessage); $this->parser->parse($data); } @@ -2077,14 +2077,14 @@ YAML; public function testParsingNonExistentFilesThrowsException() { $this->expectException('Symfony\Component\Yaml\Exception\ParseException'); - $this->expectExceptionMessageRegExp('#^File ".+/Fixtures/nonexistent.yml" does not exist\.$#'); + $this->expectExceptionMessageMatches('#^File ".+/Fixtures/nonexistent.yml" does not exist\.$#'); $this->parser->parseFile(__DIR__.'/Fixtures/nonexistent.yml'); } public function testParsingNotReadableFilesThrowsException() { $this->expectException('Symfony\Component\Yaml\Exception\ParseException'); - $this->expectExceptionMessageRegExp('#^File ".+/Fixtures/not_readable.yml" cannot be read\.$#'); + $this->expectExceptionMessageMatches('#^File ".+/Fixtures/not_readable.yml" cannot be read\.$#'); if ('\\' === \DIRECTORY_SEPARATOR) { $this->markTestSkipped('chmod is not supported on Windows'); } From e873ddd72cf920fd1e1fecb2971c191d77755d0f Mon Sep 17 00:00:00 2001 From: Michal Forbak Date: Tue, 21 Jul 2020 13:30:05 +0200 Subject: [PATCH 4/4] Connect to RedisCluster with password auth Currently it is not possible to connect to RedisCluster with password. AUTH param is described in documentation (last example) https://symfony.com/doc/current/components/cache/adapters/redis_adapter.html#configure-the-connection but totally ignored in the code and connection fails ``` RedisAdapter::createConnection( 'redis:?host[localhost]&host[localhost:6379]&host[/var/run/redis.sock:]&auth=my-password&redis_cluster=1' ); ``` See RedisCluster usage here https://github.com/phpredis/phpredis/blob/develop/cluster.markdown#declaring-a-cluster-with-an-array-of-seeds --- src/Symfony/Component/Cache/Traits/RedisTrait.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Symfony/Component/Cache/Traits/RedisTrait.php b/src/Symfony/Component/Cache/Traits/RedisTrait.php index a97309e619..9183f39e0c 100644 --- a/src/Symfony/Component/Cache/Traits/RedisTrait.php +++ b/src/Symfony/Component/Cache/Traits/RedisTrait.php @@ -228,7 +228,7 @@ trait RedisTrait } try { - $redis = new $class(null, $hosts, $params['timeout'], $params['read_timeout'], (bool) $params['persistent']); + $redis = new $class(null, $hosts, $params['timeout'], $params['read_timeout'], (bool) $params['persistent'], $params['auth'] ?? ''); } catch (\RedisClusterException $e) { throw new InvalidArgumentException(sprintf('Redis connection "%s" failed: ', $dsn).$e->getMessage()); }