Skip to content

Commit

Permalink
Improves tests.
Browse files Browse the repository at this point in the history
Signed-off-by: Mior Muhammad Zaki <crynobone@gmail.com>
  • Loading branch information
crynobone committed Feb 19, 2020
1 parent dce0b5c commit e5b2cb5
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 26 deletions.
39 changes: 13 additions & 26 deletions tests/Feature/MakeRequestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand All @@ -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')
Expand All @@ -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')
Expand All @@ -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')
Expand Down
42 changes: 42 additions & 0 deletions tests/Unit/DataTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php

namespace Laravie\Prefetch\Tests\Unit;

use Katsana\Prefetch\Data;
use PHPUnit\Framework\TestCase;

class DataTest extends TestCase
{
/** @test */
public function it_can_create_a_simple_data()
{
$data = new Data('ping');

$this->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);
}
}
18 changes: 18 additions & 0 deletions tests/Unit/EventTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

namespace Laravie\Prefetch\Tests\Unit;

use Katsana\Prefetch\Data;
use Katsana\Prefetch\Event;
use PHPUnit\Framework\TestCase;

class EventTest extends TestCase
{
/** @test */
public function it_can_create_a_simple_event()
{
$event = new Event('ping', Data::make(['pong']));

$this->assertSame("event: ping\ndata: [\"pong\"]\n\n", (string) $event);
}
}

0 comments on commit e5b2cb5

Please sign in to comment.