read()) !== null) { yield $outputStream->write($chunk); } yield $outputStream->end(); $inputStream = new ZlibInputStream(new InMemoryStream(yield $bufferStream), \ZLIB_ENCODING_GZIP); $buffer = ""; while (($chunk = yield $inputStream->read()) !== null) { $buffer .= $chunk; } $this->assertSame(\file_get_contents($file1), $buffer); }); } public function testThrowsOnWritingToClosedContext() { $this->expectException(ClosedException::class); Loop::run(function () { $gzStream = new ZlibOutputStream(new OutputBuffer(), \ZLIB_ENCODING_GZIP); $gzStream->end("foo"); $gzStream->write("bar"); }); } public function testThrowsOnEndingToClosedContext() { $this->expectException(ClosedException::class); Loop::run(function () { $gzStream = new ZlibOutputStream(new OutputBuffer(), \ZLIB_ENCODING_GZIP); $gzStream->end("foo"); $gzStream->end("bar"); }); } public function testGetEncoding() { $gzStream = new ZlibOutputStream(new OutputBuffer(), \ZLIB_ENCODING_GZIP); $this->assertSame(\ZLIB_ENCODING_GZIP, $gzStream->getEncoding()); } public function testInvalidEncoding() { $this->expectException(StreamException::class); new ZlibOutputStream(new OutputBuffer(), 1337); } public function testGetOptions() { $options = [ "level" => -1, "memory" => 8, "window" => 15, "strategy" => \ZLIB_DEFAULT_STRATEGY, ]; $gzStream = new ZlibOutputStream(new OutputBuffer(), \ZLIB_ENCODING_GZIP, $options); $this->assertSame($options, $gzStream->getOptions()); } public function testInvalidOptions() { $this->expectException(StreamException::class); new ZlibOutputStream(new OutputBuffer(), \ZLIB_ENCODING_GZIP, ["level" => 42]); } }