2017-12-14 06:06:38 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Amp\Parallel\Test\Sync;
|
|
|
|
|
2019-08-27 19:17:41 +02:00
|
|
|
use Amp\Parallel\Sync\ChannelException;
|
2017-12-14 06:06:38 +01:00
|
|
|
use Amp\Parallel\Sync\ChannelParser;
|
2019-08-27 19:17:41 +02:00
|
|
|
use Amp\Parallel\Sync\SerializationException;
|
|
|
|
use Amp\PHPUnit\AsyncTestCase;
|
2017-12-14 06:06:38 +01:00
|
|
|
|
2019-08-27 19:17:41 +02:00
|
|
|
class ChannelParserTest extends AsyncTestCase
|
2018-10-07 16:50:45 +02:00
|
|
|
{
|
|
|
|
public function testCorruptedData()
|
|
|
|
{
|
2019-08-27 19:17:41 +02:00
|
|
|
$this->expectException(SerializationException::class);
|
|
|
|
$this->expectExceptionMessage('Exception thrown when unserializing data');
|
|
|
|
|
2017-12-14 06:06:38 +01:00
|
|
|
$data = "Invalid serialized data";
|
|
|
|
$data = \pack("CL", 0, \strlen($data)) . $data;
|
|
|
|
$parser = new ChannelParser($this->createCallback(0));
|
|
|
|
$parser->push($data);
|
|
|
|
}
|
2018-01-22 23:12:55 +01:00
|
|
|
|
2018-10-07 16:50:45 +02:00
|
|
|
public function testInvalidHeaderData()
|
|
|
|
{
|
2019-08-27 19:17:41 +02:00
|
|
|
$this->expectException(ChannelException::class);
|
|
|
|
$this->expectExceptionMessage('Invalid packet received: Invalid packet');
|
|
|
|
|
2018-01-22 23:12:55 +01:00
|
|
|
$data = "Invalid packet";
|
|
|
|
$parser = new ChannelParser($this->createCallback(0));
|
|
|
|
$parser->push($data);
|
|
|
|
}
|
|
|
|
|
2018-10-07 16:50:45 +02:00
|
|
|
public function testInvalidHeaderBinaryData()
|
|
|
|
{
|
2019-08-27 19:17:41 +02:00
|
|
|
$this->expectException(ChannelException::class);
|
|
|
|
$this->expectExceptionMessage('Invalid packet received: B \xf3\xf2\x0\x1');
|
|
|
|
|
2018-01-22 23:12:55 +01:00
|
|
|
$data = "\x42\x20\xf3\xf2\x00\x01";
|
|
|
|
$parser = new ChannelParser($this->createCallback(0));
|
|
|
|
$parser->push($data);
|
|
|
|
}
|
2017-12-14 06:06:38 +01:00
|
|
|
}
|