1
0
mirror of https://github.com/danog/byte-stream.git synced 2024-11-26 20:04:51 +01:00
byte-stream/test/ResourceStreamTest.php
2017-06-18 20:16:05 +02:00

33 lines
917 B
PHP

<?php
namespace Amp\ByteStream\Test;
use Amp\ByteStream\ResourceInputStream;
use Amp\ByteStream\ResourceOutputStream;
use Amp\Loop;
use PHPUnit\Framework\TestCase;
class ResourceStreamTest extends TestCase {
public function testLargePayloads() {
Loop::run(function () {
$domain = \stripos(PHP_OS, "win") === 0 ? STREAM_PF_INET : STREAM_PF_UNIX;
list($left, $right) = @\stream_socket_pair($domain, \STREAM_SOCK_STREAM, \STREAM_IPPROTO_IP);
$a = new ResourceOutputStream($left);
$b = new ResourceInputStream($right);
$length = 1 * 1024 * 1024; // 1M
$message = \str_repeat(".", $length);
$a->end($message);
$received = "";
while (null !== $chunk = yield $b->read()) {
$received .= $chunk;
}
$this->assertSame($message, $received);
});
}
}