From a1b14843764ab2168448e54f491c727fab96bed6 Mon Sep 17 00:00:00 2001 From: Christian Flothmann Date: Thu, 11 Jan 2018 08:05:20 +0100 Subject: [PATCH 01/10] always call the parent class' constructor --- .../DependencyInjection/Dumper/PhpDumper.php | 23 ++++++-- .../Tests/Dumper/PhpDumperTest.php | 40 +++++++++++++ ...tructorWithMandatoryArgumentsContainer.php | 10 ++++ ...structorWithOptionalArgumentsContainer.php | 10 ++++ .../ConstructorWithoutArgumentsContainer.php | 10 ++++ .../Container/NoConstructorContainer.php | 7 +++ ...er_class_constructor_without_arguments.php | 57 +++++++++++++++++++ ...s_with_mandatory_constructor_arguments.php | 55 ++++++++++++++++++ ...ss_with_optional_constructor_arguments.php | 57 +++++++++++++++++++ ...om_container_class_without_constructor.php | 55 ++++++++++++++++++ 10 files changed, 320 insertions(+), 4 deletions(-) create mode 100644 src/Symfony/Component/DependencyInjection/Tests/Fixtures/Container/ConstructorWithMandatoryArgumentsContainer.php create mode 100644 src/Symfony/Component/DependencyInjection/Tests/Fixtures/Container/ConstructorWithOptionalArgumentsContainer.php create mode 100644 src/Symfony/Component/DependencyInjection/Tests/Fixtures/Container/ConstructorWithoutArgumentsContainer.php create mode 100644 src/Symfony/Component/DependencyInjection/Tests/Fixtures/Container/NoConstructorContainer.php create mode 100644 src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/custom_container_class_constructor_without_arguments.php create mode 100644 src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/custom_container_class_with_mandatory_constructor_arguments.php create mode 100644 src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/custom_container_class_with_optional_constructor_arguments.php create mode 100644 src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/custom_container_class_without_constructor.php diff --git a/src/Symfony/Component/DependencyInjection/Dumper/PhpDumper.php b/src/Symfony/Component/DependencyInjection/Dumper/PhpDumper.php index 4ff85f51b3..2fd3c72fd1 100644 --- a/src/Symfony/Component/DependencyInjection/Dumper/PhpDumper.php +++ b/src/Symfony/Component/DependencyInjection/Dumper/PhpDumper.php @@ -128,6 +128,11 @@ class PhpDumper extends Dumper if (0 !== strpos($baseClass = $options['base_class'], '\\') && 'Container' !== $baseClass) { $baseClass = sprintf('%s\%s', $options['namespace'] ? '\\'.$options['namespace'] : '', $baseClass); + $baseClassWithNamespace = $baseClass; + } elseif ('Container' === $baseClass) { + $baseClassWithNamespace = Container::class; + } else { + $baseClassWithNamespace = $baseClass; } $this->initializeMethodNamesMap('Container' === $baseClass ? Container::class : $baseClass); @@ -169,7 +174,7 @@ class PhpDumper extends Dumper } $code = - $this->startClass($options['class'], $baseClass). + $this->startClass($options['class'], $baseClass, $baseClassWithNamespace). $this->addServices(). $this->addDefaultParametersMethod(). $this->endClass() @@ -917,12 +922,13 @@ EOF; /** * Adds the class headers. * - * @param string $class Class name - * @param string $baseClass The name of the base class + * @param string $class Class name + * @param string $baseClass The name of the base class + * @param string $baseClassWithNamespace Fully qualified base class name * * @return string */ - private function startClass($class, $baseClass) + private function startClass($class, $baseClass, $baseClassWithNamespace) { $bagClass = $this->container->isCompiled() ? 'use Symfony\Component\DependencyInjection\ParameterBag\FrozenParameterBag;' : 'use Symfony\Component\DependencyInjection\ParameterBag\\ParameterBag;'; $namespaceLine = !$this->asFiles && $this->namespace ? "\nnamespace {$this->namespace};\n" : ''; @@ -970,9 +976,18 @@ EOF; } if ($this->container->isCompiled()) { + if (Container::class !== $baseClassWithNamespace) { + $r = $this->container->getReflectionClass($baseClassWithNamespace, false); + + if (null !== $r && (null !== $constructor = $r->getConstructor()) && 0 === $constructor->getNumberOfRequiredParameters()) { + $code .= " parent::__construct();\n\n"; + } + } + if ($this->container->getParameterBag()->all()) { $code .= " \$this->parameters = \$this->getDefaultParameters();\n\n"; } + $code .= " \$this->services = array();\n"; } else { $arguments = $this->container->getParameterBag()->all() ? 'new ParameterBag($this->getDefaultParameters())' : null; diff --git a/src/Symfony/Component/DependencyInjection/Tests/Dumper/PhpDumperTest.php b/src/Symfony/Component/DependencyInjection/Tests/Dumper/PhpDumperTest.php index 4a882828a3..f12fc608c9 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Dumper/PhpDumperTest.php +++ b/src/Symfony/Component/DependencyInjection/Tests/Dumper/PhpDumperTest.php @@ -107,6 +107,46 @@ class PhpDumperTest extends TestCase $this->assertStringEqualsFile(self::$fixturesPath.'/php/services12.php', $dumper->dump(array('file' => __FILE__)), '->dump() dumps __DIR__ relative strings'); } + public function testDumpCustomContainerClassWithoutConstructor() + { + $container = new ContainerBuilder(); + $container->compile(); + + $dumper = new PhpDumper($container); + + $this->assertStringEqualsFile(self::$fixturesPath.'/php/custom_container_class_without_constructor.php', $dumper->dump(array('base_class' => 'NoConstructorContainer', 'namespace' => 'Symfony\Component\DependencyInjection\Tests\Fixtures\Container'))); + } + + public function testDumpCustomContainerClassConstructorWithoutArguments() + { + $container = new ContainerBuilder(); + $container->compile(); + + $dumper = new PhpDumper($container); + + $this->assertStringEqualsFile(self::$fixturesPath.'/php/custom_container_class_constructor_without_arguments.php', $dumper->dump(array('base_class' => 'ConstructorWithoutArgumentsContainer', 'namespace' => 'Symfony\Component\DependencyInjection\Tests\Fixtures\Container'))); + } + + public function testDumpCustomContainerClassWithOptionalArgumentLessConstructor() + { + $container = new ContainerBuilder(); + $container->compile(); + + $dumper = new PhpDumper($container); + + $this->assertStringEqualsFile(self::$fixturesPath.'/php/custom_container_class_with_optional_constructor_arguments.php', $dumper->dump(array('base_class' => 'ConstructorWithOptionalArgumentsContainer', 'namespace' => 'Symfony\Component\DependencyInjection\Tests\Fixtures\Container'))); + } + + public function testDumpCustomContainerClassWithMandatoryArgumentLessConstructor() + { + $container = new ContainerBuilder(); + $container->compile(); + + $dumper = new PhpDumper($container); + + $this->assertStringEqualsFile(self::$fixturesPath.'/php/custom_container_class_with_mandatory_constructor_arguments.php', $dumper->dump(array('base_class' => 'ConstructorWithMandatoryArgumentsContainer', 'namespace' => 'Symfony\Component\DependencyInjection\Tests\Fixtures\Container'))); + } + /** * @dataProvider provideInvalidParameters * @expectedException \InvalidArgumentException diff --git a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/Container/ConstructorWithMandatoryArgumentsContainer.php b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/Container/ConstructorWithMandatoryArgumentsContainer.php new file mode 100644 index 0000000000..ba55fb75d8 --- /dev/null +++ b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/Container/ConstructorWithMandatoryArgumentsContainer.php @@ -0,0 +1,10 @@ +services = array(); + + $this->aliases = array(); + } + + public function getRemovedIds() + { + return array( + 'Psr\\Container\\ContainerInterface' => true, + 'Symfony\\Component\\DependencyInjection\\ContainerInterface' => true, + ); + } + + public function compile() + { + throw new LogicException('You cannot compile a dumped container that was already compiled.'); + } + + public function isCompiled() + { + return true; + } + + public function isFrozen() + { + @trigger_error(sprintf('The %s() method is deprecated since Symfony 3.3 and will be removed in 4.0. Use the isCompiled() method instead.', __METHOD__), E_USER_DEPRECATED); + + return true; + } +} diff --git a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/custom_container_class_with_mandatory_constructor_arguments.php b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/custom_container_class_with_mandatory_constructor_arguments.php new file mode 100644 index 0000000000..dd9ed9cbb3 --- /dev/null +++ b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/custom_container_class_with_mandatory_constructor_arguments.php @@ -0,0 +1,55 @@ +services = array(); + + $this->aliases = array(); + } + + public function getRemovedIds() + { + return array( + 'Psr\\Container\\ContainerInterface' => true, + 'Symfony\\Component\\DependencyInjection\\ContainerInterface' => true, + ); + } + + public function compile() + { + throw new LogicException('You cannot compile a dumped container that was already compiled.'); + } + + public function isCompiled() + { + return true; + } + + public function isFrozen() + { + @trigger_error(sprintf('The %s() method is deprecated since Symfony 3.3 and will be removed in 4.0. Use the isCompiled() method instead.', __METHOD__), E_USER_DEPRECATED); + + return true; + } +} diff --git a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/custom_container_class_with_optional_constructor_arguments.php b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/custom_container_class_with_optional_constructor_arguments.php new file mode 100644 index 0000000000..d65ac7dfbc --- /dev/null +++ b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/custom_container_class_with_optional_constructor_arguments.php @@ -0,0 +1,57 @@ +services = array(); + + $this->aliases = array(); + } + + public function getRemovedIds() + { + return array( + 'Psr\\Container\\ContainerInterface' => true, + 'Symfony\\Component\\DependencyInjection\\ContainerInterface' => true, + ); + } + + public function compile() + { + throw new LogicException('You cannot compile a dumped container that was already compiled.'); + } + + public function isCompiled() + { + return true; + } + + public function isFrozen() + { + @trigger_error(sprintf('The %s() method is deprecated since Symfony 3.3 and will be removed in 4.0. Use the isCompiled() method instead.', __METHOD__), E_USER_DEPRECATED); + + return true; + } +} diff --git a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/custom_container_class_without_constructor.php b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/custom_container_class_without_constructor.php new file mode 100644 index 0000000000..4cf1ae40b4 --- /dev/null +++ b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/custom_container_class_without_constructor.php @@ -0,0 +1,55 @@ +services = array(); + + $this->aliases = array(); + } + + public function getRemovedIds() + { + return array( + 'Psr\\Container\\ContainerInterface' => true, + 'Symfony\\Component\\DependencyInjection\\ContainerInterface' => true, + ); + } + + public function compile() + { + throw new LogicException('You cannot compile a dumped container that was already compiled.'); + } + + public function isCompiled() + { + return true; + } + + public function isFrozen() + { + @trigger_error(sprintf('The %s() method is deprecated since Symfony 3.3 and will be removed in 4.0. Use the isCompiled() method instead.', __METHOD__), E_USER_DEPRECATED); + + return true; + } +} From 67e821b94f304a9f33ad91f492b0a6ebf2424843 Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Tue, 30 Jan 2018 22:38:46 +0100 Subject: [PATCH 02/10] [Config] Handle Service/EventSubscriberInterface in ReflectionClassResource --- .../Resource/ReflectionClassResource.php | 17 ++++++- .../Resource/ReflectionClassResourceTest.php | 46 +++++++++++++++++++ src/Symfony/Component/Config/composer.json | 3 +- .../RegisterServiceSubscribersPass.php | 12 ++--- .../RegisterListenersPass.php | 16 +++---- 5 files changed, 77 insertions(+), 17 deletions(-) diff --git a/src/Symfony/Component/Config/Resource/ReflectionClassResource.php b/src/Symfony/Component/Config/Resource/ReflectionClassResource.php index a8e1f9611b..735784ad64 100644 --- a/src/Symfony/Component/Config/Resource/ReflectionClassResource.php +++ b/src/Symfony/Component/Config/Resource/ReflectionClassResource.php @@ -11,6 +11,9 @@ namespace Symfony\Component\Config\Resource; +use Symfony\Component\DependencyInjection\ServiceSubscriberInterface; +use Symfony\Component\EventDispatcher\EventSubscriberInterface; + /** * @author Nicolas Grekas */ @@ -114,7 +117,9 @@ class ReflectionClassResource implements SelfCheckingResourceInterface, \Seriali private function generateSignature(\ReflectionClass $class) { - yield $class->getDocComment().$class->getModifiers(); + yield $class->getDocComment(); + yield (int) $class->isFinal(); + yield (int) $class->isAbstract(); if ($class->isTrait()) { yield print_r(class_uses($class->name), true); @@ -149,6 +154,16 @@ class ReflectionClassResource implements SelfCheckingResourceInterface, \Seriali yield print_r($defaults, true); } } + + if ($class->isSubclassOf(EventSubscriberInterface::class)) { + yield EventSubscriberInterface::class; + yield print_r(\call_user_func(array($class->name, 'getSubscribedEvents')), true); + } + + if ($class->isSubclassOf(ServiceSubscriberInterface::class)) { + yield ServiceSubscriberInterface::class; + yield print_r(\call_user_func(array($class->name, 'getSubscribedServices')), true); + } } } diff --git a/src/Symfony/Component/Config/Tests/Resource/ReflectionClassResourceTest.php b/src/Symfony/Component/Config/Tests/Resource/ReflectionClassResourceTest.php index 4eca3d50e4..3f13096f0a 100644 --- a/src/Symfony/Component/Config/Tests/Resource/ReflectionClassResourceTest.php +++ b/src/Symfony/Component/Config/Tests/Resource/ReflectionClassResourceTest.php @@ -13,6 +13,8 @@ namespace Symfony\Component\Config\Tests\Resource; use PHPUnit\Framework\TestCase; use Symfony\Component\Config\Resource\ReflectionClassResource; +use Symfony\Component\DependencyInjection\ServiceSubscriberInterface; +use Symfony\Component\EventDispatcher\EventSubscriberInterface; class ReflectionClassResourceTest extends TestCase { @@ -136,8 +138,52 @@ EOPHP; yield array(0, 14, '/** priv docblock */'); yield array(0, 15, ''); } + + public function testEventSubscriber() + { + $res = new ReflectionClassResource(new \ReflectionClass(TestEventSubscriber::class)); + $this->assertTrue($res->isFresh(0)); + + TestEventSubscriber::$subscribedEvents = array(123); + $this->assertFalse($res->isFresh(0)); + + $res = new ReflectionClassResource(new \ReflectionClass(TestEventSubscriber::class)); + $this->assertTrue($res->isFresh(0)); + } + + public function testServiceSubscriber() + { + $res = new ReflectionClassResource(new \ReflectionClass(TestServiceSubscriber::class)); + $this->assertTrue($res->isFresh(0)); + + TestServiceSubscriber::$subscribedServices = array(123); + $this->assertFalse($res->isFresh(0)); + + $res = new ReflectionClassResource(new \ReflectionClass(TestServiceSubscriber::class)); + $this->assertTrue($res->isFresh(0)); + } } interface DummyInterface { } + +class TestEventSubscriber implements EventSubscriberInterface +{ + public static $subscribedEvents = array(); + + public static function getSubscribedEvents() + { + return self::$subscribedEvents; + } +} + +class TestServiceSubscriber implements ServiceSubscriberInterface +{ + public static $subscribedServices = array(); + + public static function getSubscribedServices() + { + return self::$subscribedServices; + } +} diff --git a/src/Symfony/Component/Config/composer.json b/src/Symfony/Component/Config/composer.json index 6f759720e6..ab26402819 100644 --- a/src/Symfony/Component/Config/composer.json +++ b/src/Symfony/Component/Config/composer.json @@ -22,7 +22,8 @@ "require-dev": { "symfony/finder": "~3.3|~4.0", "symfony/yaml": "~3.0|~4.0", - "symfony/dependency-injection": "~3.3|~4.0" + "symfony/dependency-injection": "~3.3|~4.0", + "symfony/event-dispatcher": "~3.3|~4.0" }, "conflict": { "symfony/finder": "<3.3", diff --git a/src/Symfony/Component/DependencyInjection/Compiler/RegisterServiceSubscribersPass.php b/src/Symfony/Component/DependencyInjection/Compiler/RegisterServiceSubscribersPass.php index 4ed990ac08..572eabb7d9 100644 --- a/src/Symfony/Component/DependencyInjection/Compiler/RegisterServiceSubscribersPass.php +++ b/src/Symfony/Component/DependencyInjection/Compiler/RegisterServiceSubscribersPass.php @@ -56,14 +56,14 @@ class RegisterServiceSubscribersPass extends AbstractRecursivePass } $class = $value->getClass(); - if (!is_subclass_of($class, ServiceSubscriberInterface::class)) { - if (!class_exists($class, false)) { - throw new InvalidArgumentException(sprintf('Class "%s" used for service "%s" cannot be found.', $class, $this->currentId)); - } - + if (!$r = $this->container->getReflectionClass($class)) { + throw new InvalidArgumentException(sprintf('Class "%s" used for service "%s" cannot be found.', $class, $this->currentId)); + } + if (!$r->isSubclassOf(ServiceSubscriberInterface::class)) { throw new InvalidArgumentException(sprintf('Service "%s" must implement interface "%s".', $this->currentId, ServiceSubscriberInterface::class)); } - $this->container->addObjectResource($class); + $class = $r->name; + $subscriberMap = array(); $declaringClass = (new \ReflectionMethod($class, 'getSubscribedServices'))->class; diff --git a/src/Symfony/Component/EventDispatcher/DependencyInjection/RegisterListenersPass.php b/src/Symfony/Component/EventDispatcher/DependencyInjection/RegisterListenersPass.php index 9f9c09c528..ff636d6180 100644 --- a/src/Symfony/Component/EventDispatcher/DependencyInjection/RegisterListenersPass.php +++ b/src/Symfony/Component/EventDispatcher/DependencyInjection/RegisterListenersPass.php @@ -89,17 +89,15 @@ class RegisterListenersPass implements CompilerPassInterface $def = $container->getDefinition($id); // We must assume that the class value has been correctly filled, even if the service is created by a factory - $class = $container->getParameterBag()->resolveValue($def->getClass()); - $interface = 'Symfony\Component\EventDispatcher\EventSubscriberInterface'; + $class = $def->getClass(); - if (!is_subclass_of($class, $interface)) { - if (!class_exists($class, false)) { - throw new InvalidArgumentException(sprintf('Class "%s" used for service "%s" cannot be found.', $class, $id)); - } - - throw new InvalidArgumentException(sprintf('Service "%s" must implement interface "%s".', $id, $interface)); + if (!$r = $container->getReflectionClass($class)) { + throw new InvalidArgumentException(sprintf('Class "%s" used for service "%s" cannot be found.', $class, $id)); } - $container->addObjectResource($class); + if (!$r->isSubclassOf(EventSubscriberInterface::class)) { + throw new InvalidArgumentException(sprintf('Service "%s" must implement interface "%s".', $id, EventSubscriberInterface::class)); + } + $class = $r->name; ExtractingEventDispatcher::$subscriber = $class; $extractingDispatcher->addSubscriber($extractingDispatcher); From ad98c1fa906ab10bc9ce0cc5dc304f9a6028bd40 Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Wed, 31 Jan 2018 16:05:11 +0100 Subject: [PATCH 03/10] [DI][Routing] Fix tracking of globbed resources --- .../Resources/config/routing.xml | 2 +- .../Bundle/FrameworkBundle/composer.json | 2 +- .../Loader/GlobFileLoader.php | 40 ++++++++++++++++ src/Symfony/Component/HttpKernel/Kernel.php | 4 +- .../Component/HttpKernel/composer.json | 4 +- .../Routing/Loader/GlobFileLoader.php | 47 +++++++++++++++++++ 6 files changed, 93 insertions(+), 6 deletions(-) create mode 100644 src/Symfony/Component/DependencyInjection/Loader/GlobFileLoader.php create mode 100644 src/Symfony/Component/Routing/Loader/GlobFileLoader.php diff --git a/src/Symfony/Bundle/FrameworkBundle/Resources/config/routing.xml b/src/Symfony/Bundle/FrameworkBundle/Resources/config/routing.xml index 74643a9d20..1ad1a752a6 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Resources/config/routing.xml +++ b/src/Symfony/Bundle/FrameworkBundle/Resources/config/routing.xml @@ -38,7 +38,7 @@ - + diff --git a/src/Symfony/Bundle/FrameworkBundle/composer.json b/src/Symfony/Bundle/FrameworkBundle/composer.json index 1f0f233feb..9bb59cf8e8 100644 --- a/src/Symfony/Bundle/FrameworkBundle/composer.json +++ b/src/Symfony/Bundle/FrameworkBundle/composer.json @@ -28,7 +28,7 @@ "symfony/polyfill-mbstring": "~1.0", "symfony/filesystem": "~2.8|~3.0|~4.0", "symfony/finder": "~2.8|~3.0|~4.0", - "symfony/routing": "~3.4|~4.0" + "symfony/routing": "^3.4.5|^4.0.5" }, "require-dev": { "doctrine/cache": "~1.0", diff --git a/src/Symfony/Component/DependencyInjection/Loader/GlobFileLoader.php b/src/Symfony/Component/DependencyInjection/Loader/GlobFileLoader.php new file mode 100644 index 0000000000..4b25610efe --- /dev/null +++ b/src/Symfony/Component/DependencyInjection/Loader/GlobFileLoader.php @@ -0,0 +1,40 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\DependencyInjection\Loader; + +/** + * GlobFileLoader loads files from a glob pattern. + * + * @author Nicolas Grekas + */ +class GlobFileLoader extends FileLoader +{ + /** + * {@inheritdoc} + */ + public function load($resource, $type = null) + { + foreach ($this->glob($resource, false, $globResource) as $path => $info) { + $this->import($path); + } + + $this->container->addResource($globResource); + } + + /** + * {@inheritdoc} + */ + public function supports($resource, $type = null) + { + return 'glob' === $type; + } +} diff --git a/src/Symfony/Component/HttpKernel/Kernel.php b/src/Symfony/Component/HttpKernel/Kernel.php index 56dbc1f5f6..a5f5e3c770 100644 --- a/src/Symfony/Component/HttpKernel/Kernel.php +++ b/src/Symfony/Component/HttpKernel/Kernel.php @@ -22,6 +22,7 @@ use Symfony\Component\DependencyInjection\Loader\XmlFileLoader; use Symfony\Component\DependencyInjection\Loader\YamlFileLoader; use Symfony\Component\DependencyInjection\Loader\IniFileLoader; use Symfony\Component\DependencyInjection\Loader\PhpFileLoader; +use Symfony\Component\DependencyInjection\Loader\GlobFileLoader; use Symfony\Component\DependencyInjection\Loader\DirectoryLoader; use Symfony\Component\DependencyInjection\Loader\ClosureLoader; use Symfony\Component\Filesystem\Filesystem; @@ -32,7 +33,6 @@ use Symfony\Component\HttpKernel\Config\EnvParametersResource; use Symfony\Component\HttpKernel\Config\FileLocator; use Symfony\Component\HttpKernel\DependencyInjection\MergeExtensionConfigurationPass; use Symfony\Component\HttpKernel\DependencyInjection\AddAnnotatedClassesToCachePass; -use Symfony\Component\Config\Loader\GlobFileLoader; use Symfony\Component\Config\Loader\LoaderResolver; use Symfony\Component\Config\Loader\DelegatingLoader; use Symfony\Component\Config\ConfigCache; @@ -880,7 +880,7 @@ abstract class Kernel implements KernelInterface, RebootableInterface, Terminabl new YamlFileLoader($container, $locator), new IniFileLoader($container, $locator), new PhpFileLoader($container, $locator), - new GlobFileLoader($locator), + new GlobFileLoader($container, $locator), new DirectoryLoader($container, $locator), new ClosureLoader($container), )); diff --git a/src/Symfony/Component/HttpKernel/composer.json b/src/Symfony/Component/HttpKernel/composer.json index b33675763f..26b782bb38 100644 --- a/src/Symfony/Component/HttpKernel/composer.json +++ b/src/Symfony/Component/HttpKernel/composer.json @@ -28,7 +28,7 @@ "symfony/config": "~2.8|~3.0|~4.0", "symfony/console": "~2.8|~3.0|~4.0", "symfony/css-selector": "~2.8|~3.0|~4.0", - "symfony/dependency-injection": "~3.4|~4.0", + "symfony/dependency-injection": "^3.4.5|^4.0.5", "symfony/dom-crawler": "~2.8|~3.0|~4.0", "symfony/expression-language": "~2.8|~3.0|~4.0", "symfony/finder": "~2.8|~3.0|~4.0", @@ -45,7 +45,7 @@ }, "conflict": { "symfony/config": "<2.8", - "symfony/dependency-injection": "<3.4", + "symfony/dependency-injection": "<3.4.5|<4.0.5,>=4", "symfony/var-dumper": "<3.3", "twig/twig": "<1.34|<2.4,>=2" }, diff --git a/src/Symfony/Component/Routing/Loader/GlobFileLoader.php b/src/Symfony/Component/Routing/Loader/GlobFileLoader.php new file mode 100644 index 0000000000..03ee341b98 --- /dev/null +++ b/src/Symfony/Component/Routing/Loader/GlobFileLoader.php @@ -0,0 +1,47 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\Routing\Loader; + +use Symfony\Component\Config\Loader\FileLoader; +use Symfony\Component\Routing\RouteCollection; + +/** + * GlobFileLoader loads files from a glob pattern. + * + * @author Nicolas Grekas + */ +class GlobFileLoader extends FileLoader +{ + /** + * {@inheritdoc} + */ + public function load($resource, $type = null) + { + $collection = new RouteCollection(); + + foreach ($this->glob($resource, false, $globResource) as $path => $info) { + $collection->addCollection($this->import($path)); + } + + $collection->addResource($globResource); + + return $collection; + } + + /** + * {@inheritdoc} + */ + public function supports($resource, $type = null) + { + return 'glob' === $type; + } +} From 829f59da7f88bc8945761ae95091aa0352c1e7e6 Mon Sep 17 00:00:00 2001 From: Gabriel Caruso Date: Thu, 1 Feb 2018 03:55:42 -0200 Subject: [PATCH 04/10] Improve assertions --- .../Bridge/Doctrine/Tests/ManagerRegistryTest.php | 2 +- src/Symfony/Bridge/Monolog/Tests/LoggerTest.php | 4 ++-- .../DependencyInjection/FrameworkExtensionTest.php | 2 +- .../Cache/Tests/Adapter/NullAdapterTest.php | 2 +- .../Cache/Tests/Adapter/ProxyAdapterTest.php | 2 +- .../Component/Cache/Tests/Simple/NullCacheTest.php | 2 +- .../Tests/Resource/ReflectionClassResourceTest.php | 2 +- .../DataCollector/FormDataCollectorTest.php | 4 ++-- .../Storage/Handler/NativeSessionHandlerTest.php | 2 +- .../Component/HttpKernel/Tests/KernelTest.php | 4 ++-- .../Tests/Profiler/FileProfilerStorageTest.php | 12 ++++++------ .../Routing/Tests/RouteCollectionBuilderTest.php | 2 +- 12 files changed, 20 insertions(+), 20 deletions(-) diff --git a/src/Symfony/Bridge/Doctrine/Tests/ManagerRegistryTest.php b/src/Symfony/Bridge/Doctrine/Tests/ManagerRegistryTest.php index d1596a1968..490a48cfe6 100644 --- a/src/Symfony/Bridge/Doctrine/Tests/ManagerRegistryTest.php +++ b/src/Symfony/Bridge/Doctrine/Tests/ManagerRegistryTest.php @@ -40,7 +40,7 @@ class ManagerRegistryTest extends TestCase $registry->resetManager(); $this->assertSame($foo, $container->get('foo')); - $this->assertFalse(isset($foo->bar)); + $this->assertObjectNotHasAttribute('bar', $foo); } } diff --git a/src/Symfony/Bridge/Monolog/Tests/LoggerTest.php b/src/Symfony/Bridge/Monolog/Tests/LoggerTest.php index a5fab0583c..fdd36336cb 100644 --- a/src/Symfony/Bridge/Monolog/Tests/LoggerTest.php +++ b/src/Symfony/Bridge/Monolog/Tests/LoggerTest.php @@ -28,7 +28,7 @@ class LoggerTest extends TestCase $logger = new Logger(__METHOD__, array($handler)); $this->assertTrue($logger->error('error message')); - $this->assertSame(1, count($logger->getLogs())); + $this->assertCount(1, $logger->getLogs()); } public function testGetLogsWithoutDebugProcessor() @@ -93,7 +93,7 @@ class LoggerTest extends TestCase $logger = new Logger(__METHOD__, array($handler), array($processor)); $this->assertTrue($logger->error('error message')); - $this->assertSame(1, count($logger->getLogs())); + $this->assertCount(1, $logger->getLogs()); } public function testCountErrorsWithDebugProcessor() diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php index cabccb38c1..b40e735c98 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php @@ -1123,7 +1123,7 @@ abstract class FrameworkExtensionTest extends TestCase $this->assertFalse($poolDefinition->isAbstract(), sprintf('Service definition "%s" is not abstract.', $id)); $tag = $poolDefinition->getTag('cache.pool'); - $this->assertTrue(isset($tag[0]['default_lifetime']), 'The default lifetime is stored as an attribute of the "cache.pool" tag.'); + $this->assertArrayHasKey('default_lifetime', $tag[0], 'The default lifetime is stored as an attribute of the "cache.pool" tag.'); $this->assertSame($defaultLifetime, $tag[0]['default_lifetime'], 'The default lifetime is stored as an attribute of the "cache.pool" tag.'); $parentDefinition = $poolDefinition; diff --git a/src/Symfony/Component/Cache/Tests/Adapter/NullAdapterTest.php b/src/Symfony/Component/Cache/Tests/Adapter/NullAdapterTest.php index c28a455026..73e5cad552 100644 --- a/src/Symfony/Component/Cache/Tests/Adapter/NullAdapterTest.php +++ b/src/Symfony/Component/Cache/Tests/Adapter/NullAdapterTest.php @@ -53,7 +53,7 @@ class NullAdapterTest extends TestCase $itemKey = $item->getKey(); $this->assertEquals($itemKey, $key, 'Keys must be preserved when fetching multiple items'); - $this->assertTrue(in_array($key, $keys), 'Cache key can not change.'); + $this->assertContains($key, $keys, 'Cache key can not change.'); $this->assertFalse($item->isHit()); // Remove $key for $keys diff --git a/src/Symfony/Component/Cache/Tests/Adapter/ProxyAdapterTest.php b/src/Symfony/Component/Cache/Tests/Adapter/ProxyAdapterTest.php index 5e6abd16c1..ff4b9d34bc 100644 --- a/src/Symfony/Component/Cache/Tests/Adapter/ProxyAdapterTest.php +++ b/src/Symfony/Component/Cache/Tests/Adapter/ProxyAdapterTest.php @@ -43,7 +43,7 @@ class ProxyAdapterTest extends AdapterTestCase $proxyItem = $pool->getItem('foo'); - $this->assertFalse($proxyItem === $item); + $this->assertNotSame($item, $proxyItem); $pool->save($proxyItem->set('bar')); } } diff --git a/src/Symfony/Component/Cache/Tests/Simple/NullCacheTest.php b/src/Symfony/Component/Cache/Tests/Simple/NullCacheTest.php index 16dd7764d2..7b760fd3bd 100644 --- a/src/Symfony/Component/Cache/Tests/Simple/NullCacheTest.php +++ b/src/Symfony/Component/Cache/Tests/Simple/NullCacheTest.php @@ -47,7 +47,7 @@ class NullCacheTest extends TestCase $count = 0; foreach ($items as $key => $item) { - $this->assertTrue(in_array($key, $keys), 'Cache key can not change.'); + $this->assertContains($key, $keys, 'Cache key can not change.'); $this->assertSame($default, $item); // Remove $key for $keys diff --git a/src/Symfony/Component/Config/Tests/Resource/ReflectionClassResourceTest.php b/src/Symfony/Component/Config/Tests/Resource/ReflectionClassResourceTest.php index 4eca3d50e4..b14099a9eb 100644 --- a/src/Symfony/Component/Config/Tests/Resource/ReflectionClassResourceTest.php +++ b/src/Symfony/Component/Config/Tests/Resource/ReflectionClassResourceTest.php @@ -100,7 +100,7 @@ EOPHP; $signature = implode("\n", iterator_to_array($generateSignature(new \ReflectionClass($class)))); if ($changeExpected) { - $this->assertTrue($expectedSignature !== $signature); + $this->assertNotSame($expectedSignature, $signature); } else { $this->assertSame($expectedSignature, $signature); } diff --git a/src/Symfony/Component/Form/Tests/Extension/DataCollector/FormDataCollectorTest.php b/src/Symfony/Component/Form/Tests/Extension/DataCollector/FormDataCollectorTest.php index 7e591d414e..bd3f25bffb 100644 --- a/src/Symfony/Component/Form/Tests/Extension/DataCollector/FormDataCollectorTest.php +++ b/src/Symfony/Component/Form/Tests/Extension/DataCollector/FormDataCollectorTest.php @@ -690,9 +690,9 @@ class FormDataCollectorTest extends TestCase $this->assertTrue($formData['has_children_error']); $this->assertTrue($child1Data['has_children_error']); - $this->assertFalse(isset($child11Data['has_children_error']), 'The leaf data does not contains "has_children_error" property.'); + $this->assertArrayNotHasKey('has_children_error', $child11Data, 'The leaf data does not contains "has_children_error" property.'); $this->assertFalse($child2Data['has_children_error']); - $this->assertFalse(isset($child21Data['has_children_error']), 'The leaf data does not contains "has_children_error" property.'); + $this->assertArrayNotHasKey('has_children_error', $child21Data, 'The leaf data does not contains "has_children_error" property.'); } public function testReset() diff --git a/src/Symfony/Component/HttpFoundation/Tests/Session/Storage/Handler/NativeSessionHandlerTest.php b/src/Symfony/Component/HttpFoundation/Tests/Session/Storage/Handler/NativeSessionHandlerTest.php index 1a68d575e2..4a9fb600d2 100644 --- a/src/Symfony/Component/HttpFoundation/Tests/Session/Storage/Handler/NativeSessionHandlerTest.php +++ b/src/Symfony/Component/HttpFoundation/Tests/Session/Storage/Handler/NativeSessionHandlerTest.php @@ -32,7 +32,7 @@ class NativeSessionHandlerTest extends TestCase { $handler = new NativeSessionHandler(); - $this->assertTrue($handler instanceof \SessionHandler); + $this->assertInstanceOf('SessionHandler', $handler); $this->assertTrue($handler instanceof NativeSessionHandler); } } diff --git a/src/Symfony/Component/HttpKernel/Tests/KernelTest.php b/src/Symfony/Component/HttpKernel/Tests/KernelTest.php index 755e1db2b7..a16ac37dee 100644 --- a/src/Symfony/Component/HttpKernel/Tests/KernelTest.php +++ b/src/Symfony/Component/HttpKernel/Tests/KernelTest.php @@ -849,14 +849,14 @@ EOF; $kernel = new CustomProjectDirKernel(); $kernel->boot(); - $this->assertSame($containerClass, get_class($kernel->getContainer())); + $this->assertInstanceOf($containerClass, $kernel->getContainer()); $this->assertFileExists($containerFile); unlink(__DIR__.'/Fixtures/cache/custom/FixturesCustomDebugProjectContainer.php.meta'); $kernel = new CustomProjectDirKernel(function ($container) { $container->register('foo', 'stdClass')->setPublic(true); }); $kernel->boot(); - $this->assertTrue(get_class($kernel->getContainer()) !== $containerClass); + $this->assertNotInstanceOf($containerClass, $kernel->getContainer()); $this->assertFileExists($containerFile); $this->assertFileExists(dirname($containerFile).'.legacy'); } diff --git a/src/Symfony/Component/HttpKernel/Tests/Profiler/FileProfilerStorageTest.php b/src/Symfony/Component/HttpKernel/Tests/Profiler/FileProfilerStorageTest.php index 99ff207567..a1db1d9c0e 100644 --- a/src/Symfony/Component/HttpKernel/Tests/Profiler/FileProfilerStorageTest.php +++ b/src/Symfony/Component/HttpKernel/Tests/Profiler/FileProfilerStorageTest.php @@ -83,22 +83,22 @@ class FileProfilerStorageTest extends TestCase $profile = new Profile('simple_quote'); $profile->setUrl('http://foo.bar/\''); $this->storage->write($profile); - $this->assertTrue(false !== $this->storage->read('simple_quote'), '->write() accepts single quotes in URL'); + $this->assertNotFalse($this->storage->read('simple_quote'), '->write() accepts single quotes in URL'); $profile = new Profile('double_quote'); $profile->setUrl('http://foo.bar/"'); $this->storage->write($profile); - $this->assertTrue(false !== $this->storage->read('double_quote'), '->write() accepts double quotes in URL'); + $this->assertNotFalse($this->storage->read('double_quote'), '->write() accepts double quotes in URL'); $profile = new Profile('backslash'); $profile->setUrl('http://foo.bar/\\'); $this->storage->write($profile); - $this->assertTrue(false !== $this->storage->read('backslash'), '->write() accepts backslash in URL'); + $this->assertNotFalse($this->storage->read('backslash'), '->write() accepts backslash in URL'); $profile = new Profile('comma'); $profile->setUrl('http://foo.bar/,'); $this->storage->write($profile); - $this->assertTrue(false !== $this->storage->read('comma'), '->write() accepts comma in URL'); + $this->assertNotFalse($this->storage->read('comma'), '->write() accepts comma in URL'); } public function testStoreDuplicateToken() @@ -247,7 +247,7 @@ class FileProfilerStorageTest extends TestCase $profile->setMethod('GET'); $this->storage->write($profile); - $this->assertTrue(false !== $this->storage->read('token1')); + $this->assertNotFalse($this->storage->read('token1')); $this->assertCount(1, $this->storage->find('127.0.0.1', '', 10, 'GET')); $profile = new Profile('token2'); @@ -256,7 +256,7 @@ class FileProfilerStorageTest extends TestCase $profile->setMethod('GET'); $this->storage->write($profile); - $this->assertTrue(false !== $this->storage->read('token2')); + $this->assertNotFalse($this->storage->read('token2')); $this->assertCount(2, $this->storage->find('127.0.0.1', '', 10, 'GET')); $this->storage->purge(); diff --git a/src/Symfony/Component/Routing/Tests/RouteCollectionBuilderTest.php b/src/Symfony/Component/Routing/Tests/RouteCollectionBuilderTest.php index f6af600bd4..76a042d670 100644 --- a/src/Symfony/Component/Routing/Tests/RouteCollectionBuilderTest.php +++ b/src/Symfony/Component/Routing/Tests/RouteCollectionBuilderTest.php @@ -357,7 +357,7 @@ class RouteCollectionBuilderTest extends TestCase $routeCollectionBuilder->import('/directory/recurse/*', '/other/', 'glob'); $routes = $routeCollectionBuilder->build()->all(); - $this->assertEquals(2, count($routes)); + $this->assertCount(2, $routes); $this->assertEquals('/other/a', $routes['a']->getPath()); $this->assertEquals('/other/b', $routes['b']->getPath()); } From 945c753d4413c6f6ebbc1036cc1ac8f72c130f9e Mon Sep 17 00:00:00 2001 From: Samuel ROZE Date: Thu, 1 Feb 2018 08:54:27 +0000 Subject: [PATCH 05/10] Add tests for glob loaders --- .../Tests/Loader/GlobFileLoaderTest.php | 44 ++++++++++++++++++ .../Tests/Loader/GlobFileLoaderTest.php | 45 +++++++++++++++++++ 2 files changed, 89 insertions(+) create mode 100644 src/Symfony/Component/DependencyInjection/Tests/Loader/GlobFileLoaderTest.php create mode 100644 src/Symfony/Component/Routing/Tests/Loader/GlobFileLoaderTest.php diff --git a/src/Symfony/Component/DependencyInjection/Tests/Loader/GlobFileLoaderTest.php b/src/Symfony/Component/DependencyInjection/Tests/Loader/GlobFileLoaderTest.php new file mode 100644 index 0000000000..a3be4dfd3b --- /dev/null +++ b/src/Symfony/Component/DependencyInjection/Tests/Loader/GlobFileLoaderTest.php @@ -0,0 +1,44 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\DependencyInjection\Tests\Loader; + +use PHPUnit\Framework\TestCase; +use Symfony\Component\Config\Resource\GlobResource; +use Symfony\Component\DependencyInjection\ContainerBuilder; +use Symfony\Component\DependencyInjection\Loader\GlobFileLoader; +use Symfony\Component\Config\FileLocator; + +class GlobFileLoaderTest extends TestCase +{ + public function testSupports() + { + $loader = new GlobFileLoader(new ContainerBuilder(), new FileLocator()); + + $this->assertTrue($loader->supports('any-path', 'glob'), '->supports() returns true if the resource has the glob type'); + $this->assertFalse($loader->supports('any-path'), '->supports() returns false if the resource is not of glob type'); + } + + public function testLoadAddsTheGlobResourceToTheContainer() + { + $loader = new GlobFileLoaderWithoutImport($container = new ContainerBuilder(), new FileLocator()); + $loader->load(__DIR__.'/../Fixtures/config/*'); + + $this->assertEquals(new GlobResource(__DIR__.'/../Fixtures/config', '/*', false), $container->getResources()[1]); + } +} + +class GlobFileLoaderWithoutImport extends GlobFileLoader +{ + public function import($resource, $type = null, $ignoreErrors = false, $sourceResource = null) + { + } +} diff --git a/src/Symfony/Component/Routing/Tests/Loader/GlobFileLoaderTest.php b/src/Symfony/Component/Routing/Tests/Loader/GlobFileLoaderTest.php new file mode 100644 index 0000000000..08d806a8a4 --- /dev/null +++ b/src/Symfony/Component/Routing/Tests/Loader/GlobFileLoaderTest.php @@ -0,0 +1,45 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\Routing\Tests\Loader; + +use PHPUnit\Framework\TestCase; +use Symfony\Component\Config\Resource\GlobResource; +use Symfony\Component\Config\FileLocator; +use Symfony\Component\Routing\Loader\GlobFileLoader; +use Symfony\Component\Routing\RouteCollection; + +class GlobFileLoaderTest extends TestCase +{ + public function testSupports() + { + $loader = new GlobFileLoader(new FileLocator()); + + $this->assertTrue($loader->supports('any-path', 'glob'), '->supports() returns true if the resource has the glob type'); + $this->assertFalse($loader->supports('any-path'), '->supports() returns false if the resource is not of glob type'); + } + + public function testLoadAddsTheGlobResourceToTheContainer() + { + $loader = new GlobFileLoaderWithoutImport(new FileLocator()); + $collection = $loader->load(__DIR__.'/../Fixtures/directory/*.yml'); + + $this->assertEquals(new GlobResource(__DIR__.'/../Fixtures/directory', '/*.yml', false), $collection->getResources()[0]); + } +} + +class GlobFileLoaderWithoutImport extends GlobFileLoader +{ + public function import($resource, $type = null, $ignoreErrors = false, $sourceResource = null) + { + return new RouteCollection(); + } +} From 6ab8dd92e9c06e691769b3b23e54a5e2f273ae83 Mon Sep 17 00:00:00 2001 From: "Israel J. Carberry" Date: Thu, 1 Feb 2018 09:00:52 -0600 Subject: [PATCH 06/10] Allow remember-me factory creation when multiple user providers are configured. --- .../DependencyInjection/SecurityExtension.php | 3 +++ .../SecurityExtensionTest.php | 22 +++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/src/Symfony/Bundle/SecurityBundle/DependencyInjection/SecurityExtension.php b/src/Symfony/Bundle/SecurityBundle/DependencyInjection/SecurityExtension.php index a2be3a24be..6f43a4ce8c 100644 --- a/src/Symfony/Bundle/SecurityBundle/DependencyInjection/SecurityExtension.php +++ b/src/Symfony/Bundle/SecurityBundle/DependencyInjection/SecurityExtension.php @@ -515,6 +515,9 @@ class SecurityExtension extends Extension throw new InvalidConfigurationException(sprintf('Invalid firewall "%s": user provider "%s" not found.', $id, $firewall[$key]['provider'])); } $userProvider = $providerIds[$normalizedName]; + } elseif ('remember_me' === $key) { + // RememberMeFactory will use the firewall secret when created + $userProvider = null; } else { $userProvider = $defaultProvider ?: $this->getFirstProvider($id, $key, $providerIds); } diff --git a/src/Symfony/Bundle/SecurityBundle/Tests/DependencyInjection/SecurityExtensionTest.php b/src/Symfony/Bundle/SecurityBundle/Tests/DependencyInjection/SecurityExtensionTest.php index 7b5f6685c4..52a18d08ac 100644 --- a/src/Symfony/Bundle/SecurityBundle/Tests/DependencyInjection/SecurityExtensionTest.php +++ b/src/Symfony/Bundle/SecurityBundle/Tests/DependencyInjection/SecurityExtensionTest.php @@ -259,6 +259,28 @@ class SecurityExtensionTest extends TestCase $this->addToAssertionCount(1); } + public function testPerListenerProviderWithRememberMe() + { + $container = $this->getRawContainer(); + $container->loadFromExtension('security', array( + 'providers' => array( + 'first' => array('id' => 'foo'), + 'second' => array('id' => 'bar'), + ), + + 'firewalls' => array( + 'default' => array( + 'form_login' => array('provider' => 'second'), + 'logout_on_user_change' => true, + 'remember_me' => array('secret' => 'baz'), + ), + ), + )); + + $container->compile(); + $this->addToAssertionCount(1); + } + protected function getRawContainer() { $container = new ContainerBuilder(); From 48db494b19e3fbddeffef0b77a52b6414f5057a0 Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Sat, 3 Feb 2018 15:55:47 +0100 Subject: [PATCH 07/10] fix merge --- .../Component/CssSelector/Tests/CssSelectorConverterTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Symfony/Component/CssSelector/Tests/CssSelectorConverterTest.php b/src/Symfony/Component/CssSelector/Tests/CssSelectorConverterTest.php index a27fadfef1..a3eea7ad21 100644 --- a/src/Symfony/Component/CssSelector/Tests/CssSelectorConverterTest.php +++ b/src/Symfony/Component/CssSelector/Tests/CssSelectorConverterTest.php @@ -59,7 +59,7 @@ class CssSelectorConverterTest extends TestCase array('h1', 'h1'), array('foo|h1', 'foo:h1'), array('h1, h2, h3', 'h1 | h2 | h3'), - array('h1:nth-child(3n+1)', "*/*[name() = 'h1' and (position() - 1 >= 0 and (position() - 1) mod 3 = 0)]"), + array('h1:nth-child(3n+1)', "*/*[(name() = 'h1') and (position() - 1 >= 0 and (position() - 1) mod 3 = 0)]"), array('h1 > p', 'h1/p'), array('h1#foo', "h1[@id = 'foo']"), array('h1.foo', "h1[@class and contains(concat(' ', normalize-space(@class), ' '), ' foo ')]"), From b9def8ab5043149a8905dae143c543b6d5484e2b Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Sun, 4 Feb 2018 10:26:21 +0100 Subject: [PATCH 08/10] [travis] cache compiled php extensions --- .travis.yml | 28 +++++++++++++++++++++++----- 1 file changed, 23 insertions(+), 5 deletions(-) diff --git a/.travis.yml b/.travis.yml index c4eab34323..7f13d5b60c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -35,6 +35,7 @@ cache: directories: - .phpunit - php-$MIN_PHP + - php-ext services: mongodb @@ -102,6 +103,23 @@ before_install: echo extension = mongo.so >> $INI fi + # tpecl is a helper to compile and cache php extensions + tpecl () { + local ext_name=$1 + local ext_so=$2 + local ext_dir=$(php -r "echo ini_get('extension_dir');") + local ext_cache=~/php-ext/$(basename $ext_dir)/$ext_name + + if [[ -e $ext_cache/$ext_so ]]; then + echo extension = $ext_cache/$ext_so >> $INI + else + mkdir -p $ext_cache + echo yes | pecl install -f $ext_name && + cp $ext_dir/$ext_so $ext_cache + fi + } + export -f tpecl + # Matrix lines for intermediate PHP versions are skipped for pull requests if [[ ! $deps && ! $PHP = ${MIN_PHP%.*} && ! $PHP = hhvm* && $TRAVIS_PULL_REQUEST != false ]]; then deps=skip @@ -120,12 +138,12 @@ before_install: - | # Install extra PHP extensions if [[ ! $skip && $PHP = 5.* ]]; then - ([[ $deps ]] || tfold ext.symfony_debug 'cd src/Symfony/Component/Debug/Resources/ext && phpize && ./configure && make && echo extension = $(pwd)/modules/symfony_debug.so >> '"$INI") && - tfold ext.memcached pecl install -f memcached-2.1.0 && - tfold ext.apcu4 'echo yes | pecl install -f apcu-4.0.11' + ([[ $deps ]] || tfold ext.symfony_debug 'cd src/Symfony/Component/Debug/Resources/ext && phpize && ./configure && make && echo extension = $(pwd)/modules/symfony_debug.so >> '"$INI") + tfold ext.memcached tpecl memcached-2.1.0 memcached.so + tfold ext.apcu tpecl apcu-4.0.11 apcu.so elif [[ ! $skip && $PHP = 7.* ]]; then - tfold ext.apcu5 'echo yes | pecl install -f apcu-5.1.6' - tfold ext.mongodb pecl install -f mongodb-1.4.0RC1 + tfold ext.apcu tpecl apcu-5.1.6 apcu.so + tfold ext.mongodb tpecl mongodb-1.4.0RC1 mongodb.so fi install: From afbb8bec18bde61de24516a644a4e304c478360b Mon Sep 17 00:00:00 2001 From: Valouleloup Date: Sat, 3 Feb 2018 17:30:37 +0100 Subject: [PATCH 09/10] Fix lock strategy tests --- .../Component/Lock/Tests/Strategy/ConsensusStrategyTest.php | 2 +- .../Component/Lock/Tests/Strategy/UnanimousStrategyTest.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Symfony/Component/Lock/Tests/Strategy/ConsensusStrategyTest.php b/src/Symfony/Component/Lock/Tests/Strategy/ConsensusStrategyTest.php index 09215f9a94..87e83a9925 100644 --- a/src/Symfony/Component/Lock/Tests/Strategy/ConsensusStrategyTest.php +++ b/src/Symfony/Component/Lock/Tests/Strategy/ConsensusStrategyTest.php @@ -82,7 +82,7 @@ class ConsensusStrategyTest extends TestCase /** * @dataProvider provideIndeterminate */ - public function canBeMet($success, $failure, $total, $isMet) + public function testCanBeMet($success, $failure, $total, $isMet) { $this->assertSame($isMet, $this->strategy->canBeMet($failure, $total)); } diff --git a/src/Symfony/Component/Lock/Tests/Strategy/UnanimousStrategyTest.php b/src/Symfony/Component/Lock/Tests/Strategy/UnanimousStrategyTest.php index 76ea68a41e..beff54a685 100644 --- a/src/Symfony/Component/Lock/Tests/Strategy/UnanimousStrategyTest.php +++ b/src/Symfony/Component/Lock/Tests/Strategy/UnanimousStrategyTest.php @@ -82,7 +82,7 @@ class UnanimousStrategyTest extends TestCase /** * @dataProvider provideIndeterminate */ - public function canBeMet($success, $failure, $total, $isMet) + public function testCanBeMet($success, $failure, $total, $isMet) { $this->assertSame($isMet, $this->strategy->canBeMet($failure, $total)); } From f2d54fe694a5d04991922b151c1b5107b91e5178 Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Sun, 4 Feb 2018 14:10:03 +0100 Subject: [PATCH 10/10] fix merge --- .../SecurityBundle/DependencyInjection/SecurityExtension.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Symfony/Bundle/SecurityBundle/DependencyInjection/SecurityExtension.php b/src/Symfony/Bundle/SecurityBundle/DependencyInjection/SecurityExtension.php index b8d9fb52e5..b5d08d596e 100644 --- a/src/Symfony/Bundle/SecurityBundle/DependencyInjection/SecurityExtension.php +++ b/src/Symfony/Bundle/SecurityBundle/DependencyInjection/SecurityExtension.php @@ -412,7 +412,7 @@ class SecurityExtension extends Extension } elseif ('remember_me' === $key) { // RememberMeFactory will use the firewall secret when created $userProvider = null; - } elseif($defaultProvider) { + } elseif ($defaultProvider) { $userProvider = $defaultProvider; } else { throw new InvalidConfigurationException(sprintf('Not configuring explicitly the provider for the "%s" listener on "%s" firewall is ambiguous as there is more than one registered provider.', $key, $id));