forked from phpro/http-tools
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHashExtractorTest.php
More file actions
57 lines (46 loc) · 1.53 KB
/
HashExtractorTest.php
File metadata and controls
57 lines (46 loc) · 1.53 KB
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
53
54
55
56
57
<?php
declare(strict_types=1);
namespace Phpro\HttpTools\Tests\Unit\Encoding\Binary\Extractor;
use Phpro\HttpTools\Encoding\Binary\Extractor\HashExtractor;
use Phpro\HttpTools\Test\UseHttpFactories;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\Attributes\Test;
use PHPUnit\Framework\TestCase;
use Psl\Hash\Algorithm;
use function Psl\Hash\hash;
use Psr\Http\Message\ResponseInterface;
final class HashExtractorTest extends TestCase
{
use UseHttpFactories;
#[DataProvider('provideCases')]
#[Test]
public function it_can_extract_hash(ResponseInterface $response, string $expected, int $endPosition = 0): void
{
$extractor = new HashExtractor(Algorithm::Md5);
$actual = $extractor($response);
self::assertSame($actual, $expected);
self::assertSame($endPosition, $response->getBody()->tell());
}
public static function provideCases(): iterable
{
yield 'from-empty-stream-size' => [
self::createResponse(),
hash('', Algorithm::Md5),
];
yield 'from-stream-size' => [
self::createResponse()
->withBody(
self::createStream('12345')
),
hash('12345', Algorithm::Md5),
];
$stream = self::createStream('12345');
$stream->seek(3);
yield 'from-partially-read-stream' => [
self::createResponse()
->withBody($stream),
hash('12345', Algorithm::Md5),
3,
];
}
}