Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit8fde9b3

Browse files
committed
[Messenger] fallback to default bus if BusNameStamp missing from Envelope
1 parent27d10a6 commit8fde9b3

File tree

2 files changed

+17
-11
lines changed

2 files changed

+17
-11
lines changed

‎src/Symfony/Component/Messenger/RoutableMessageBus.php‎

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,14 +45,15 @@ public function dispatch($envelope, array $stamps = []): Envelope
4545

4646
/** @var BusNameStamp $busNameStamp */
4747
$busNameStamp =$envelope->last(BusNameStamp::class);
48-
if (null ===$busNameStamp) {
49-
thrownewInvalidArgumentException('Envelope does not contain a BusNameStamp.');
48+
$busNameStampName = MessageBusInterface::class;
49+
if (null !==$busNameStamp) {
50+
$busNameStampName =$busNameStamp->getBusName();
5051
}
5152

52-
if (!$this->busLocator->has($busNameStamp->getBusName())) {
53-
thrownewInvalidArgumentException(sprintf('Invalid bus name "%s" on BusNameStamp.',$busNameStamp->getBusName()));
53+
if (!$this->busLocator->has($busNameStampName)) {
54+
thrownewInvalidArgumentException(sprintf('Invalid bus name "%s" on BusNameStamp.',$busNameStampName));
5455
}
5556

56-
return$this->busLocator->get($busNameStamp->getBusName())->dispatch($envelope,$stamps);
57+
return$this->busLocator->get($busNameStampName)->dispatch($envelope,$stamps);
5758
}
5859
}

‎src/Symfony/Component/Messenger/Tests/RoutableMessageBusTest.php‎

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,18 +41,23 @@ public function testItRoutesToTheCorrectBus()
4141
$this->assertSame($envelope,$routableBus->dispatch($envelope, [$stamp]));
4242
}
4343

44-
publicfunctiontestItExceptionOnMissingStamp()
44+
publicfunctiontestItRoutesToDefaultBus()
4545
{
46-
$this->expectException(InvalidArgumentException::class);
47-
$this->expectExceptionMessage('does not contain a BusNameStamp');
48-
4946
$envelope =newEnvelope(new \stdClass());
47+
$stamp =newDelayStamp(5);
48+
$defaultBus =$this->createMock(MessageBusInterface::class);
49+
$defaultBus->expects($this->once())->method('dispatch')->with($envelope, [$stamp])
50+
->willReturn($envelope);
5051

5152
$container =$this->createMock(ContainerInterface::class);
52-
$container->expects($this->never())->method('has');
53+
$container->expects($this->once())->method('has')->with(MessageBusInterface::class)
54+
->willReturn(true);
55+
$container->expects($this->once())->method('get')->with(MessageBusInterface::class)
56+
->willReturn($defaultBus);
5357

5458
$routableBus =newRoutableMessageBus($container);
55-
$routableBus->dispatch($envelope);
59+
60+
$this->assertSame($envelope,$routableBus->dispatch($envelope, [$stamp]));
5661
}
5762

5863
publicfunctiontestItExceptionOnBusNotFound()

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp