binaryResponsesIncludeExtraHeaders()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 6
dl 0
loc 10
rs 10
c 1
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace ShlinkioTest\Shlink\Common\Response;
6
7
use PHPUnit\Framework\TestCase;
8
use Shlinkio\Shlink\Common\Response\ResponseUtilsTrait;
9
10
class ResponseUtilsTraitTest extends TestCase
11
{
12
    use ResponseUtilsTrait;
13
14
    /**
15
     * @test
16
     * @dataProvider provideFiles
17
     */
18
    public function expectedBinaryResponsesAreGenerated(
19
        string $expectedType,
20
        string $expectedLength,
21
        string $path
22
    ): void {
23
        $this->assertExpectedResponseForMethod('generateBinaryResponse', $expectedType, $expectedLength, $path);
24
        $this->assertExpectedResponseForMethod('generateImageResponse', $expectedType, $expectedLength, $path);
25
    }
26
27
    public function provideFiles(): iterable
28
    {
29
        yield ['image/png', '2433', __DIR__ . '/../../test-resources/shlink-logo.png'];
30
        yield ['text/plain', '20', __DIR__ . '/../../test-resources/text-file.txt'];
31
    }
32
33
    private function assertExpectedResponseForMethod(
34
        string $method,
35
        string $expectedType,
36
        string $expectedLength,
37
        string $path
38
    ): void {
39
        $resp = $this->{$method}($path);
40
41
        $this->assertStringContainsString($expectedType, $resp->getHeaderLine('Content-Type'));
42
        $this->assertStringContainsString($expectedLength, $resp->getHeaderLine('Content-Length'));
43
    }
44
45
    /** @test */
46
    public function binaryResponsesIncludeExtraHeaders(): void
47
    {
48
        $resp = $this->generateBinaryResponse(__DIR__ . '/../../test-resources/shlink-logo.png', [
49
            'foo' => 'bar',
50
            'baz' => 'foo',
51
        ]);
52
        $headers = $resp->getHeaders();
53
54
        $this->assertArrayHasKey('foo', $headers);
55
        $this->assertArrayHasKey('baz', $headers);
56
    }
57
}
58