testHtmlResponseIsCompressed()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 7
Ratio 100 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 7
loc 7
rs 9.4285
cc 1
eloc 4
nc 1
nop 0
1
<?php
2
3
namespace SteffenBrand\HtmlCompressMiddleware\Test;
4
5
use PHPUnit\Framework\TestCase;
6
use SteffenBrand\HtmlCompressMiddleware\HtmlCompressMiddlewareFactory;
7
use SteffenBrand\HtmlCompressMiddleware\Test\Mock\MockContainer;
8
use SteffenBrand\HtmlCompressMiddleware\Test\Mock\MockRequestHandler;
9
use Zend\Diactoros\ServerRequest;
10
use Zend\Diactoros\Stream;
11
12
/**
13
 * Class HtmlCompressMiddlewareTest
14
 * @package SteffenBrand\HtmlCompressMiddleware\Test
15
 */
16
class HtmlCompressMiddlewareTest extends TestCase
17
{
18
    /**
19
     * @var ServerRequest
20
     */
21
    private $request;
22
23
    public function setUp()
24
    {
25
        $this->request = new ServerRequest();
26
        $this->request = $this->request->withBody(new Stream(fopen('data:text/plain,' . 'test' . PHP_EOL . 'test', 'rb')));
27
    }
28
29
    /**
30
     * @throws \Psr\Container\ContainerExceptionInterface
31
     * @throws \Psr\Container\NotFoundExceptionInterface
32
     */
33 View Code Duplication
    public function testHtmlResponseIsCompressed(): void
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
34
    {
35
        $middleware = (new HtmlCompressMiddlewareFactory())->__invoke(new MockContainer(false));
36
        $response = $middleware->process($this->request, new MockRequestHandler('text/html'));
37
38
        $this->assertEquals('test test', $response->getBody()->getContents());
39
    }
40
41
    /**
42
     * @throws \Psr\Container\ContainerExceptionInterface
43
     * @throws \Psr\Container\NotFoundExceptionInterface
44
     */
45 View Code Duplication
    public function testJsonResponseIsNotCompressed(): void
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
46
    {
47
        $middleware = (new HtmlCompressMiddlewareFactory())->__invoke(new MockContainer(false));
48
        $response = $middleware->process($this->request, new MockRequestHandler('application/json'));
49
50
        $this->assertEquals('test' . PHP_EOL . 'test', $response->getBody()->getContents());
51
    }
52
53
    /**
54
     * @throws \Psr\Container\ContainerExceptionInterface
55
     * @throws \Psr\Container\NotFoundExceptionInterface
56
     */
57 View Code Duplication
    public function testDebugHtmlResponseIsNotCompressed(): void
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
58
    {
59
        $middleware = (new HtmlCompressMiddlewareFactory())->__invoke(new MockContainer(true));
60
        $response = $middleware->process($this->request, new MockRequestHandler('text/html'));
61
62
        $this->assertEquals('test' . PHP_EOL . 'test', $response->getBody()->getContents());
63
    }
64
}