Skip to content

Commit ccd903f

Browse files
committed
Merge branch '6.4' into 7.0
* 6.4: [Scheduler] Fix changelog [FrameworkBundle][Test]: add token attributes in `KernelBrowser::loginUser()` Fix stateful scheduler [Scheduler] Speed up tests [HttpClient] Enable using EventSourceHttpClient::connect() for both GET and POST [Serializer] Allow Context to target classes [Validator] Add is_valid function to Expression constraint Fix Form profiler toggles [FrameworkBundle] Fix missing PhraseProviderFactory import [Security] Fixing deprecation message
2 parents b330136 + 0315b30 commit ccd903f

File tree

3 files changed

+30
-2
lines changed

3 files changed

+30
-2
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ CHANGELOG
1212
* Add `HarFileResponseFactory` testing utility, allow to replay responses from `.har` files
1313
* Add `max_retries` option to `RetryableHttpClient` to adjust the retry logic on a per request level
1414
* Add `PingWehookMessage` and `PingWebhookMessageHandler`
15+
* Enable using EventSourceHttpClient::connect() for both GET and POST
1516

1617
6.3
1718
---

EventSourceHttpClient.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,9 @@ public function __construct(HttpClientInterface $client = null, float $reconnect
3939
$this->reconnectionTime = $reconnectionTime;
4040
}
4141

42-
public function connect(string $url, array $options = []): ResponseInterface
42+
public function connect(string $url, array $options = [], string $method = 'GET'): ResponseInterface
4343
{
44-
return $this->request('GET', $url, self::mergeDefaultOptions($options, [
44+
return $this->request($method, $url, self::mergeDefaultOptions($options, [
4545
'buffer' => false,
4646
'headers' => [
4747
'Accept' => 'text/event-stream',

Tests/EventSourceHttpClientTest.php

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,33 @@ public function testGetServerSentEvents()
110110
}
111111
}
112112

113+
public function testPostServerSentEvents()
114+
{
115+
$chunk = new DataChunk(0, '');
116+
$response = new MockResponse('', ['canceled' => false, 'http_method' => 'POST', 'url' => 'http://localhost:8080/events', 'response_headers' => ['content-type: text/event-stream']]);
117+
$responseStream = new ResponseStream((function () use ($response, $chunk) {
118+
yield $response => new FirstChunk();
119+
yield $response => $chunk;
120+
yield $response => new ErrorChunk(0, 'timeout');
121+
})());
122+
123+
$hasCorrectHeaders = function ($options) {
124+
$this->assertSame(['Accept: text/event-stream', 'Cache-Control: no-cache'], $options['headers']);
125+
$this->assertSame('mybody', $options['body']);
126+
127+
return true;
128+
};
129+
130+
$httpClient = $this->createMock(HttpClientInterface::class);
131+
132+
$httpClient->method('request')->with('POST', 'http://localhost:8080/events', $this->callback($hasCorrectHeaders))->willReturn($response);
133+
134+
$httpClient->method('stream')->willReturn($responseStream);
135+
136+
$es = new EventSourceHttpClient($httpClient);
137+
$res = $es->connect('http://localhost:8080/events', ['body' => 'mybody'], 'POST');
138+
}
139+
113140
/**
114141
* @dataProvider contentTypeProvider
115142
*/

0 commit comments

Comments
 (0)