Skip to content

Commit 8ac169c

Browse files
weaverryannicolas-grekas
authored andcommitted
Failing test case for complex near-circular situation + lazy
1 parent ade939f commit 8ac169c

File tree

5 files changed

+193
-1
lines changed

5 files changed

+193
-1
lines changed

Tests/ContainerBuilderTest.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1423,6 +1423,13 @@ public function testAlmostCircular($visibility)
14231423
$this->assertEquals((object) ['bar6' => (object) []], $foo6);
14241424

14251425
$this->assertInstanceOf(\stdClass::class, $container->get('root'));
1426+
1427+
$manager3 = $container->get('manager3');
1428+
$listener3 = $container->get('listener3');
1429+
$this->assertSame($manager3, $listener3->manager, 'Both should identically be the manager3 service');
1430+
1431+
$listener4 = $container->get('listener4');
1432+
$this->assertInstanceOf('stdClass', $listener4);
14261433
}
14271434

14281435
public function provideAlmostCircular()

Tests/Dumper/PhpDumperTest.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -842,6 +842,13 @@ public function testAlmostCircular($visibility)
842842
$this->assertEquals((object) ['bar6' => (object) []], $foo6);
843843

844844
$this->assertInstanceOf(\stdClass::class, $container->get('root'));
845+
846+
$manager3 = $container->get('manager3');
847+
$listener3 = $container->get('listener3');
848+
$this->assertSame($manager3, $listener3->manager);
849+
850+
$listener4 = $container->get('listener4');
851+
$this->assertInstanceOf('stdClass', $listener4);
845852
}
846853

847854
public function provideAlmostCircular()

Tests/Fixtures/containers/container_almost_circular.php

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
use Symfony\Component\DependencyInjection\ContainerBuilder;
44
use Symfony\Component\DependencyInjection\Definition;
5-
use Symfony\Component\DependencyInjection\Dumper\PhpDumper;
65
use Symfony\Component\DependencyInjection\Reference;
76
use Symfony\Component\DependencyInjection\Tests\Fixtures\FooForCircularWithAddCalls;
87

@@ -102,6 +101,35 @@
102101
$container->register('subscriber2', 'stdClass')->setPublic(false)
103102
->addArgument(new Reference('manager2'));
104103

104+
// doctrine-like event system with listener
105+
106+
$container->register('manager3', 'stdClass')
107+
->setLazy(true)
108+
->setPublic(true)
109+
->addArgument(new Reference('connection3'));
110+
111+
$container->register('connection3', 'stdClass')
112+
->setPublic($public)
113+
->setProperty('listener', [new Reference('listener3')]);
114+
115+
$container->register('listener3', 'stdClass')
116+
->setPublic(true)
117+
->setProperty('manager', new Reference('manager3'));
118+
119+
// doctrine-like event system with small differences
120+
121+
$container->register('manager4', 'stdClass')
122+
->setLazy(true)
123+
->addArgument(new Reference('connection4'));
124+
125+
$container->register('connection4', 'stdClass')
126+
->setPublic($public)
127+
->setProperty('listener', [new Reference('listener4')]);
128+
129+
$container->register('listener4', 'stdClass')
130+
->setPublic(true)
131+
->addArgument(new Reference('manager4'));
132+
105133
// private service involved in a loop
106134

107135
$container->register('foo6', 'stdClass')

Tests/Fixtures/php/services_almost_circular_private.php

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,13 @@ public function __construct()
3939
'level4' => 'getLevel4Service',
4040
'level5' => 'getLevel5Service',
4141
'level6' => 'getLevel6Service',
42+
'listener3' => 'getListener3Service',
43+
'listener4' => 'getListener4Service',
4244
'logger' => 'getLoggerService',
4345
'manager' => 'getManagerService',
4446
'manager2' => 'getManager2Service',
47+
'manager3' => 'getManager3Service',
48+
'manager4' => 'getManager4Service',
4549
'multiuse1' => 'getMultiuse1Service',
4650
'root' => 'getRootService',
4751
'subscriber' => 'getSubscriberService',
@@ -53,6 +57,7 @@ public function __construct()
5357
'level4' => true,
5458
'level5' => true,
5559
'level6' => true,
60+
'manager4' => true,
5661
'multiuse1' => true,
5762
];
5863

