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

ResponseTest::setUp()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 5
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
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