Skip to content

Commit

Permalink
Add basic zlib input stream test
Browse files Browse the repository at this point in the history
  • Loading branch information
kelunik committed May 17, 2017
1 parent 9e90d1f commit 34a571c
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 0 deletions.
44 changes: 44 additions & 0 deletions test/ZlibInputStreamTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php

namespace Amp\ByteStream\Test;

use Amp\ByteStream\InMemoryStream;
use Amp\ByteStream\IteratorStream;
use Amp\ByteStream\ZlibInputStream;
use Amp\Delayed;
use Amp\Loop;
use Amp\PHPUnit\TestCase;
use Amp\Producer;

class ZlibInputStreamTest extends TestCase {
public function testRead() {
Loop::run(function () {
$file1 = __DIR__ . "/fixtures/foobar.txt";
$file2 = __DIR__ . "/fixtures/foobar.txt.gz";

$stream = new IteratorStream(new Producer(function (callable $emit) use ($file2) {
$content = \file_get_contents($file2);

while ($content !== "") {
yield $emit($content[0]);
$content = \substr($content, 1);
}
}));

$gzStream = new ZlibInputStream($stream, \ZLIB_ENCODING_GZIP);

$buffer = "";
while (($chunk = yield $gzStream->read()) !== null) {
$buffer .= $chunk;
}

$this->assertSame(\file_get_contents($file1), $buffer);
});
}

public function testInvalidEncoding() {
$this->expectException(\Error::class);

new ZlibInputStream(new InMemoryStream(""), 1337);
}
}
1 change: 1 addition & 0 deletions test/fixtures/foobar.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
foobar content

0 comments on commit 34a571c

Please sign in to comment.