Skip to content

Commit bc03c1b

Browse files
bug symfony#29196 [Messenger] Fix collecting messages (ro0NL)
This PR was merged into the 4.2-dev branch. Discussion ---------- [Messenger] Fix collecting messages | Q | A | ------------- | --- | Branch? | master | Bug fix? | yes | New feature? | no | BC breaks? | no-ish | Deprecations? | no | Tests pass? | yes <!-- please add some, will be required by reviewers --> | Fixed tickets | #... <!-- #-prefixed issue number(s), if any --> | License | MIT | Doc PR | symfony/symfony-docs#... <!-- required for new features --> In 4.2 there's always one dispatched message because we provide the template with a generator. Calling `{{ gen|length }}` always returns `1` Before ![image](https://user-images.githubusercontent.com/1047696/48368788-f0028980-e6b4-11e8-91b0-54f755b9fb93.png) After ![image](https://user-images.githubusercontent.com/1047696/48368817-0ad4fe00-e6b5-11e8-8215-54bfdb307c47.png) Commits ------- bfc7d94 [Messenger] Fix collecting messages
2 parents 8cc7267 + bfc7d94 commit bc03c1b

File tree

2 files changed

+10
-8
lines changed

2 files changed

+10
-8
lines changed

src/Symfony/Component/Messenger/DataCollector/MessengerDataCollector.php

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -117,13 +117,15 @@ public function getExceptionsCount(string $bus = null): int
117117
return $count;
118118
}
119119

120-
public function getMessages(string $bus = null): iterable
120+
public function getMessages(string $bus = null): array
121121
{
122-
foreach ($this->data['messages'] ?? array() as $message) {
123-
if (null === $bus || $bus === $message['bus']) {
124-
yield $message;
125-
}
122+
if (null === $bus) {
123+
return $this->data['messages'];
126124
}
125+
126+
return array_filter($this->data['messages'], function ($message) use ($bus) {
127+
return $bus === $message['bus'];
128+
});
127129
}
128130

129131
public function getBuses(): array

src/Symfony/Component/Messenger/Tests/DataCollector/MessengerDataCollectorTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public function testHandle()
5050

5151
$collector->lateCollect();
5252

53-
$messages = iterator_to_array($collector->getMessages());
53+
$messages = $collector->getMessages();
5454
$this->assertCount(1, $messages);
5555

5656
$file = __FILE__;
@@ -95,7 +95,7 @@ public function testHandleWithException()
9595

9696
$collector->lateCollect();
9797

98-
$messages = iterator_to_array($collector->getMessages());
98+
$messages = $collector->getMessages();
9999
$this->assertCount(1, $messages);
100100

101101
$file = __FILE__;
@@ -145,7 +145,7 @@ public function testKeepsOrderedDispatchCalls()
145145

146146
$collector->lateCollect();
147147

148-
$messages = iterator_to_array($collector->getMessages());
148+
$messages = $collector->getMessages();
149149
$this->assertCount(5, $messages);
150150

151151
$this->assertSame('#1', $messages[0]['message']['value']['message']);

0 commit comments

Comments
 (0)