45 lines
1.3 KiB
PHP
45 lines
1.3 KiB
PHP
<?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);
|
|
}
|
|
} |