Merge branch '3.3' into 3.4

* 3.3:
  [TwigBundle] Add Doctrine Cache to dev dependencies
  [Yaml] Fix linting yaml with constants as keys
  [Routing] Revert the change in [#b42018] with respect to Routing/Route.php
This commit is contained in:
Nicolas Grekas 2017-06-14 09:34:46 +02:00
commit c8cf42bcbb
6 changed files with 79 additions and 6 deletions

View File

@ -116,11 +116,7 @@ class Route implements \Serializable
*/
public function unserialize($serialized)
{
if (\PHP_VERSION_ID >= 70000) {
$data = unserialize($serialized, array('allowed_classes' => array(CompiledRoute::class)));
} else {
$data = unserialize($serialized);
}
$data = unserialize($serialized);
$this->path = $data['path'];
$this->host = $data['host'];
$this->defaults = $data['defaults'];

View File

@ -0,0 +1,18 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* 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
{
}

View File

@ -0,0 +1,26 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* 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());
}
}

View File

@ -220,6 +220,24 @@ class RouteTest extends TestCase
$this->assertNotSame($route, $unserialized);
}
/**
* 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()
{
$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);
try {
$unserialized = unserialize($serialized);
$this->assertInstanceOf('\Symfony\Component\Routing\Tests\Fixtures\CustomCompiledRoute', $unserialized->compile(), 'the unserialized route compiled successfully');
} catch (\Exception $e) {
$this->fail('unserializing a route which uses a custom compiled route class');
}
}
/**
* 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

View File

@ -18,6 +18,7 @@ use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Style\SymfonyStyle;
use Symfony\Component\Yaml\Exception\ParseException;
use Symfony\Component\Yaml\Parser;
use Symfony\Component\Yaml\Yaml;
/**
* Validates YAML files syntax and outputs encountered errors.
@ -111,7 +112,7 @@ EOF
});
try {
$this->getParser()->parse($content);
$this->getParser()->parse($content, Yaml::PARSE_CONSTANT);
} catch (ParseException $e) {
return array('file' => $file, 'valid' => false, 'message' => $e->getMessage());
} finally {

View File

@ -51,6 +51,15 @@ bar';
$this->assertContains('Unable to parse at line 3 (near "bar").', trim($tester->getDisplay()));
}
public function testConstantAsKey()
{
$yaml = <<<YAML
!php/const:Symfony\Component\Yaml\Tests\Command\Foo::TEST: bar
YAML;
$ret = $this->createCommandTester()->execute(array('filename' => $this->createFile($yaml)), array('verbosity' => OutputInterface::VERBOSITY_VERBOSE, 'decorated' => false));
$this->assertSame(0, $ret, 'lint:yaml exits with code 0 in case of success');
}
/**
* @expectedException \RuntimeException
*/
@ -105,3 +114,8 @@ bar';
rmdir(sys_get_temp_dir().'/framework-yml-lint-test');
}
}
class Foo
{
const TEST = 'foo';
}