8000 Merge branch '4.3' into 4.4 · symfony/symfony@c1bca29 · GitHub
[go: up one dir, main page]

Skip to content

Commit c1bca29

Browse files
Merge branch '4.3' into 4.4
* 4.3: [DependencyInjection] Fixed the `getServiceIds` implementation to always return aliases [Messenger] Stop worker when it should stop
2 parents 3debf91 + 43e1c8e commit c1bca29

File tree

5 files changed

+55
-2
lines changed

5 files changed

+55
-2
lines changed

src/Symfony/Component/DependencyInjection/Container.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,7 @@ public function reset()
332332
*/
333333
public function getServiceIds()
334334
{
335-
return array_map('strval', array_unique(array_merge(['service_container'], array_keys($this->fileMap), array_keys($this->methodMap), array_keys($this->services))));
335+
return array_map('strval', array_unique(array_merge(['service_container'], array_keys($this->fileMap), array_keys($this->methodMap), array_keys($this->aliases), array_keys($this->services))));
336336
}
337337

338338
/**

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ public function testGetServiceIds()
139139

140140
$sc = new ProjectServiceContainer();
141141
$sc->set('foo', $obj = new \stdClass());
142-
$this->assertEquals(['service_container', 'bar', 'foo_bar', 'foo.baz', 'circular', 'throw_exception', 'throws_exception_on_service_configuration', 'internal_dependency', 'foo'], $sc->getServiceIds(), '->getServiceIds() returns defined service ids by factory methods in the method map, followed by service ids defined by set()');
142+
$this->assertEquals(['service_container', 'bar', 'foo_bar', 'foo.baz', 'circular', 'throw_exception', 'throws_exception_on_service_configuration', 'internal_dependency', 'alias', 'foo'], $sc->getServiceIds(), '->getServiceIds() returns defined service ids by factory methods in the method map, followed by service ids defined by set()');
143143
}
144144

145145
public function testSet()

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

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1300,6 +1300,30 @@ public function testScalarService()
13001300
$this->assertSame('some value', $container->get('bar')->foo);
13011301
}
13021302

1303+
public function testAliasCanBeFoundInTheDumpedContainerWhenBothTheAliasAndTheServiceArePublic()
1304+
{
1305+
$container = new ContainerBuilder();
1306+
1307+
$container->register('foo', 'stdClass')->setPublic(true);
1308+
$container->setAlias('bar', 'foo')->setPublic(true);
1309+
1310+
$container->compile();
1311+
1312+
// Bar is found in the compiled container
1313+
$service_ids = $container->getServiceIds();
1314+
$this->assertContains('bar', $service_ids);
1315+
1316+
$dumper = new PhpDumper($container);
1317+
$dump = $dumper->dump(['class' => 'Symfony_DI_PhpDumper_AliasesCanBeFoundInTheDumpedContainer']);
1318+
eval('?>'.$dump);
1319+
1320+
$container = new \Symfony_DI_PhpDumper_AliasesCanBeFoundInTheDumpedContainer();
1321+
1322+
// Bar should still be found in the compiled container
1323+
$service_ids = $container->getServiceIds();
1324+
$this->assertContains('bar', $service_ids);
1325+
}
1326+
13031327
public function testWither()
13041328
{
13051329
$container = new ContainerBuilder();

src/Symfony/Component/Messenger/Tests/WorkerTest.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
use Symfony\Component\Messenger\Tests\Fixtures\DummyMessage;
2828
use Symfony\Component\Messenger\Transport\Receiver\ReceiverInterface;
2929
use Symfony\Component\Messenger\Worker;
30+
use Symfony\Component\Messenger\Worker\StopWhenMessageCountIsExceededWorker;
3031
use Symfony\Contracts\EventDispatcher\EventDispatcherInterface;
3132

3233
/**
@@ -361,6 +362,30 @@ public function testWorkerWithMultipleReceivers()
361362
// make sure they were processed in the correct order
362363
$this->assertSame([$envelope1, $envelope2, $envelope3, $envelope4, $envelope5, $envelope6], $processedEnvelopes);
363364
}
365+
366+
public function testWorkerWithDecorator()
367+
{
368+
$envelope1 = new Envelope(new DummyMessage('message1'));
369+
$envelope2 = new Envelope(new DummyMessage('message2'));
370+
$envelope3 = new Envelope(new DummyMessage('message3'));
371+
372+
$receiver = new DummyReceiver([
373+
[$envelope1, $envelope2, $envelope3],
374+
]);
375+
376+
$bus = $this->getMockBuilder(MessageBusInterface::class)->getMock();
377+
378+
$worker = new Worker([$receiver], $bus);
379+
$workerWithDecorator = new StopWhenMessageCountIsExceededWorker($worker, 2);
380+
$processedEnvelopes = [];
381+
$workerWithDecorator->run([], function (?Envelope $envelope) use ($worker, &$processedEnvelopes) {
382+
if (null !== $envelope) {
383+
$processedEnvelopes[] = $envelope;
384+
}
385+
});
386+
387+
$this->assertSame([$envelope1, $envelope2], $processedEnvelopes);
388+
}
364389
}
365390

366391
class DummyReceiver implements ReceiverInterface

src/Symfony/Component/Messenger/Worker.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,10 @@ public function run(array $options = [], callable $onHandledCallback = null): vo
9090

9191
$this->handleMessage($envelope, $receiver, $transportName, $this->retryStrategies[$transportName] ?? null);
9292
$onHandled($envelope);
93+
94+
if ($this->shouldStop) {
95+
break 2;
96+
}
9397
}
9498

9599
// after handling a single receiver, quit and start the loop again

0 commit comments

Comments
 (0)
0