@@ -160,6 +160,50 @@ class_exists(\Symfony\Component\VarExporter\Internal\LazyObjectState::class);
160
160
$ this ->assertSame ($ expected , ProxyHelper::generateLazyProxy (null , [new \ReflectionClass (TestForProxyHelperInterface1::class), new \ReflectionClass (TestForProxyHelperInterface2::class)]));
161
161
}
162
162
163
+ /**
164
+ * @dataProvider classWithUnserializeMagicMethodProvider
165
+ */
166
+ public function testGenerateLazyProxyForClassWithUnserializeMagicMethod (object $ obj , string $ expected )
167
+ {
168
+ $ this ->assertStringContainsString ($ expected , ProxyHelper::generateLazyProxy (new \ReflectionClass ($ obj ::class)));
169
+ }
170
+
171
+ public static function classWithUnserializeMagicMethodProvider (): iterable
172
+ {
173
+ yield 'not type hinted __unserialize method ' => [new class () {
174
+ public function __unserialize ($ array )
175
+ {
176
+ }
177
+ }, <<<'EOPHP'
178
+ implements \Symfony\Component\VarExporter\LazyObjectInterface
179
+ {
180
+ use \Symfony\Component\VarExporter\LazyProxyTrait {
181
+ __unserialize as private __doUnserialize;
182
+ }
183
+
184
+ private const LAZY_OBJECT_PROPERTY_SCOPES = [];
185
+
186
+ public function __unserialize($data): void
187
+ {
188
+ $this->__doUnserialize($data);
189
+ }
190
+ }
191
+ EOPHP];
192
+
193
+ yield 'type hinted __unserialize method' => [new class() {
194
+ public function __unserialize(array $array)
195
+ {
196
+ }
197
+ }, <<<'EOPHP'
198
+ implements \Symfony\Component\VarExporter\LazyObjectInterface
199
+ {
200
+ use \Symfony\Component\VarExporter\LazyProxyTrait;
201
+
202
+ private const LAZY_OBJECT_PROPERTY_SCOPES = [];
203
+ }
204
+ EOPHP];
205
+ }
206
+
163
207
public function testAttributes()
164
208
{
165
209
$expected = <<<'EOPHP'
@@ -182,6 +226,7 @@ public function foo(#[\SensitiveParameter, AnotherAttribute] $a): int
182
226
{
183
227
}
184
228
});
229
+
185
230
$ this ->assertStringContainsString ($ expected , ProxyHelper::generateLazyProxy ($ class ));
186
231
}
187
232
0 commit comments