forked from phpro/http-tools
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExtensionExtractorTest.php
More file actions
55 lines (48 loc) · 1.61 KB
/
ExtensionExtractorTest.php
File metadata and controls
55 lines (48 loc) · 1.61 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
<?php
declare(strict_types=1);
namespace Phpro\HttpTools\Tests\Unit\Encoding\Binary\Extractor;
use Phpro\HttpTools\Encoding\Binary\Extractor\ExtensionExtractor;
use Phpro\HttpTools\Test\UseHttpFactories;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\Attributes\Test;
use PHPUnit\Framework\TestCase;
use Psr\Http\Message\ResponseInterface;
final class ExtensionExtractorTest extends TestCase
{
use UseHttpFactories;
#[DataProvider('provideCases')]
#[Test]
public function it_can_extract_extension(ResponseInterface $response, ?string $expected): void
{
$extractor = new ExtensionExtractor();
$actual = $extractor($response);
self::assertSame($actual, $expected);
}
public static function provideCases(): iterable
{
yield 'from-valid-content-type' => [
self::createResponse()
->withHeader('Content-Type', 'image/jpeg'),
'jpg',
];
yield 'from-invalid-content-type' => [
self::createResponse()
->withHeader('Content-Type', ['unknown/unkown']),
null,
];
yield 'filename-with-extension' => [
self::createResponse()
->withHeader('Content-Disposition', 'attachment; filename="hello.jpg"'),
'jpg',
];
yield 'filename-without-extension-mime-type' => [
self::createResponse()
->withHeader('Content-Disposition', 'attachment; filename="hello"'),
null,
];
yield 'none' => [
self::createResponse(),
null,
];
}
}