2222
2323class ManagerRegistryTest extends TestCase
2424{
25- public static function setUpBeforeClass (): void
25+ public function testResetService ()
2626 {
2727 $ container = new ContainerBuilder ();
2828
@@ -32,10 +32,7 @@ public static function setUpBeforeClass(): void
3232
3333 $ dumper = new PhpDumper ($ container );
3434 eval ('?> ' .$ dumper ->dump (['class ' => 'LazyServiceDoctrineBridgeContainer ' ]));
35- }
3635
37- public function testResetService ()
38- {
3936 $ container = new \LazyServiceDoctrineBridgeContainer ();
4037
4138 $ registry = new TestManagerRegistry ('name ' , [], ['defaultManager ' => 'foo ' ], 'defaultConnection ' , 'defaultManager ' , 'proxyInterfaceName ' );
@@ -52,6 +49,63 @@ public function testResetService()
5249 $ this ->assertFalse (isset ($ foo ->bar ));
5350 }
5451
52+ /**
53+ * @requires PHP 8.4
54+ *
55+ * @dataProvider provideResetServiceWithNativeLazyObjectsCases
56+ */
57+ public function testResetServiceWithNativeLazyObjects (string $ class )
58+ {
59+ $ container = new $ class ();
60+
61+ $ registry = new TestManagerRegistry (
62+ 'irrelevant ' ,
63+ [],
64+ ['defaultManager ' => 'foo ' ],
65+ 'irrelevant ' ,
66+ 'defaultManager ' ,
67+ 'irrelevant ' ,
68+ );
69+ $ registry ->setTestContainer ($ container );
70+
71+ $ foo = $ container ->get ('foo ' );
72+ self ::assertSame (DummyManager::class, $ foo ::class);
73+
74+ $ foo ->bar = 123 ;
75+ self ::assertTrue (isset ($ foo ->bar ));
76+
77+ $ registry ->resetManager ();
78+
79+ self ::assertSame ($ foo , $ container ->get ('foo ' ));
80+ self ::assertSame (DummyManager::class, $ foo ::class);
81+ self ::assertFalse (isset ($ foo ->bar ));
82+ }
83+
84+ public static function provideResetServiceWithNativeLazyObjectsCases (): iterable
85+ {
86+ $ container = new ContainerBuilder ();
87+
88+ $ container ->register ('foo ' , DummyManager::class)->setPublic (true );
89+ $ container ->getDefinition ('foo ' )->setLazy (true );
90+ $ container ->compile ();
91+
92+ $ dumper = new PhpDumper ($ container );
93+
94+ eval ('?> ' .$ dumper ->dump (['class ' => 'NativeLazyServiceDoctrineBridgeContainer ' ]));
95+
96+ yield ['NativeLazyServiceDoctrineBridgeContainer ' ];
97+
98+ $ dumps = $ dumper ->dump (['class ' => 'NativeLazyServiceDoctrineBridgeContainerAsFiles ' , 'as_files ' => true ]);
99+
100+ $ lastDump = array_pop ($ dumps );
101+ foreach (array_reverse ($ dumps ) as $ dump ) {
102+ eval ('?> ' .$ dump );
103+ }
104+ eval ('?> ' .$ lastDump );
105+
106+ yield ['NativeLazyServiceDoctrineBridgeContainerAsFiles ' ];
107+ }
108+
55109 /**
56110 * When performing an entity manager lazy service reset, the reset operations may re-use the container
57111 * to create a "fresh" service: when doing so, it can happen that the "fresh" service is itself a proxy.
0 commit comments