Passed
Push — develop ( 6e78c9...4aabf2 )
by Stan
04:01 queued 22s
created

ResponseTest   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 3
dl 0
loc 40
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A it_should_add_a_link_header_and_cookie_when_given_pushable_resources() 0 11 1
A it_should_not_add_a_link_header_or_cookie_without_pushable_resources() 0 8 1
A setUp() 0 5 1
1
<?php
2
3
use Krenor\Http2Pusher\Response;
0 ignored issues
show
Bug introduced by
This use statement conflicts with another class in this namespace, Response. Consider defining an alias.

Let?s assume that you have a directory layout like this:

.
|-- OtherDir
|   |-- Bar.php
|   `-- Foo.php
`-- SomeDir
    `-- Foo.php

and let?s assume the following content of Bar.php:

// Bar.php
namespace OtherDir;

use SomeDir\Foo; // This now conflicts the class OtherDir\Foo

If both files OtherDir/Foo.php and SomeDir/Foo.php are loaded in the same runtime, you will see a PHP error such as the following:

PHP Fatal error:  Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php

However, as OtherDir/Foo.php does not necessarily have to be loaded and the error is only triggered if it is loaded before OtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias:

// Bar.php
namespace OtherDir;

use SomeDir\Foo as SomeDirFoo; // There is no conflict anymore.
Loading history...
4
use Krenor\Http2Pusher\Tests\TestCase;
5
6
class ResponseTest extends TestCase
7
{
8
    /**
9
     * @var Response
10
     */
11
    private $response;
12
13
    /**
14
     * Bootstrap the test environment.
15
     */
16
    public function setUp()
17
    {
18
        parent::setUp();
19
20
        $this->response = new Response();
21
    }
22
23
    /** @test */
24
    public function it_should_not_add_a_link_header_or_cookie_without_pushable_resources()
25
    {
26
        $this->response->pushes($this->builder, $this->nonPushable);
27
28
        $headers = $this->response->headers;
29
30
        $this->assertFalse($headers->has('Link'));
31
        $this->assertCount(0, $headers->getCookies());
32
    }
33
34
    /** @test */
35
    public function it_should_add_a_link_header_and_cookie_when_given_pushable_resources()
36
    {
37
        $this->response->pushes($this->builder, $this->pushable);
38
39
        $headers = $this->response->headers;
40
41
        $this->assertTrue($headers->has('Link'));
42
        $this->assertCount(1, $headers->getCookies());
43
        $this->assertSame(
44
            $this->builderSettings['cookie']['name'],
45
            $headers->getCookies()[0]->getName()
46
        );
47
    }
48
}
49