8000 Add separate test for inline factory · symfony/symfony@f3515db · GitHub
[go: up one dir, main page]

Skip to content

Commit f3515db

Browse files
committed
Add separate test for inline factory
1 parent 54a5b7b commit f3515db

File tree

7 files changed

+158
-25
lines changed

7 files changed

+158
-25
lines changed

src/Symfony/Component/DependencyInjection/Compiler/AnalyzeServiceReferencesPass.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ protected function processValue($value, $isRoot = false)
9090
$inExpression = $this->inExpression();
9191

9292
if ($value instanceof ArgumentInterface) {
93-
$this->lazy = !$value instanceof IteratorArgument || !$this->byFactory;
93+
$this->lazy = !$this->byFactory || !$value instanceof IteratorArgument;
9494
parent::processValue($value->getValues());
9595
$this->lazy = $lazy;
9696

@@ -146,7 +146,6 @@ protected function processValue($value, $isRoot = false)
146146
$this->processValue($value->getFactory());
147147
$this->byFactory = $byFactory;
148148
$this->processValue($value->getArguments());
149-
$this->byFactory = false;
150149

151150
$properties = $value->getProperties();
152151
$setters = $value->getMethodCalls();

src/Symfony/Component/DependencyInjection/Dumper/PhpDumper.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -420,7 +420,7 @@ private function collectCircularReferences(string $sourceId, array $edges, array
420420
foreach ($edges as $edge) {
421421
$node = $edge->getDestNode();
422422
$id = $node->getId();
423-
if (!$node->getValue() instanceof Definition || $sourceId === $id || $edge->isLazy() || $edge->isWeak()) {
423+
if ($sourceId === $id || !$node->getValue() instanceof Definition || $edge->isLazy() || $edge->isWeak()) {
424424
continue;
425425
}
426426

src/Symfony/Component/DependencyInjection/Tests/ContainerBuilderTest.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1383,6 +1383,9 @@ public function testAlmostCircular($visibility)
13831383
$logger = $container->get('monolog.logger');
13841384
$this->assertEquals(new \stdClass(), $logger->handler);
13851385

1386+
$logger_inline = $container->get('monolog_inline.logger');
1387+
$this->assertEquals(new \stdClass(), $logger_inline->handler);
1388+
13861389
$foo = $container->get('foo');
13871390
$this->assertSame($foo, $foo->bar->foobar->foo);
13881391

src/Symfony/Component/DependencyInjection/Tests/Dumper/PhpDumperTest.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1063,6 +1063,9 @@ public function testAlmostCircular($visibility)
10631063
$logger = $container->get('monolog.logger');
10641064
$this->assertEquals(new \stdClass(), $logger->handler);
10651065

1066+
$logger_inline = $container->get('monolog_inline.logger');
1067+
$this->assertEquals(new \stdClass(), $logger_inline->handler);
1068+
10661069
$foo = $container->get('foo');
10671070
$this->assertSame($foo, $foo->bar->foobar->foo);
10681071

src/Symfony/Component/DependencyInjection/Tests/Fixtures/containers/container_almost_circular.php

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
$container->register('doctrine.config', 'stdClass')->setPublic(false)
1616
->setProperty('resolver', new Reference('doctrine.entity_listener_resolver'))
1717
->setProperty('flag', 'ok');
18-
;
1918

2019
$container->register('doctrine.entity_manager', 'stdClass')->setPublic(true)
2120
->setFactory([FactoryChecker::class, 'create'])
@@ -43,13 +42,10 @@
4342
// monolog-like + handler that require monolog
4443

4544
$container->register('monolog.logger', 'stdClass')->setPublic(true)
46-
->setProperty('handler', new Reference('mailer.mailer'));
45+
->setProperty('handler', new Reference('mailer.transport'));
4746

48-
$container->register('mailer.mailer', 'stdClass')->setPublic(false)
49-
->addArgument(
50-
(new Definition('stdClass'))
51-
->setFactory([new Reference('mailer.transport_factory'), 'create'])
52-
);
47+
$container->register('mailer.transport', 'stdClass')->setPublic($public)
48+
->setFactory([new Reference('mailer.transport_factory'), 'create']);
5349

5450
$container->register('mailer.transport_factory', FactoryCircular::class)->setPublic($public)
5551
->addArgument(new TaggedIteratorArgument('mailer.transport'));
@@ -59,7 +55,28 @@
5955
->addTag('mailer.transport');
6056

6157
$container->register('monolog.logger_2', 'stdClass')->setPublic($public)
62-
->setProperty('handler', new Reference('mailer.mailer'));
58+
->setProperty('handler', new Reference('mailer.transport'));
59+
60+
// monolog-like + handler that require monolog with inlined factory
61+
62+
$container->register('monolog_inline.logger', 'stdClass')->setPublic(true)
63+
->setProperty('handler', new Reference('mailer_inline.mailer'));
64+
65+
$container->register('mailer_inline.mailer', 'stdClass')->setPublic(false)
66+
->addArgument(
67+
(new Definition('stdClass'))
68+
->setFactory([new Reference('mailer_inline.transport_factory'), 'create'])
69+
);
70+
71+
$container->register('mailer_inline.transport_factory', FactoryCircular::class)->setPublic($public)
72+
->addArgument(new TaggedIteratorArgument('mailer_inline.transport'));
73+
74+
$container->register('mailer_inline.transport_factory.amazon', 'stdClass')->setPublic($public)
75+
->addArgument(new Reference('monolog_inline.logger_2'))
76+
->addTag('mailer.transport');
77+
78+
$container->register('monolog_inline.logger_2', 'stdClass')->setPublic($public)
79+
->setProperty('handler', new Reference('mailer_inline.mailer'));
6380

6481
// same visibility for deps
6582

src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services_almost_circular_private.php

Lines changed: 52 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ public function __construct()
4141
'manager2' => 'getManager2Service',
4242
'manager3' => 'getManager3Service',
4343
'monolog.logger' => 'getMonolog_LoggerService',
44+
'monolog_inline.logger' => 'getMonologInline_LoggerService',
4445
'pA' => 'getPAService',
4546
'root' => 'getRootService',
4647
'subscriber' => 'getSubscriberService',
@@ -86,11 +87,15 @@ public function getRemovedIds(): array
8687
'level5' => true,
8788
'level6' => true,
8889
'logger2' => true,
89-
'mailer.mailer' => true,
90+
'mailer.transport' => true,
9091
'mailer.transport_factory' => true,
9192
'mailer.transport_factory.amazon' => true,
93+
'mailer_inline.mailer' => true,
94+
'mailer_inline.transport_factory' => true,
95+
'mailer_inline.transport_factory.amazon' => true,
9296
'manager4' => true,
9397
'monolog.logger_2' => true,
98+
'monolog_inline.logger_2' => true,
9499
'multiuse1' => true,
95100
'pB' => true,
96101
'pC' => true,
@@ -393,7 +398,21 @@ protected function getMonolog_LoggerService()
393398
{
394399
$this->services['monolog.logger'] = $instance = new \stdClass();
395400

396-
$instance->handler = ($this->privates['mailer.mailer'] ?? $this->getMailer_MailerService());
401+
$instance->handler = ($this->privates['mailer.transport'] ?? $this->getMailer_TransportService());
402+
403+
return $instance;
404+
}
405+
406+
/**
407+
* Gets the public 'monolog_inline.logger' shared service.
408+
*
409+
* @return \stdClass
410+
*/
411+
protected function getMonologInline_LoggerService()
412+
{
413+
$this->services['monolog_inline.logger'] = $instance = new \stdClass();
414+
415+
$instance->handler = ($this->privates['mailer_inline.mailer'] ?? $this->getMailerInline_MailerService());
397416

398417
return $instance;
399418
}
@@ -495,15 +514,16 @@ protected function getLevel5Service()
495514
}
496515

497516
/**
498-
* Gets the private 'mailer.mailer' shared service.
517+
* Gets the private 'mailer.transport' shared service.
499518
*
500519
* @return \stdClass
501520
*/
502-
protected function getMailer_MailerService()
521+
protected function getMailer_TransportService()
503522
{
504-
return $this->privates['mailer.mailer'] = new \stdClass((new \FactoryCircular(new RewindableGenerator(function () {
523+
return $this->privates['mailer.transport'] = (new \FactoryCircular(new RewindableGenerator(function () {
505524
yield 0 => ($this->privates['mailer.transport_factory.amazon'] ?? $this->getMailer_TransportFactory_AmazonService());
506-
}, 1)))->create());
525+
yield 1 => $this->getMailerInline_TransportFactory_AmazonService();
526+
}, 2)))->create();
507527
}
508528

509529
/**
@@ -517,11 +537,36 @@ protected function getMailer_TransportFactory_AmazonService()
517537

518538
$this->privates['mailer.transport_factory.amazon'] = $instance = new \stdClass($a);
519539

520-
$a->handler = ($this->privates['mailer.mailer'] ?? $this->getMailer_MailerService());
540+
$a->handler = ($this->privates['mailer.transport'] ?? $this->getMailer_TransportService());
521541

522542
return $instance;
523543
}
524544

545+
/**
546+
* Gets the private 'mailer_inline.mailer' shared service.
547+
*
548+
* @return \stdClass
549+
*/
550+
protected function getMailerInline_MailerService()
551+
{
552+
return $this->privates['mailer_inline.mailer'] = new \stdClass((new \FactoryCircular(new RewindableGenerator(function () {
553+
return new \EmptyIterator();
554+
}, 0)))->create());
555+
}
556+
557+
/**
558+
* Gets the private 'mailer_inline.transport_factory.amazon' shared service.
559+
*
560+
* @return \stdClass
561+
*/
562+
protected function getMailerInline_TransportFactory_AmazonService()
563+
{
564+
$a = new \stdClass();
565+
$a->handler = ($this->privates['mailer_inline.mailer'] ?? $this->getMailerInline_MailerService());
566+
567+
return new \stdClass($a);
568+
}
569+
525570
/**
526571
* Gets the private 'manager4' shared service.
527572
*

src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services_almost_circular_public.php

Lines changed: 73 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -48,13 +48,18 @@ public function __construct()
4848
'listener3' => 'getListener3Service',
4949
'listener4' => 'getListener4Service',
5050
'logger' => 'getLoggerService',
51+
'mailer.transport' => 'getMailer_TransportService',
5152
'mailer.transport_factory' => 'getMailer_TransportFactoryService',
5253
'mailer.transport_factory.amazon' => 'getMailer_TransportFactory_AmazonService',
54+
'mailer_inline.transport_factory' => 'getMailerInline_TransportFactoryService',
55+
'mailer_inline.transport_factory.amazon' => 'getMailerInline_TransportFactory_AmazonService',
5356
'manager' => 'getManagerService',
5457
'manager2' => 'getManager2Service',
5558
'manager3' => 'getManager3Service',
5659
'monolog.logger' => 'getMonolog_LoggerService',
5760
'monolog.logger_2' => 'getMonolog_Logger2Service',
61+
'monolog_inline.logger' => 'getMonologInline_LoggerService',
62+
'monolog_inline.logger_2' => 'getMonologInline_Logger2Service',
5863
'pA' => 'getPAService',
5964
'pB' => 'getPBService',
6065
'pC' => 'getPCService',
@@ -92,7 +97,7 @@ public function getRemovedIds(): array
9297
'level5' => true,
9398
'level6' => true,
9499
'logger2' => true,
95-
'mailer.mailer' => true,
100+
'mailer_inline.mailer' => true,
96101
'manager4' => true,
97102
'multiuse1' => true,
98103
'subscriber2' => true,
@@ -482,6 +487,16 @@ protected function getLoggerService()
482487
return $instance;
483488
}
484489

490+
/**
491+
* Gets the public 'mailer.transport' shared service.
492+
*
493+
* @return \stdClass
494+
*/
495+
protected function getMailer_TransportService()
496+
{
497+
return $this->services['mailer.transport'] = ($this->services['mailer.transport_factory'] ?? $this->getMailer_TransportFactoryService())->create();
498+
}
499+
485500
/**
486501
* Gets the public 'mailer.transport_factory' shared service.
487502
*
@@ -491,7 +506,8 @@ protected function getMailer_TransportFactoryService()
491506
{
492507
return $this->services['mailer.transport_factory'] = new \FactoryCircular(new RewindableGenerator(function () {
493508
yield 0 => ($this->services['mailer.transport_factory.amazon'] ?? $this->getMailer_TransportFactory_AmazonService());
494-
}, 1));
509+
yield 1 => ($this->services['mailer_inline.transport_factory.amazon'] ?? $this->getMailerInline_TransportFactory_AmazonService());
510+
}, 2));
495511
}
496512

497513
/**
@@ -504,6 +520,28 @@ protected function getMailer_TransportFactory_AmazonService()
504520
return $this->services['mailer.transport_factory.amazon'] = new \stdClass(($this->services['monolog.logger_2'] ?? $this->getMonolog_Logger2Service()));
505521
}
506522

523+
/**
524+
* Gets the public 'mailer_inline.transport_factory' shared service.
525+
*
526+
* @return \FactoryCircular
527+
*/
528+
protected function getMailerInline_TransportFactoryService()
529+
{
530+
return $this->services['mailer_inline.transport_factory'] = new \FactoryCircular(new RewindableGenerator(function () {
531+
return new \EmptyIterator();
532+
}, 0));
533+
}
534+
535+
/**
536+
* Gets the public 'mailer_inline.transport_factory.amazon' shared service.
537+
*
538+
* @return \stdClass
539+
*/
540+
protected function getMailerInline_TransportFactory_AmazonService()
541+
{
542+
return $this->services['mailer_inline.transport_factory.amazon'] = new \stdClass(($this->services['monolog_inline.logger_2'] ?? $this->getMonologInline_Logger2Service()));
543+
}
544+
507545
/**
508546
* Gets the public 'manager' shared service.
509547
*
@@ -561,7 +599,7 @@ protected function getMonolog_LoggerService()
561599
{
562600
$this->services['monolog.logger'] = $instance = new \stdClass();
563601

564-
$instance->handler = ($this->privates['mailer.mailer'] ?? $this->getMailer_MailerService());
602+
$instance->handler = ($this->services['mailer.transport'] ?? $this->getMailer_TransportService());
565603

566604
return $instance;
567605
}
@@ -575,7 +613,35 @@ protected function getMonolog_Logger2Service()
575613
{
576614
$this->services['monolog.logger_2'] = $instance = new \stdClass();
577615

578-
$instance->handler = ($this->privates['mailer.mailer'] ?? $this->getMailer_MailerService());
616+
$instance->handler = ($this->services['mailer.transport'] ?? $this->getMailer_TransportService());
617+
618+
return $instance;
619+
}
620+
621+
/**
622+
* Gets the public 'monolog_inline.logger' shared service.
623+
*
624+
* @return \stdClass
625+
*/
626+
protected function getMonologInline_LoggerService()
627+
{
628+
$this->services['monolog_inline.logger'] = $instance = new \stdClass();
629+
630+
$instance->handler = ($this->privates['mailer_inline.mailer'] ?? $this->getMailerInline_MailerService());
631+
632+
return $instance;
633+
}
634+
635+
/**
636+
* Gets the public 'monolog_inline.logger_2' shared service.
637+
*
638+
* @return \stdClass
639+
*/
640+
protected function getMonologInline_Logger2Service()
641+
{
642+
$this->services['monolog_inline.logger_2'] = $instance = new \stdClass();
643+
644+
$instance->handler = ($this->privates['mailer_inline.mailer'] ?? $this->getMailerInline_MailerService());
579645

580646
return $instance;
581647
}
@@ -710,13 +776,13 @@ protected function getLevel5Service()
710776
}
711777

712778
/**
713-
* Gets the private 'mailer.mailer' shared service.
779+
* Gets the private 'mailer_inline.mailer' shared service.
714780
*
715781
* @return \stdClass
716782
*/
717-
protected function getMailer_MailerService()
783+
protected function getMailerInline_MailerService()
718784
{
719-
return $this->privates['mailer.mailer'] = new \stdClass(($this->services['mailer.transport_factory'] ?? $this->getMailer_TransportFactoryService())->create());
785+
return $this->privates['mailer_inline.mailer'] = new \stdClass(($this->services['mailer_inline.transport_factory'] ?? $this->getMailerInline_TransportFactoryService())->create());
720786
}
721787

722788
/**

0 commit comments

Comments
 (0)
0