Passed
Push — master ( 9013bb...125cf1 )
by Kirill
03:56
created

HeadersTest   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 67
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
eloc 31
c 1
b 0
f 0
dl 0
loc 67
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A testFetch() 0 11 1
A setUp() 0 4 1
A testFetchNoImplode() 0 15 1
A testHas() 0 9 1
A testShortcut() 0 8 1
1
<?php
2
3
/**
4
 * Spiral Framework.
5
 *
6
 * @license   MIT
7
 * @author    Anton Titov (Wolfy-J)
8
 */
9
10
declare(strict_types=1);
11
12
namespace Spiral\Tests\Http;
13
14
use PHPUnit\Framework\TestCase;
15
use Psr\Http\Message\ServerRequestInterface;
16
use Spiral\Core\Container;
17
use Spiral\Http\Request\InputManager;
18
use Laminas\Diactoros\ServerRequest;
19
20
class HeadersTest extends TestCase
21
{
22
    /**
23
     * @var Container
24
     */
25
    private $container;
26
27
    /**
28
     * @var InputManager
29
     */
30
    private $input;
31
32
    public function setUp(): void
33
    {
34
        $this->container = new Container();
35
        $this->input = new InputManager($this->container);
36
    }
37
38
    public function testShortcut(): void
39
    {
40
        $request = new ServerRequest();
41
42
        $request = $request->withAddedHeader('Path', 'value');
43
        $this->container->bind(ServerRequestInterface::class, $request);
0 ignored issues
show
Bug introduced by
$request of type Laminas\Diactoros\ServerRequest is incompatible with the type array|callable|string expected by parameter $resolver of Spiral\Core\Container::bind(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

43
        $this->container->bind(ServerRequestInterface::class, /** @scrutinizer ignore-type */ $request);
Loading history...
44
45
        $this->assertSame('value', $this->input->header('path'));
46
    }
47
48
    public function testHas(): void
49
    {
50
        $request = new ServerRequest();
51
52
        $request = $request->withAddedHeader('Path', 'value');
53
        $this->container->bind(ServerRequestInterface::class, $request);
0 ignored issues
show
Bug introduced by
$request of type Laminas\Diactoros\ServerRequest is incompatible with the type array|callable|string expected by parameter $resolver of Spiral\Core\Container::bind(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

53
        $this->container->bind(ServerRequestInterface::class, /** @scrutinizer ignore-type */ $request);
Loading history...
54
55
        $this->assertTrue($this->input->headers->has('path'));
56
        $this->assertTrue($this->input->headers->has('Path'));
57
    }
58
59
    public function testFetch(): void
60
    {
61
        $request = new ServerRequest();
62
63
        $request = $request->withAddedHeader('Path', 'value');
64
        $request = $request->withAddedHeader('Path', 'value2');
65
        $this->container->bind(ServerRequestInterface::class, $request);
0 ignored issues
show
Bug introduced by
$request of type Laminas\Diactoros\ServerRequest is incompatible with the type array|callable|string expected by parameter $resolver of Spiral\Core\Container::bind(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

65
        $this->container->bind(ServerRequestInterface::class, /** @scrutinizer ignore-type */ $request);
Loading history...
66
67
        $this->assertSame([
68
            'Path' => 'value,value2'
69
        ], $this->input->headers->fetch(['path']));
70
    }
71
72
    public function testFetchNoImplode(): void
73
    {
74
        $request = new ServerRequest();
75
76
        $request = $request->withAddedHeader('Path', 'value');
77
        $request = $request->withAddedHeader('Path', 'value2');
78
        $this->container->bind(ServerRequestInterface::class, $request);
0 ignored issues
show
Bug introduced by
$request of type Laminas\Diactoros\ServerRequest is incompatible with the type array|callable|string expected by parameter $resolver of Spiral\Core\Container::bind(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

78
        $this->container->bind(ServerRequestInterface::class, /** @scrutinizer ignore-type */ $request);
Loading history...
79
80
        $this->assertSame([
81
            'Path' => ['value', 'value2']
82
        ], $this->input->headers->fetch(['path'], false, true, null));
83
84
        $this->assertSame(
85
            ['value', 'value2'],
86
            $this->input->headers->get('path', null, false)
87
        );
88
    }
89
}
90