Skip to content
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
12 changes: 5 additions & 7 deletions src/Symfony/Component/HttpFoundation/ServerEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -132,14 +132,12 @@ public function getIterator(): \Traversable
}
yield $head;

if ($this->data) {
if (is_iterable($this->data)) {
foreach ($this->data as $data) {
yield \sprintf('data: %s', $data)."\n";
}
} else {
yield \sprintf('data: %s', $this->data)."\n";
if (is_iterable($this->data)) {
foreach ($this->data as $data) {
yield \sprintf('data: %s', $data)."\n";
}
} elseif ('' !== $this->data) {
yield \sprintf('data: %s', $this->data)."\n";
}

yield "\n";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,28 @@ public function testStreamEventWithSendMethod()
$this->assertSameResponseContent("data: foo\n\n", $response);
}

public function testStreamEventWith0Data()
{
$response = new EventStreamResponse(function () {
yield new ServerEvent(
data: '0',
);
});

$this->assertSameResponseContent("data: 0\n\n", $response);
}

public function testStreamEventEmptyStringIgnored()
{
$response = new EventStreamResponse(function () {
yield new ServerEvent(
data: '',
);
});

$this->assertSameResponseContent("\n", $response);
}

private function assertSameResponseContent(string $expected, EventStreamResponse $response): void
{
ob_start();
Expand Down