Skip to content

Commit

Permalink
Add compatibility with the Symfony 4.4 VarExporter
Browse files Browse the repository at this point in the history
  • Loading branch information
cmodijk committed Oct 20, 2023
1 parent 38ad392 commit ceb4e7a
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/Doctrine/ORM/Query/ParserResult.php
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,9 @@ public function __unserialize(array $data): void
{
foreach (self::LEGACY_PROPERTY_MAPPING as $property => $legacyProperty) {
$this->$property = $data[sprintf("\0%s\0%s", self::class, $legacyProperty)]
?? $data[self::class][$legacyProperty]
?? $data[sprintf("\0%s\0%s", self::class, $property)]
?? $data[self::class][$property]
?? $this->$property
?? null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,13 @@
use Doctrine\Tests\OrmFunctionalTestCase;
use Generator;
use ReflectionMethod;
use Symfony\Component\VarExporter\VarExporter;

use function file_get_contents;
use function file_put_contents;
use function rtrim;
use function serialize;
use function unlink;
use function unserialize;

class ParserResultSerializationTest extends OrmFunctionalTestCase
Expand Down Expand Up @@ -61,6 +64,31 @@ public static function provideSerializedSingleSelectResults(): Generator
yield '2.15.0' => [rtrim(file_get_contents(__DIR__ . '/ParserResults/single_select_2_15_0.txt'), "\n")];
}

public function testSymfony44ProvidedData(): void
{
$sqlExecutor = $this->createMock(SingleSelectExecutor::class);
$resultSetMapping = $this->createMock(ResultSetMapping::class);

$tempFile = 'symfony_44-temp.php';

$parserResult = new ParserResult();
$parserResult->setSqlExecutor($sqlExecutor);
$parserResult->setResultSetMapping($resultSetMapping);
$parserResult->addParameterMapping('name', 0);

$exported = VarExporter::export($parserResult);
$data = file_put_contents($tempFile, '<?php return ' . $exported . ';');

$unserialized = require $tempFile;

$this->assertInstanceOf(ParserResult::class, $unserialized);
$this->assertInstanceOf(ResultSetMapping::class, $unserialized->getResultSetMapping());
$this->assertEquals(['name' => [0]], $unserialized->getParameterMappings());
$this->assertInstanceOf(SingleSelectExecutor::class, $unserialized->getSqlExecutor());

unlink($tempFile);
}

private static function parseQuery(Query $query): ParserResult
{
$r = new ReflectionMethod($query, 'parse');
Expand Down

0 comments on commit ceb4e7a

Please sign in to comment.