$httpClient =
$this->
createMock(HttpClientInterface::
class);
$httpClient->
method('request'
)->
with('GET', 'http://localhost:8080/events',
$this->
callback($hasCorrectHeaders))->
willReturn($response);
$httpClient->
method('stream'
)->
willReturn($responseStream);
$es =
new EventSourceHttpClient($httpClient);
$res =
$es->
connect('http://localhost:8080/events'
);
$expected =
[ new FirstChunk(),
new ServerSentEvent("event: builderror\nid: 46\ndata: {\"foo\": \"bar\"}\n\n"
),
new ServerSentEvent("event: reload\nid: 47\ndata: {}\n\n"
),
new ServerSentEvent("event: reload\nid: 48\ndata: {}\n\n"
),
new ServerSentEvent("data: test\ndata:test\nid: 49\nevent: testEvent\n\n\n"
),
new ServerSentEvent("id: 50\ndata: <tag>\ndata\ndata: <foo />\ndata\ndata: </tag>\n\n"
),
];
$i = 0;
$this->
expectExceptionMessage('Response has been canceled'
);
while ($res) { if ($i > 0
) { $res->
cancel();
}