4
4
5
5
namespace Doctrine \Tests \ORM \Functional ;
6
6
7
+ use Closure ;
7
8
use Doctrine \ORM \Query ;
8
9
use Doctrine \ORM \Query \Exec \SingleSelectExecutor ;
9
10
use Doctrine \ORM \Query \ParserResult ;
12
13
use Generator ;
13
14
use ReflectionMethod ;
14
15
use ReflectionProperty ;
16
+ use Symfony \Component \VarExporter \Instantiator ;
17
+ use Symfony \Component \VarExporter \VarExporter ;
15
18
16
19
use function file_get_contents ;
17
20
use function rtrim ;
@@ -27,21 +30,46 @@ protected function setUp(): void
27
30
parent ::setUp ();
28
31
}
29
32
30
- public function testSerializeParserResult (): void
33
+ /**
34
+ * @param Closure(ParserResult): ParserResult $toSerializedAndBack
35
+ *
36
+ * @dataProvider provideToSerializedAndBack
37
+ */
38
+ public function testSerializeParserResult (Closure $ toSerializedAndBack ): void
31
39
{
32
40
$ query = $ this ->_em
33
41
->createQuery ('SELECT u FROM Doctrine\Tests\Models\Company\CompanyEmployee u WHERE u.name = :name ' );
34
42
35
43
$ parserResult = self ::parseQuery ($ query );
36
- $ serialized = serialize ($ parserResult );
37
- $ unserialized = unserialize ($ serialized );
44
+ $ unserialized = $ toSerializedAndBack ($ parserResult );
38
45
39
46
$ this ->assertInstanceOf (ParserResult::class, $ unserialized );
40
47
$ this ->assertInstanceOf (ResultSetMapping::class, $ unserialized ->getResultSetMapping ());
41
48
$ this ->assertEquals (['name ' => [0 ]], $ unserialized ->getParameterMappings ());
42
49
$ this ->assertInstanceOf (SingleSelectExecutor::class, $ unserialized ->getSqlExecutor ());
43
50
}
44
51
52
+ /** @return Generator<string, array{Closure(ParserResult): ParserResult}> */
53
+ public function provideToSerializedAndBack (): Generator
54
+ {
55
+ yield 'native serialization function ' => [
56
+ static function (ParserResult $ parserResult ): ParserResult {
57
+ return unserialize (serialize ($ parserResult ));
58
+ },
59
+ ];
60
+
61
+ $ instantiatorMethod = new ReflectionMethod (Instantiator::class, 'instantiate ' );
62
+ if ($ instantiatorMethod ->getReturnType () === null ) {
63
+ $ this ->markTestSkipped ('symfony/var-exporter 5.4+ is required. ' );
64
+ }
65
+
66
+ yield 'symfony/var-exporter ' => [
67
+ static function (ParserResult $ parserResult ): ParserResult {
68
+ return eval ('return ' . VarExporter::export ($ parserResult ) . '; ' );
69
+ },
70
+ ];
71
+ }
72
+
45
73
public function testItSerializesParserResultWithAForwardCompatibleFormat (): void
46
74
{
47
75
$ query = $ this ->_em
0 commit comments