1
0
mirror of https://github.com/danog/parallel.git synced 2024-12-12 09:09:35 +01:00
parallel/test/Sync/ChannelParserTest.php

43 lines
1.3 KiB
PHP
Raw Normal View History

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-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');
$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');
$data = "\x42\x20\xf3\xf2\x00\x01";
$parser = new ChannelParser($this->createCallback(0));
$parser->push($data);
}
2017-12-14 06:06:38 +01:00
}