-
Notifications
You must be signed in to change notification settings - Fork 1.2k
/
Copy pathHashingStreamTest.php
52 lines (45 loc) · 1.36 KB
/
HashingStreamTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
<?php
namespace Aws\Test;
use GuzzleHttp\Psr7;
use Aws\PhpHash;
use Aws\HashingStream;
use PHPUnit\Framework\TestCase;
/**
* @covers Aws\HashingStream
*/
class HashingStreamTest extends TestCase
{
public function testCanCreateRollingMd5()
{
$source = Psr7\Utils::streamFor('foobar');
$hash = new PhpHash('md5');
(new HashingStream($source, $hash))->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);
}
}