diff --git a/tests/Feature/MakeRequestTest.php b/tests/Feature/MakeRequestTest.php index e104a04..a792aa4 100644 --- a/tests/Feature/MakeRequestTest.php +++ b/tests/Feature/MakeRequestTest.php @@ -32,14 +32,10 @@ public function it_can_make_a_request() { $response = $this->get('/stream'); - $this->assertSame('data: "foo" - -data: "bar" - -id: 1234 -data: "foobar" - -', $response->streamedContent()); + $this->assertSame( + "data: \"foo\"\n\ndata: \"bar\"\n\nid: 1234\ndata: \"foobar\"\n\n", + $response->streamedContent() + ); $response->assertOk() ->assertHeader('Content-Type', 'text/event-stream; charset=UTF-8') @@ -51,9 +47,7 @@ public function it_can_make_a_request_with_exit_command() { $response = $this->get('/stream-with-exit'); - $this->assertSame('data: "foobar" - -', $response->streamedContent()); + $this->assertSame("data: \"foobar\"\n\n", $response->streamedContent()); $response->assertOk() ->assertHeader('Content-Type', 'text/event-stream; charset=UTF-8') @@ -65,14 +59,10 @@ public function it_can_make_a_request_with_event_command() { $response = $this->get('/stream-with-event'); - $this->assertSame('data: "foo" - -event: ping -data: ["pong"] - -data: "bar" - -', $response->streamedContent()); + $this->assertSame( + "data: \"foo\"\n\nevent: ping\ndata: [\"pong\"]\n\ndata: \"bar\"\n\n", + $response->streamedContent() + ); $response->assertOk() ->assertHeader('Content-Type', 'text/event-stream; charset=UTF-8') @@ -84,13 +74,10 @@ public function it_can_make_a_request_with_loop_until_command() { $response = $this->get('/stream-with-loop'); - $this->assertSame('data: "foo" - -data: "bar" - -data: "foobar" - -', $response->streamedContent()); + $this->assertSame( + "data: \"foo\"\n\ndata: \"bar\"\n\ndata: \"foobar\"\n\n", + $response->streamedContent() + ); $response->assertOk() ->assertHeader('Content-Type', 'text/event-stream; charset=UTF-8') diff --git a/tests/Unit/DataTest.php b/tests/Unit/DataTest.php new file mode 100644 index 0000000..746ee01 --- /dev/null +++ b/tests/Unit/DataTest.php @@ -0,0 +1,42 @@ +assertSame("data: \"ping\"\n\n", (string) $data); + } + + + /** @test */ + public function it_can_create_a_simple_data_using_array() + { + $data = new Data(['ping' => 'foobar']); + + $this->assertSame("data: {\"ping\":\"foobar\"}\n\n", (string) $data); + } + + /** @test */ + public function it_can_create_a_simple_data_with_id() + { + $data = new Data('ping', 1); + + $this->assertSame("id: 1\ndata: \"ping\"\n\n", (string) $data); + } + + /** @test */ + public function it_can_create_a_simple_data_using_array_with_id() + { + $data = new Data(['ping' => 'foobar'], 2); + + $this->assertSame("id: 2\ndata: {\"ping\":\"foobar\"}\n\n", (string) $data); + } +} diff --git a/tests/Unit/EventTest.php b/tests/Unit/EventTest.php new file mode 100644 index 0000000..2d49c39 --- /dev/null +++ b/tests/Unit/EventTest.php @@ -0,0 +1,18 @@ +assertSame("event: ping\ndata: [\"pong\"]\n\n", (string) $event); + } +}