getContents(); $this->assertSame(md5('foobar'), bin2hex($hash->complete())); } public function testCallbackTriggeredWhenComplete() { $source = Psr7\Utils::streamFor('foobar'); $hash = new PhpHash('md5'); $called = false; $stream = new HashingStream($source, $hash, function () use (&$called) { $called = true; }); $stream->getContents(); $this->assertTrue($called); } public function testCanOnlySeekToTheBeginning() { $source = Psr7\Utils::streamFor('foobar'); $hash = new PhpHash('md5'); $stream = new HashingStream($source, $hash); // Reading works fine $bytes = $stream->read(3); $this->assertSame('foo', $bytes); // Seeking to 0 is fine $stream->seek(0); $stream->getContents(); $this->assertSame(md5('foobar'), bin2hex($hash->complete())); // Seeking arbitrarily is not fine $stream->seek(3); } }