[Messenger] Fix collecting messages
This commit is contained in:
parent
6eb5f93918
commit
bfc7d94169
@ -117,13 +117,15 @@ class MessengerDataCollector extends DataCollector implements LateDataCollectorI
|
||||
return $count;
|
||||
}
|
||||
|
||||
public function getMessages(string $bus = null): iterable
|
||||
public function getMessages(string $bus = null): array
|
||||
{
|
||||
foreach ($this->data['messages'] ?? array() as $message) {
|
||||
if (null === $bus || $bus === $message['bus']) {
|
||||
yield $message;
|
||||
}
|
||||
if (null === $bus) {
|
||||
return $this->data['messages'];
|
||||
}
|
||||
|
||||
return array_filter($this->data['messages'], function ($message) use ($bus) {
|
||||
return $bus === $message['bus'];
|
||||
});
|
||||
}
|
||||
|
||||
public function getBuses(): array
|
||||
|
@ -50,7 +50,7 @@ class MessengerDataCollectorTest extends TestCase
|
||||
|
||||
$collector->lateCollect();
|
||||
|
||||
$messages = iterator_to_array($collector->getMessages());
|
||||
$messages = $collector->getMessages();
|
||||
$this->assertCount(1, $messages);
|
||||
|
||||
$file = __FILE__;
|
||||
@ -95,7 +95,7 @@ DUMP;
|
||||
|
||||
$collector->lateCollect();
|
||||
|
||||
$messages = iterator_to_array($collector->getMessages());
|
||||
$messages = $collector->getMessages();
|
||||
$this->assertCount(1, $messages);
|
||||
|
||||
$file = __FILE__;
|
||||
@ -145,7 +145,7 @@ DUMP
|
||||
|
||||
$collector->lateCollect();
|
||||
|
||||
$messages = iterator_to_array($collector->getMessages());
|
||||
$messages = $collector->getMessages();
|
||||
$this->assertCount(5, $messages);
|
||||
|
||||
$this->assertSame('#1', $messages[0]['message']['value']['message']);
|
||||
|
Reference in New Issue
Block a user