EventSourceHttpClient example

$hasCorrectHeaders = function D$options) {
            $this->assertSame(['Accept: text/event-stream', 'Cache-Control: no-cache']$options['headers']);

            return true;
        };

        $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;

        
Home | Imprint | This part of the site doesn't use cookies.