From 30a4e8f87311c655a7add95cfae4aeea3afa955c Mon Sep 17 00:00:00 2001 From: Fruty Date: Wed, 24 Jan 2018 16:08:40 +0200 Subject: [PATCH 1/5] Added normalized env getter in kernel for correct container compile. --- src/Symfony/Component/HttpKernel/Kernel.php | 10 ++++- .../Component/HttpKernel/Tests/KernelTest.php | 38 +++++++++++++++++++ 2 files changed, 47 insertions(+), 1 deletion(-) diff --git a/src/Symfony/Component/HttpKernel/Kernel.php b/src/Symfony/Component/HttpKernel/Kernel.php index 18334092a9218..1ff93a3f46f81 100644 --- a/src/Symfony/Component/HttpKernel/Kernel.php +++ b/src/Symfony/Component/HttpKernel/Kernel.php @@ -425,7 +425,15 @@ protected function build(ContainerBuilder $container) */ protected function getContainerClass() { - return $this->name.ucfirst($this->environment).($this->debug ? 'Debug' : '').'ProjectContainer'; + return $this->name.ucfirst($this->getNormalizedEnv()).($this->debug ? 'Debug' : '').'ProjectContainer'; + } + + /** + * @return null|string|string[] + */ + protected function getNormalizedEnv() + { + return preg_replace('/[^\p{L}\p{Nd}]+/im', null, $this->environment); } /** diff --git a/src/Symfony/Component/HttpKernel/Tests/KernelTest.php b/src/Symfony/Component/HttpKernel/Tests/KernelTest.php index f1a44de87737d..cbb1f4219a9f7 100644 --- a/src/Symfony/Component/HttpKernel/Tests/KernelTest.php +++ b/src/Symfony/Component/HttpKernel/Tests/KernelTest.php @@ -523,6 +523,44 @@ public function testProjectDirExtension() $this->assertSame('foo', $kernel->getContainer()->getParameter('kernel.project_dir')); } + /** + * @param $env + * @param $expected + * @dataProvider envDataProvider + */ + public function testKernelNormalizedEnv($env, $expected) + { + $kernel = new class($env, true) extends Kernel { + public function registerContainerConfiguration(LoaderInterface $loader) + { + // TODO: Implement registerContainerConfiguration() method. + } + public function registerBundles() + { + // TODO: Implement registerBundles() method. + } + }; + + $reflection = new \ReflectionObject($kernel); + $normalizeEnvMethod = $reflection->getMethod('getNormalizedEnv'); + $normalizeEnvMethod->setAccessible(true); + $normalizedEnv = $normalizeEnvMethod->invoke($kernel); + + $this->assertSame($expected, $normalizedEnv); + } + + /** + * @return array + */ + public function envDataProvider() + { + return [ + ['dev-server', 'devserver'], + ['local', 'local'], + ['env_#8', 'env8'] + ]; + } + public function testKernelReset() { (new Filesystem())->remove(__DIR__.'/Fixtures/cache'); From d84ff0e9806a1949ff6c7c8ad4aa12fdfa5e6edc Mon Sep 17 00:00:00 2001 From: Fruty Date: Wed, 24 Jan 2018 16:38:09 +0200 Subject: [PATCH 2/5] Fixed fabbot.io style checks. --- src/Symfony/Component/HttpKernel/Tests/KernelTest.php | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/Symfony/Component/HttpKernel/Tests/KernelTest.php b/src/Symfony/Component/HttpKernel/Tests/KernelTest.php index cbb1f4219a9f7..ae4338359ae40 100644 --- a/src/Symfony/Component/HttpKernel/Tests/KernelTest.php +++ b/src/Symfony/Component/HttpKernel/Tests/KernelTest.php @@ -535,6 +535,7 @@ public function registerContainerConfiguration(LoaderInterface $loader) { // TODO: Implement registerContainerConfiguration() method. } + public function registerBundles() { // TODO: Implement registerBundles() method. @@ -554,11 +555,11 @@ public function registerBundles() */ public function envDataProvider() { - return [ - ['dev-server', 'devserver'], - ['local', 'local'], - ['env_#8', 'env8'] - ]; + return array( + array('dev-server', 'devserver'), + array('local', 'local'), + array('env_#8', 'env8') + ); } public function testKernelReset() From 9efb70872ab42e38629811ee215651bee11d2d9b Mon Sep 17 00:00:00 2001 From: Fruty Date: Wed, 24 Jan 2018 16:38:51 +0200 Subject: [PATCH 3/5] Fixed fabbot.io style checks. --- src/Symfony/Component/HttpKernel/Tests/KernelTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Symfony/Component/HttpKernel/Tests/KernelTest.php b/src/Symfony/Component/HttpKernel/Tests/KernelTest.php index ae4338359ae40..07ab0d7384366 100644 --- a/src/Symfony/Component/HttpKernel/Tests/KernelTest.php +++ b/src/Symfony/Component/HttpKernel/Tests/KernelTest.php @@ -558,7 +558,7 @@ public function envDataProvider() return array( array('dev-server', 'devserver'), array('local', 'local'), - array('env_#8', 'env8') + array('env_#8', 'env8'), ); } From 8f33598389f69854cb2f876e9267c29673099e89 Mon Sep 17 00:00:00 2001 From: Fruty Date: Tue, 30 Jan 2018 11:09:57 +0200 Subject: [PATCH 4/5] Normalized container classname in kernel. --- src/Symfony/Component/HttpKernel/Kernel.php | 10 +-------- .../Component/HttpKernel/Tests/KernelTest.php | 21 +++++++++---------- 2 files changed, 11 insertions(+), 20 deletions(-) diff --git a/src/Symfony/Component/HttpKernel/Kernel.php b/src/Symfony/Component/HttpKernel/Kernel.php index 1ff93a3f46f81..548d02871505d 100644 --- a/src/Symfony/Component/HttpKernel/Kernel.php +++ b/src/Symfony/Component/HttpKernel/Kernel.php @@ -425,15 +425,7 @@ protected function build(ContainerBuilder $container) */ protected function getContainerClass() { - return $this->name.ucfirst($this->getNormalizedEnv()).($this->debug ? 'Debug' : '').'ProjectContainer'; - } - - /** - * @return null|string|string[] - */ - protected function getNormalizedEnv() - { - return preg_replace('/[^\p{L}\p{Nd}]+/im', null, $this->environment); + return $this->name.ucfirst(preg_replace('/[^a-zA-Z0-9_\x7f-\xff]/', '', $this->environment)).($this->debug ? 'Debug' : '').'ProjectContainer'; } /** diff --git a/src/Symfony/Component/HttpKernel/Tests/KernelTest.php b/src/Symfony/Component/HttpKernel/Tests/KernelTest.php index 07ab0d7384366..a483fa50a0da9 100644 --- a/src/Symfony/Component/HttpKernel/Tests/KernelTest.php +++ b/src/Symfony/Component/HttpKernel/Tests/KernelTest.php @@ -526,9 +526,9 @@ public function testProjectDirExtension() /** * @param $env * @param $expected - * @dataProvider envDataProvider + * @dataProvider envAndContainerClassDataProvider */ - public function testKernelNormalizedEnv($env, $expected) + public function testContainerClassNormalization($env, $expected) { $kernel = new class($env, true) extends Kernel { public function registerContainerConfiguration(LoaderInterface $loader) @@ -542,23 +542,22 @@ public function registerBundles() } }; - $reflection = new \ReflectionObject($kernel); - $normalizeEnvMethod = $reflection->getMethod('getNormalizedEnv'); - $normalizeEnvMethod->setAccessible(true); - $normalizedEnv = $normalizeEnvMethod->invoke($kernel); + $containerClassMethod = (new \ReflectionObject($kernel))->getMethod('getContainerClass'); + $containerClassMethod->setAccessible(true); + $class = $containerClassMethod->invoke($kernel); - $this->assertSame($expected, $normalizedEnv); + $this->assertSame($expected, $class); } /** * @return array */ - public function envDataProvider() + public function envAndContainerClassDataProvider() { return array( - array('dev-server', 'devserver'), - array('local', 'local'), - array('env_#8', 'env8'), + array('dev-server', 'TestsDevserverDebugProjectContainer'), + array('local', 'TestsLocalDebugProjectContainer'), + array('env_#8---*1', 'TestsEnv_81DebugProjectContainer'), ); } From 5cab56b054c308d6595d18c2da968dc4e543a016 Mon Sep 17 00:00:00 2001 From: Fruty Date: Fri, 2 Feb 2018 15:58:32 +0200 Subject: [PATCH 5/5] Changed tests for container class normalization to support php5.3. --- .../Component/HttpKernel/Tests/KernelTest.php | 24 +++++-------------- 1 file changed, 6 insertions(+), 18 deletions(-) diff --git a/src/Symfony/Component/HttpKernel/Tests/KernelTest.php b/src/Symfony/Component/HttpKernel/Tests/KernelTest.php index a483fa50a0da9..620c74d27fabb 100644 --- a/src/Symfony/Component/HttpKernel/Tests/KernelTest.php +++ b/src/Symfony/Component/HttpKernel/Tests/KernelTest.php @@ -524,23 +524,11 @@ public function testProjectDirExtension() } /** - * @param $env - * @param $expected - * @dataProvider envAndContainerClassDataProvider + * @dataProvider envAndContainerClassDataProviderForCustomProjectDirKernel */ public function testContainerClassNormalization($env, $expected) { - $kernel = new class($env, true) extends Kernel { - public function registerContainerConfiguration(LoaderInterface $loader) - { - // TODO: Implement registerContainerConfiguration() method. - } - - public function registerBundles() - { - // TODO: Implement registerBundles() method. - } - }; + $kernel = new CustomProjectDirKernel(null, null, $env); $containerClassMethod = (new \ReflectionObject($kernel))->getMethod('getContainerClass'); $containerClassMethod->setAccessible(true); @@ -552,12 +540,12 @@ public function registerBundles() /** * @return array */ - public function envAndContainerClassDataProvider() + public function envAndContainerClassDataProviderForCustomProjectDirKernel() { return array( - array('dev-server', 'TestsDevserverDebugProjectContainer'), - array('local', 'TestsLocalDebugProjectContainer'), - array('env_#8---*1', 'TestsEnv_81DebugProjectContainer'), + array('dev-server', 'FixturesDevserverDebugProjectContainer'), + array('local', 'FixturesLocalDebugProjectContainer'), + array('env_#8---*1', 'FixturesEnv_81DebugProjectContainer'), ); }