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

ServerTest::testUnsetAndExceptions()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 5
c 1
b 0
f 0
dl 0
loc 10
rs 10
cc 1
nc 1
nop 0
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\Exception\InputException;
18
use Spiral\Http\Request\InputManager;
19
use Laminas\Diactoros\ServerRequest;
20
21
class ServerTest extends TestCase
22
{
23
    /**
24
     * @var Container
25
     */
26
    private $container;
27
28
    /**
29
     * @var InputManager
30
     */
31
    private $input;
32
33
    public function setUp(): void
34
    {
35
        $this->container = new Container();
36
        $this->input = new InputManager($this->container);
37
    }
38
39
    public function testShortcut(): void
40
    {
41
        $request = new ServerRequest(
42
            ['PATH' => 'sample']
43
        );
44
45
        $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

45
        $this->container->bind(ServerRequestInterface::class, /** @scrutinizer ignore-type */ $request);
Loading history...
46
47
        $this->assertSame('sample', $this->input->server('path'));
48
    }
49
50
    public function testHas(): void
51
    {
52
        $request = new ServerRequest(
53
            ['PATH' => 'sample']
54
        );
55
56
        $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

56
        $this->container->bind(ServerRequestInterface::class, /** @scrutinizer ignore-type */ $request);
Loading history...
57
58
        $this->assertTrue($this->input->server->has('path'));
59
        $this->assertFalse($this->input->server->has('another'));
60
        $this->assertTrue($this->input->server->has('path'));
61
    }
62
63
    public function testGet(): void
64
    {
65
        $request = new ServerRequest(
66
            ['PATH' => 'sample']
67
        );
68
69
        $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

69
        $this->container->bind(ServerRequestInterface::class, /** @scrutinizer ignore-type */ $request);
Loading history...
70
71
        $this->assertSame('sample', $this->input->server->get('path'));
72
        $this->assertSame(null, $this->input->server->get('other'));
73
    }
74
75
    public function testGetDot(): void
76
    {
77
        $request = new ServerRequest(
78
            ['PATH' => ['SAMPLE' => 1]]
79
        );
80
81
        $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

81
        $this->container->bind(ServerRequestInterface::class, /** @scrutinizer ignore-type */ $request);
Loading history...
82
83
        $this->assertSame(1, $this->input->server->get('path.SAMPLE'));
84
        $this->assertSame(null, $this->input->server->get('path.another'));
85
    }
86
87
    public function testAll(): void
88
    {
89
        $request = new ServerRequest(
90
            ['PATH' => 'sample']
91
        );
92
93
        $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

93
        $this->container->bind(ServerRequestInterface::class, /** @scrutinizer ignore-type */ $request);
Loading history...
94
95
        $this->assertSame([
96
            'PATH' => 'sample',
97
        ], $this->input->server->all());
98
    }
99
100
    public function testServerBagFetchNoFill(): void
101
    {
102
        $request = new ServerRequest(
103
            ['PATH' => 'sample']
104
        );
105
106
        $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

106
        $this->container->bind(ServerRequestInterface::class, /** @scrutinizer ignore-type */ $request);
Loading history...
107
108
        $this->assertSame([
109
            'PATH' => 'sample',
110
        ], $this->input->server->all());
111
112
        $this->assertSame([
113
            'PATH' => 'sample',
114
        ], $this->input->server->fetch(['path']));
115
    }
116
117
    public function testServerBagFetchAndFill(): void
118
    {
119
        $request = new ServerRequest(
120
            ['PATH' => 'sample']
121
        );
122
123
        $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

123
        $this->container->bind(ServerRequestInterface::class, /** @scrutinizer ignore-type */ $request);
Loading history...
124
125
        $this->assertSame([
126
            'PATH' => 'sample',
127
        ], $this->input->server->fetch(['path'], true, null));
128
129
        $this->assertSame(
130
            ['PATH' => 'sample', 'OTHER' => null],
131
            $this->input->server->fetch(['path', 'other'], true, null)
132
        );
133
    }
134
135
    public function testServerBagCount(): void
136
    {
137
        $request = new ServerRequest(
138
            ['PATH' => 'sample']
139
        );
140
141
        $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

141
        $this->container->bind(ServerRequestInterface::class, /** @scrutinizer ignore-type */ $request);
Loading history...
142
143
        $this->assertSame(1, $this->input->server->count());
144
    }
145
146
    public function testServerBagArrayAccess(): void
147
    {
148
        $request = new ServerRequest(
149
            ['PATH' => 'sample']
150
        );
151
152
        $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

152
        $this->container->bind(ServerRequestInterface::class, /** @scrutinizer ignore-type */ $request);
Loading history...
153
154
        $this->assertSame('sample', $this->input->server['path']);
155
        $this->assertFalse(isset($this->input->server['other']));
156
    }
157
158
    public function testDebugInfo(): void
159
    {
160
        $request = new ServerRequest(
161
            ['PATH' => 'sample']
162
        );
163
164
        $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

164
        $this->container->bind(ServerRequestInterface::class, /** @scrutinizer ignore-type */ $request);
Loading history...
165
166
        $this->assertSame(
167
            ['PATH' => 'sample',],
168
            $this->input->server->__debugInfo()
169
        );
170
    }
171
172
    public function testIterator(): void
173
    {
174
        $request = new ServerRequest(
175
            ['PATH' => 'sample']
176
        );
177
178
        $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

178
        $this->container->bind(ServerRequestInterface::class, /** @scrutinizer ignore-type */ $request);
Loading history...
179
180
        $this->assertSame(
181
            ['PATH' => 'sample',],
182
            iterator_to_array($this->input->server)
183
        );
184
    }
185
186
    public function testSetAndExceptions(): void
187
    {
188
        $this->expectException(InputException::class);
189
190
        $request = new ServerRequest(
191
            ['PATH' => 'sample']
192
        );
193
194
        $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

194
        $this->container->bind(ServerRequestInterface::class, /** @scrutinizer ignore-type */ $request);
Loading history...
195
        $this->input->server->offsetSet('a', 'value');
196
    }
197
198
    public function testUnsetAndExceptions(): void
199
    {
200
        $this->expectException(InputException::class);
201
202
        $request = new ServerRequest(
203
            ['PATH' => 'sample']
204
        );
205
206
        $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

206
        $this->container->bind(ServerRequestInterface::class, /** @scrutinizer ignore-type */ $request);
Loading history...
207
        $this->input->server->offsetUnset('a');
208
    }
209
}
210