Completed
Pull Request — master (#260)
by Bogdan
14:16
created

JpegResponseTest   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 2
dl 0
loc 30
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A testDefaultParameters() 0 9 1
A testSetDifferentMimeType() 0 6 1
A testSetDifferentFileName() 0 10 1
1
<?php
2
3
/**
4
Deprecation Notice: Class Knp\Bundle\SnappyBundle\Tests\Snappy\LoggableGeneratorTest located in ./vendor/knplabs/knp-snappy-bundle/Tests/Snappy/Generator/LoggableGeneratorTest.php does not comply with psr-4 autoloading standard. It will not autoload anymore in Composer v2.0. in phar:///usr/bin/composer/src/Composer/Autoload/ClassMapGenerator.php:201
5
Deprecation Notice: Class Knp\Bundle\SnappyBundle\DependencyInjection\ConfigurationTest located in ./vendor/knplabs/knp-snappy-bundle/Tests/DependencyInjection/ConfigurationTest.php does not comply with psr-4 autoloading standard. It will not autoload anymore in Composer v2.0. in phar:///usr/bin/composer/src/Composer/Autoload/ClassMapGenerator.php:201
6
7
 */
8
9
namespace Knp\Bundle\SnappyBundle\Tests\Response\Snappy;
10
11
use Knp\Bundle\SnappyBundle\Snappy\Response\JpegResponse;
12
use PHPUnit\Framework\TestCase;
13
14
class JpegResponseTest extends TestCase
15
{
16
    public function testDefaultParameters()
17
    {
18
        $response = new JpegResponse('some_binary_output');
19
20
        $this->assertSame(200, $response->getStatusCode());
21
        $this->assertSame('some_binary_output', $response->getContent());
22
        $this->assertSame('image/jpg', $response->headers->get('Content-Type'));
23
        $this->assertSame('inline; filename=output.jpg', str_replace('"', '', $response->headers->get('Content-Disposition')));
24
    }
25
26
    public function testSetDifferentMimeType()
27
    {
28
        $response = new JpegResponse('some_binary_output', 'test.jpg', 'application/octet-stream');
29
30
        $this->assertSame('application/octet-stream', $response->headers->get('Content-Type'));
31
    }
32
33
    public function testSetDifferentFileName()
34
    {
35
        $fileName = 'test.jpg';
36
        $response = new JpegResponse('some_binary_output', $fileName);
37
        $fileNameFromDispositionRegex = '/.*filename=([^"]+)/';
38
39
        $this->assertSame(1, preg_match($fileNameFromDispositionRegex, str_replace('"', '', $response->headers->get('Content-Disposition')), $matches), 1);
40
41
        $this->assertSame($fileName, $matches[1]);
42
    }
43
}
44