@@ -69,6 +74,8 @@ public function getRemovedIds()
6974
'bar6' => true,
7075
'config' => true,
7176
'config2' => true,
77+
'connection3' => true,
78+
'connection4' => true,
7279
'dispatcher' => true,
7380
'dispatcher2' => true,
7481
'foo4' => true,
@@ -81,6 +88,7 @@ public function getRemovedIds()
8188
'level5' => true,
8289
'level6' => true,
8390
'logger2' => true,
91+
'manager4' => true,
8492
'multiuse1' => true,
8593
'subscriber2' => true,
8694
];
@@ -272,6 +280,36 @@ protected function getFoobar4Service()
272280
return $instance;
273281
}
274282

283+
/**
284+
* Gets the public 'listener3' shared service.
285+
*
286+
* @return \stdClass
287+
*/
288+
protected function getListener3Service()
289+
{
290+
$this->services['listener3'] = $instance = new \stdClass();
291+
292+
$instance->manager = ${($_ = isset($this->services['manager3']) ? $this->services['manager3'] : $this->getManager3Service()) && false ?: '_'};
293+
294+
return $instance;
295+
}
296+
297+
/**
298+
* Gets the public 'listener4' shared service.
299+
*
300+
* @return \stdClass
301+
*/
302+
protected function getListener4Service()
303+
{
304+
$a = ${($_ = isset($this->services['manager4']) ? $this->services['manager4'] : $this->getManager4Service()) && false ?: '_'};
305+
306+
if (isset($this->services['listener4'])) {
307+
return $this->services['listener4'];
308+
}
309+
310+
return $this->services['listener4'] = new \stdClass($a);
311+
}
312+
275313
/**
276314
* Gets the public 'logger' shared service.
277315
*
@@ -324,6 +362,19 @@ protected function getManager2Service()
324362
return $this->services['manager2'] = new \stdClass($a);
325363
}
326364

365+
/**
366+
* Gets the public 'manager3' shared service.
367+
*
368+
* @return \stdClass
369+
*/
370+
protected function getManager3Service($lazyLoad = true)
371+
{
372+
$a = new \stdClass();
373+
$a->listener = [0 => ${($_ = isset($this->services['listener3']) ? $this->services['listener3'] : $this->getListener3Service()) && false ?: '_'}];
374+
375+
return $this->services['manager3'] = new \stdClass($a);
376+
}
377+
327378
/**
328379
* Gets the public 'root' shared service.
329380
*
@@ -430,6 +481,19 @@ protected function getLevel6Service()
430481
return $instance;
431482
}
432483

484+
/**
485+
* Gets the private 'manager4' shared service.
486+
*
487+
* @return \stdClass
488+
*/
489+
protected function getManager4Service($lazyLoad = true)
490+
{
491+
$a = new \stdClass();
492+
$a->listener = [0 => ${($_ = isset($this->services['listener4']) ? $this->services['listener4'] : $this->getListener4Service()) && false ?: '_'}];
493+
494+
return $this->services['manager4'] = new \stdClass($a);
495+
}
496+
433497
/**
434498
* Gets the private 'multiuse1' shared service.
435499
*

Tests/Fixtures/php/services_almost_circular_public.php

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ public function __construct()
3030
'baz6' => 'getBaz6Service',
3131
'connection' => 'getConnectionService',
3232
'connection2' => 'getConnection2Service',
33+
'connection3' => 'getConnection3Service',
34+
'connection4' => 'getConnection4Service',
3335
'dispatcher' => 'getDispatcherService',
3436
'dispatcher2' => 'getDispatcher2Service',
3537
'foo' => 'getFooService',
@@ -46,9 +48,13 @@ public function __construct()
4648
'level4' => 'getLevel4Service',
4749
'level5' => 'getLevel5Service',
4850
'level6' => 'getLevel6Service',
51+
'listener3' => 'getListener3Service',
52+
'listener4' => 'getListener4Service',
4953
'logger' => 'getLoggerService',
5054
'manager' => 'getManagerService',
5155
'manager2' => 'getManager2Service',
56+
'manager3' => 'getManager3Service',
57+
'manager4' => 'getManager4Service',
5258
'multiuse1' => 'getMultiuse1Service',
5359
'root' => 'getRootService',
5460
'subscriber' => 'getSubscriberService',
@@ -60,6 +66,7 @@ public function __construct()
6066
'level4' => true,
6167
'level5' => true,
6268
'level6' => true,
69+
'manager4' => true,
6370
'multiuse1' => true,
6471
];
6572

@@ -81,6 +88,7 @@ public function getRemovedIds()
8188
'level5' => true,
8289
'level6' => true,
8390
'logger2' => true,
91+
'manager4' => true,
8492
'multiuse1' => true,
8593
'subscriber2' => true,
8694
];
@@ -212,6 +220,34 @@ protected function getConnection2Service()
212220
return $instance;
213221
}
214222

223+
/**
224+
* Gets the public 'connection3' shared service.
225+
*
226+
* @return \stdClass
227+
*/
228+
protected function getConnection3Service()
229+
{
230+
$this->services['connection3'] = $instance = new \stdClass();
231+
232+
$instance->listener = [0 => ${($_ = isset($this->services['listener3']) ? $this->services['listener3'] : $this->getListener3Service()) && false ?: '_'}];
233+
234+
return $instance;
235+
}
236+
237+
/**
238+
* Gets the public 'connection4' shared service.
239+
*
240+
* @return \stdClass
241+
*/
242+
protected function getConnection4Service()
243+
{
244+
$this->services['connection4'] = $instance = new \stdClass();
245+
246+
$instance->listener = [0 => ${($_ = isset($this->services['listener4']) ? $this->services['listener4'] : $this->getListener4Service()) && false ?: '_'}];
247+
248+
return $instance;
249+
}
250+
215251
/**
216252
* Gets the public 'dispatcher' shared service.
217253
*
@@ -372,6 +408,36 @@ protected function getFoobar4Service()
372408
return $instance;
373409
}
374410

411+
/**
412+
* Gets the public 'listener3' shared service.
413+
*
414+
* @return \stdClass
415+
*/
416+
protected function getListener3Service()
417+
{
418+
$this->services['listener3'] = $instance = new \stdClass();
419+
420+
$instance->manager = ${($_ = isset($this->services['manager3']) ? $this->services['manager3'] : $this->getManager3Service()) && false ?: '_'};
421+
422+
return $instance;
423+
}
424+
425+
/**
426+
* Gets the public 'listener4' shared service.
427+
*
428+
* @return \stdClass
429+
*/
430+
protected function getListener4Service()
431+
{
432+
$a = ${($_ = isset($this->services['manager4']) ? $this->services['manager4'] : $this->getManager4Service()) && false ?: '_'};
433+
434+
if (isset($this->services['listener4'])) {
435+
return $this->services['listener4'];
436+
}
437+
438+
return $this->services['listener4'] = new \stdClass($a);
439+
}
440+
375441
/**
376442
* Gets the public 'logger' shared service.
377443
*
@@ -424,6 +490,16 @@ protected function getManager2Service()
424490
return $this->services['manager2'] = new \stdClass($a);
425491
}
426492

493+
/**
494+
* Gets the public 'manager3' shared service.
495+
*
496+
* @return \stdClass
497+
*/
498+
protected function getManager3Service($lazyLoad = true)
499+
{
500+
return $this->services['manager3'] = new \stdClass(${($_ = isset($this->services['connection3']) ? $this->services['connection3'] : $this->getConnection3Service()) && false ?: '_'});
501+
}
502+
427503
/**
428504
* Gets the public 'root' shared service.
429505
*
@@ -530,6 +606,16 @@ protected function getLevel6Service()
530606
return $instance;
531607
}
532608

609+
/**
610+
* Gets the private 'manager4' shared service.
611+
*
612+
* @return \stdClass
613+
*/
614+
protected function getManager4Service($lazyLoad = true)
615+
{
616+
return $this->services['manager4'] = new \stdClass(${($_ = isset($this->services['connection4']) ? $this->services['connection4'] : $this->getConnection4Service()) && false ?: '_'});
617+
}
618+
533619
/**
534620
* Gets the private 'multiuse1' shared service.
535621
*

0 commit comments

Comments
 (0)