Skip to content

Commit

Permalink
Merge branch '4.3' into 4.4
Browse files Browse the repository at this point in the history
* 4.3:
  [DependencyInjection] Fixed the `getServiceIds` implementation to always return aliases
  [Messenger] Stop worker when it should stop
  • Loading branch information
nicolas-grekas committed Aug 26, 2019
2 parents 3debf91 + 43e1c8e commit c1bca29
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/Symfony/Component/DependencyInjection/Container.php
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ public function reset()
*/
public function getServiceIds()
{
return array_map('strval', array_unique(array_merge(['service_container'], array_keys($this->fileMap), array_keys($this->methodMap), array_keys($this->services))));
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))));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ public function testGetServiceIds()

$sc = new ProjectServiceContainer();
$sc->set('foo', $obj = new \stdClass());
$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()');
$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()');
}

public function testSet()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1300,6 +1300,30 @@ public function testScalarService()
$this->assertSame('some value', $container->get('bar')->foo);
}

public function testAliasCanBeFoundInTheDumpedContainerWhenBothTheAliasAndTheServiceArePublic()
{
$container = new ContainerBuilder();

$container->register('foo', 'stdClass')->setPublic(true);
$container->setAlias('bar', 'foo')->setPublic(true);

$container->compile();

// Bar is found in the compiled container
$service_ids = $container->getServiceIds();
$this->assertContains('bar', $service_ids);

$dumper = new PhpDumper($container);
$dump = $dumper->dump(['class' => 'Symfony_DI_PhpDumper_AliasesCanBeFoundInTheDumpedContainer']);
eval('?>'.$dump);

$container = new \Symfony_DI_PhpDumper_AliasesCanBeFoundInTheDumpedContainer();

// Bar should still be found in the compiled container
$service_ids = $container->getServiceIds();
$this->assertContains('bar', $service_ids);
}

public function testWither()
{
$container = new ContainerBuilder();
Expand Down
25 changes: 25 additions & 0 deletions src/Symfony/Component/Messenger/Tests/WorkerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
use Symfony\Component\Messenger\Tests\Fixtures\DummyMessage;
use Symfony\Component\Messenger\Transport\Receiver\ReceiverInterface;
use Symfony\Component\Messenger\Worker;
use Symfony\Component\Messenger\Worker\StopWhenMessageCountIsExceededWorker;
use Symfony\Contracts\EventDispatcher\EventDispatcherInterface;

/**
Expand Down Expand Up @@ -361,6 +362,30 @@ public function testWorkerWithMultipleReceivers()
// make sure they were processed in the correct order
$this->assertSame([$envelope1, $envelope2, $envelope3, $envelope4, $envelope5, $envelope6], $processedEnvelopes);
}

public function testWorkerWithDecorator()
{
$envelope1 = new Envelope(new DummyMessage('message1'));
$envelope2 = new Envelope(new DummyMessage('message2'));
$envelope3 = new Envelope(new DummyMessage('message3'));

$receiver = new DummyReceiver([
[$envelope1, $envelope2, $envelope3],
]);

$bus = $this->getMockBuilder(MessageBusInterface::class)->getMock();

$worker = new Worker([$receiver], $bus);
$workerWithDecorator = new StopWhenMessageCountIsExceededWorker($worker, 2);
$processedEnvelopes = [];
$workerWithDecorator->run([], function (?Envelope $envelope) use ($worker, &$processedEnvelopes) {
if (null !== $envelope) {
$processedEnvelopes[] = $envelope;
}
});

$this->assertSame([$envelope1, $envelope2], $processedEnvelopes);
}
}

class DummyReceiver implements ReceiverInterface
Expand Down
4 changes: 4 additions & 0 deletions src/Symfony/Component/Messenger/Worker.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,10 @@ public function run(array $options = [], callable $onHandledCallback = null): vo

$this->handleMessage($envelope, $receiver, $transportName, $this->retryStrategies[$transportName] ?? null);
$onHandled($envelope);

if ($this->shouldStop) {
break 2;
}
}

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

0 comments on commit c1bca29

Please sign in to comment.