Skip to content

[Messenger] Fix collecting messages #29196

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 14, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -117,13 +117,15 @@ public function getExceptionsCount(string $bus = null): int
return $count;
}

public function getMessages(string $bus = null): iterable
public function getMessages(string $bus = null): array
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

getMessages() in 4.1

public function getMessages(string $bus = null): array

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why change? the BC break is allowed and the new interface better, don't you think?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OH, in order to "count" on the result. OK.

{
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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public function testHandle()

$collector->lateCollect();

$messages = iterator_to_array($collector->getMessages());
$messages = $collector->getMessages();
$this->assertCount(1, $messages);

$file = __FILE__;
Expand Down Expand Up @@ -95,7 +95,7 @@ public function testHandleWithException()

$collector->lateCollect();

$messages = iterator_to_array($collector->getMessages());
$messages = $collector->getMessages();
$this->assertCount(1, $messages);

$file = __FILE__;
Expand Down Expand Up @@ -145,7 +145,7 @@ public function testKeepsOrderedDispatchCalls()

$collector->lateCollect();

$messages = iterator_to_array($collector->getMessages());
$messages = $collector->getMessages();
$this->assertCount(5, $messages);

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