From 399ec440ce20526c71193fe319ccfcb4679a0423 Mon Sep 17 00:00:00 2001 From: Dan Wilga Date: Fri, 9 Jun 2017 15:14:01 -0400 Subject: [PATCH 1/5] Revert the change in b4201810 with respect to Routing/Route.php because it breaks BC. Refers to https://github.com/symfony/symfony/pull/21090 and https://github.com/symfony/symfony/issues/23109 --- src/Symfony/Component/Routing/Route.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Symfony/Component/Routing/Route.php b/src/Symfony/Component/Routing/Route.php index 6d1b1fbec9f8f..69a7cade10c33 100644 --- a/src/Symfony/Component/Routing/Route.php +++ b/src/Symfony/Component/Routing/Route.php @@ -116,7 +116,7 @@ public function serialize() */ public function unserialize($serialized) { - $data = unserialize($serialized, array('allowed_classes' => array(CompiledRoute::class))); + $data = unserialize($serialized); $this->path = $data['path']; $this->host = $data['host']; $this->defaults = $data['defaults']; From 6624cff9254d2b5c97d7ab5884807df7007e2060 Mon Sep 17 00:00:00 2001 From: Dan Wilga Date: Mon, 12 Jun 2017 13:29:34 -0400 Subject: [PATCH 2/5] Add a test for [#399ec4] --- src/Symfony/Component/Routing/Tests/RouteTest.php | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/Symfony/Component/Routing/Tests/RouteTest.php b/src/Symfony/Component/Routing/Tests/RouteTest.php index b65dfb54085c1..0fb251aaccbde 100644 --- a/src/Symfony/Component/Routing/Tests/RouteTest.php +++ b/src/Symfony/Component/Routing/Tests/RouteTest.php @@ -220,6 +220,21 @@ public function testSerializeWhenCompiled() $this->assertNotSame($route, $unserialized); } + /** + * Tests that the compiled version does not fail when the Route refers to + * arbitrary classes. + */ + public function testSerializeWhenCompiledWithClass() + { + $testClass = new \Symfony\Component\Cache\CacheItem(); + $route = new Route('/', array(), array(), array('foo' => $testClass)); + + $serialized = serialize($route); + $unserialized = unserialize($serialized); + + $this->assertInstanceOf(get_class($testClass), $unserialized->getOption('foo')); + } + /** * Tests that the serialized representation of a route in one symfony version * also works in later symfony versions, i.e. the unserialized route is in the From 94976b91652784f1a296f22068fbbfd878633bdf Mon Sep 17 00:00:00 2001 From: Dan Wilga Date: Tue, 13 Jun 2017 08:58:34 -0400 Subject: [PATCH 3/5] Revise the routing unserialization test to be more specific --- .../Tests/Fixtures/CustomCompiledRoute.php | 17 +++++++++++++ .../Tests/Fixtures/CustomRouteCompiler.php | 24 +++++++++++++++++++ .../Component/Routing/Tests/RouteTest.php | 18 ++++++++------ 3 files changed, 52 insertions(+), 7 deletions(-) create mode 100644 src/Symfony/Component/Routing/Tests/Fixtures/CustomCompiledRoute.php create mode 100644 src/Symfony/Component/Routing/Tests/Fixtures/CustomRouteCompiler.php diff --git a/src/Symfony/Component/Routing/Tests/Fixtures/CustomCompiledRoute.php b/src/Symfony/Component/Routing/Tests/Fixtures/CustomCompiledRoute.php new file mode 100644 index 0000000000000..07033c448ffdd --- /dev/null +++ b/src/Symfony/Component/Routing/Tests/Fixtures/CustomCompiledRoute.php @@ -0,0 +1,17 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\Routing\Tests\Fixtures; + +use Symfony\Component\Routing\CompiledRoute; + +class CustomCompiledRoute extends CompiledRoute { +} diff --git a/src/Symfony/Component/Routing/Tests/Fixtures/CustomRouteCompiler.php b/src/Symfony/Component/Routing/Tests/Fixtures/CustomRouteCompiler.php new file mode 100644 index 0000000000000..368c3dd6c1ffe --- /dev/null +++ b/src/Symfony/Component/Routing/Tests/Fixtures/CustomRouteCompiler.php @@ -0,0 +1,24 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\Routing\Tests\Fixtures; + +use Symfony\Component\Routing\Route; +use Symfony\Component\Routing\RouteCompiler; + +class CustomRouteCompiler extends RouteCompiler { + /** + * {@inheritdoc} + */ + public static function compile(Route $route) { + return new CustomCompiledRoute('', '', array(), array()); + } +} \ No newline at end of file diff --git a/src/Symfony/Component/Routing/Tests/RouteTest.php b/src/Symfony/Component/Routing/Tests/RouteTest.php index 0fb251aaccbde..f385cb63ff645 100644 --- a/src/Symfony/Component/Routing/Tests/RouteTest.php +++ b/src/Symfony/Component/Routing/Tests/RouteTest.php @@ -221,18 +221,22 @@ public function testSerializeWhenCompiled() } /** - * Tests that the compiled version does not fail when the Route refers to - * arbitrary classes. + * Tests that unserialization does not fail when the compiled Route is of a + * class other than CompiledRoute, such as a subclass of it. */ public function testSerializeWhenCompiledWithClass() { - $testClass = new \Symfony\Component\Cache\CacheItem(); - $route = new Route('/', array(), array(), array('foo' => $testClass)); + $route = new Route('/', array(), array(), array('compiler_class' => '\Symfony\Component\Routing\Tests\Fixtures\CustomRouteCompiler')); + $this->assertInstanceOf('\Symfony\Component\Routing\Tests\Fixtures\CustomCompiledRoute', $route->compile(), '->compile() returned a proper route'); $serialized = serialize($route); - $unserialized = unserialize($serialized); - - $this->assertInstanceOf(get_class($testClass), $unserialized->getOption('foo')); + try { + $unserialized = unserialize($serialized); + $this->assertInstanceOf('\Symfony\Component\Routing\Tests\Fixtures\CustomCompiledRoute', $unserialized->compile(), 'the unserialized route compiled successfully'); + } + catch (\Exception $except) { + $this->fail('unserializing a route which uses a custom compiled route class'); + } } /** From d7b108856aa5d2f12dd2ca603ce1d8bc9f04a3fe Mon Sep 17 00:00:00 2001 From: Dan Wilga Date: Tue, 13 Jun 2017 09:09:21 -0400 Subject: [PATCH 4/5] Apply coding standards to routing test --- .../Routing/Tests/Fixtures/CustomCompiledRoute.php | 3 ++- .../Routing/Tests/Fixtures/CustomRouteCompiler.php | 12 +++++++----- src/Symfony/Component/Routing/Tests/RouteTest.php | 9 ++++----- 3 files changed, 13 insertions(+), 11 deletions(-) diff --git a/src/Symfony/Component/Routing/Tests/Fixtures/CustomCompiledRoute.php b/src/Symfony/Component/Routing/Tests/Fixtures/CustomCompiledRoute.php index 07033c448ffdd..0f6e198c923d9 100644 --- a/src/Symfony/Component/Routing/Tests/Fixtures/CustomCompiledRoute.php +++ b/src/Symfony/Component/Routing/Tests/Fixtures/CustomCompiledRoute.php @@ -13,5 +13,6 @@ use Symfony\Component\Routing\CompiledRoute; -class CustomCompiledRoute extends CompiledRoute { +class CustomCompiledRoute extends CompiledRoute +{ } diff --git a/src/Symfony/Component/Routing/Tests/Fixtures/CustomRouteCompiler.php b/src/Symfony/Component/Routing/Tests/Fixtures/CustomRouteCompiler.php index 368c3dd6c1ffe..256096e969b75 100644 --- a/src/Symfony/Component/Routing/Tests/Fixtures/CustomRouteCompiler.php +++ b/src/Symfony/Component/Routing/Tests/Fixtures/CustomRouteCompiler.php @@ -14,11 +14,13 @@ use Symfony\Component\Routing\Route; use Symfony\Component\Routing\RouteCompiler; -class CustomRouteCompiler extends RouteCompiler { - /** +class CustomRouteCompiler extends RouteCompiler +{ + /** * {@inheritdoc} */ - public static function compile(Route $route) { - return new CustomCompiledRoute('', '', array(), array()); + public static function compile(Route $route) + { + return new CustomCompiledRoute('', '', array(), array()); } -} \ No newline at end of file +} diff --git a/src/Symfony/Component/Routing/Tests/RouteTest.php b/src/Symfony/Component/Routing/Tests/RouteTest.php index f385cb63ff645..2f8f8bf782555 100644 --- a/src/Symfony/Component/Routing/Tests/RouteTest.php +++ b/src/Symfony/Component/Routing/Tests/RouteTest.php @@ -231,11 +231,10 @@ public function testSerializeWhenCompiledWithClass() $serialized = serialize($route); try { - $unserialized = unserialize($serialized); - $this->assertInstanceOf('\Symfony\Component\Routing\Tests\Fixtures\CustomCompiledRoute', $unserialized->compile(), 'the unserialized route compiled successfully'); - } - catch (\Exception $except) { - $this->fail('unserializing a route which uses a custom compiled route class'); + $unserialized = unserialize($serialized); + $this->assertInstanceOf('\Symfony\Component\Routing\Tests\Fixtures\CustomCompiledRoute', $unserialized->compile(), 'the unserialized route compiled successfully'); + } catch (\Exception $except) { + $this->fail('unserializing a route which uses a custom compiled route class'); } } From f3f46ac45bd540f5a9ada566f762cde53e90ead2 Mon Sep 17 00:00:00 2001 From: Dan Wilga Date: Tue, 13 Jun 2017 12:56:25 -0400 Subject: [PATCH 5/5] More coding standards fixes for routing test --- .../Routing/Tests/Fixtures/CustomRouteCompiler.php | 12 ++++++------ src/Symfony/Component/Routing/Tests/RouteTest.php | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/Symfony/Component/Routing/Tests/Fixtures/CustomRouteCompiler.php b/src/Symfony/Component/Routing/Tests/Fixtures/CustomRouteCompiler.php index 256096e969b75..c2e2afd9afcd9 100644 --- a/src/Symfony/Component/Routing/Tests/Fixtures/CustomRouteCompiler.php +++ b/src/Symfony/Component/Routing/Tests/Fixtures/CustomRouteCompiler.php @@ -17,10 +17,10 @@ class CustomRouteCompiler extends RouteCompiler { /** - * {@inheritdoc} - */ - public static function compile(Route $route) - { - return new CustomCompiledRoute('', '', array(), array()); - } + * {@inheritdoc} + */ + public static function compile(Route $route) + { + return new CustomCompiledRoute('', '', array(), array()); + } } diff --git a/src/Symfony/Component/Routing/Tests/RouteTest.php b/src/Symfony/Component/Routing/Tests/RouteTest.php index 2f8f8bf782555..ff7e320c5fc95 100644 --- a/src/Symfony/Component/Routing/Tests/RouteTest.php +++ b/src/Symfony/Component/Routing/Tests/RouteTest.php @@ -233,7 +233,7 @@ public function testSerializeWhenCompiledWithClass() try { $unserialized = unserialize($serialized); $this->assertInstanceOf('\Symfony\Component\Routing\Tests\Fixtures\CustomCompiledRoute', $unserialized->compile(), 'the unserialized route compiled successfully'); - } catch (\Exception $except) { + } catch (\Exception $e) { $this->fail('unserializing a route which uses a custom compiled route class'); } }