Initial commit
This commit is contained in:
45
tests/Line/HttpLikeProtocolTest.php
Normal file
45
tests/Line/HttpLikeProtocolTest.php
Normal file
@@ -0,0 +1,45 @@
|
||||
<?php
|
||||
|
||||
namespace NoccyLabs\React\Protocol\Line;
|
||||
|
||||
use PHPUnit\Framework\Attributes\CoversClass;
|
||||
use React\Stream\CompositeStream;
|
||||
use React\Stream\ThroughStream;
|
||||
|
||||
#[CoversClass(HttpLikeProtocol::class)]
|
||||
class HttpLikeProtocolTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
|
||||
public function testPackingFrames()
|
||||
{
|
||||
$proto = new HttpLikeProtocol(
|
||||
lineSeparator: "\n"
|
||||
);
|
||||
$packed = $proto->packFrame(['query' => 'GET / HTTP/1.1', 'headers' => [ 'foo' => [ 'bar' ]]]);
|
||||
$this->assertEquals("GET / HTTP/1.1\nfoo: bar\n\n", $packed);
|
||||
}
|
||||
|
||||
public function testUnpackingFrames()
|
||||
{
|
||||
$proto = new HttpLikeProtocol(
|
||||
lineSeparator: "\n"
|
||||
);
|
||||
|
||||
$msg1 = $proto->unpackFrame("GET / HTTP/1.1\nfoo: bar\n\n");
|
||||
$this->assertEquals(['query' => 'GET / HTTP/1.1', 'headers' => [ 'foo' => [ 'bar' ]]], $msg1);
|
||||
}
|
||||
|
||||
public function testConsumingFrames()
|
||||
{
|
||||
$proto = new HttpLikeProtocol(
|
||||
lineSeparator: "\n"
|
||||
);
|
||||
|
||||
$buffer = "GET / HTTP/1.1\nfoo: bar\n\n";
|
||||
$msg1 = $proto->consumeFrame($buffer);
|
||||
// $msg2 = $proto->consumeFrame($buffer);
|
||||
|
||||
$this->assertEquals(['query' => 'GET / HTTP/1.1', 'headers' => [ 'foo' => [ 'bar' ]]], $msg1);
|
||||
// $this->assertEquals(['bar','false'], $msg2);
|
||||
}
|
||||
}
|
||||
33
tests/Line/LineProtocolTest.php
Normal file
33
tests/Line/LineProtocolTest.php
Normal file
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
namespace NoccyLabs\React\Protocol\Line;
|
||||
|
||||
use PHPUnit\Framework\Attributes\CoversClass;
|
||||
use React\Stream\CompositeStream;
|
||||
use React\Stream\ThroughStream;
|
||||
|
||||
#[CoversClass(LineProtocol::class)]
|
||||
class LineProtocolTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
|
||||
public function testFrameSeparators()
|
||||
{
|
||||
$proto = new LineProtocol("\n");
|
||||
$packed = $proto->packFrame(['foo', 'bar']);
|
||||
$this->assertEquals("foo bar\n", $packed);
|
||||
}
|
||||
|
||||
public function testConsumingFrames()
|
||||
{
|
||||
$proto = new LineProtocol(
|
||||
lineBreak: "\n"
|
||||
);
|
||||
|
||||
$buffer = "foo true\nbar false\n";
|
||||
$msg1 = $proto->consumeFrame($buffer);
|
||||
$msg2 = $proto->consumeFrame($buffer);
|
||||
|
||||
$this->assertEquals(['foo','true'], $msg1);
|
||||
$this->assertEquals(['bar','false'], $msg2);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user