Skip to content

Commit 5a63b40

Browse files
Merge branch '7.4' into 8.0
* 7.4: [Workflow] Add missing `@param` on Transition [HttpFoundation] Fix issue where ServerEvent with "0" data is not sent [HttpClient] Don't store response with authentication headers in shared mode
2 parents 8121f3c + 1171110 commit 5a63b40

File tree

2 files changed

+27
-7
lines changed

2 files changed

+27
-7
lines changed

ServerEvent.php

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -132,14 +132,12 @@ public function getIterator(): \Traversable
132132
}
133133
yield $head;
134134

135-
if ($this->data) {
136-
if (is_iterable($this->data)) {
137-
foreach ($this->data as $data) {
138-
yield \sprintf('data: %s', $data)."\n";
139-
}
140-
} else {
141-
yield \sprintf('data: %s', $this->data)."\n";
135+
if (is_iterable($this->data)) {
136+
foreach ($this->data as $data) {
137+
yield \sprintf('data: %s', $data)."\n";
142138
}
139+
} elseif ('' !== $this->data) {
140+
yield \sprintf('data: %s', $this->data)."\n";
143141
}
144142

145143
yield "\n";

Tests/EventStreamResponseTest.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,28 @@ public function testStreamEventWithSendMethod()
116116
$this->assertSameResponseContent("data: foo\n\n", $response);
117117
}
118118

119+
public function testStreamEventWith0Data()
120+
{
121+
$response = new EventStreamResponse(function () {
122+
yield new ServerEvent(
123+
data: '0',
124+
);
125+
});
126+
127+
$this->assertSameResponseContent("data: 0\n\n", $response);
128+
}
129+
130+
public function testStreamEventEmptyStringIgnored()
131+
{
132+
$response = new EventStreamResponse(function () {
133+
yield new ServerEvent(
134+
data: '',
135+
);
136+
});
137+
138+
$this->assertSameResponseContent("\n", $response);
139+
}
140+
119141
private function assertSameResponseContent(string $expected, EventStreamResponse $response): void
120142
{
121143
ob_start();

0 commit comments

Comments
 (0)