Completed
Push — master ( cbd317...231b94 )
by Henry
09:43
created

tests/phpunit/RequestTest.php (1 issue)

call_checks.maybe_mismatching_type_passed_with_def

Bug Minor

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
namespace Redaxscript\Tests;
3
4
/**
5
 * RequestTest
6
 *
7
 * @since 2.2.0
8
 *
9
 * @package Redaxscript
10
 * @category Tests
11
 * @author Henry Ruhs
12
 *
13
 * @covers Redaxscript\Request
14
 */
15
16
class RequestTest extends TestCaseAbstract
17
{
18
	/**
19
	 * testInit
20
	 *
21
	 * @since 3.0.0
22
	 */
23
24
	public function testInit()
25
	{
26
		/* setup */
27
28
		$this->_request->init();
29
30
		/* actual */
31
32
		$actual = $this->_request;
33
34
		/* compare */
35
36
		$this->assertInstanceOf('Redaxscript\Request', $actual);
37
	}
38
39
	/**
40
	 * testAll
41
	 *
42
	 * @since 2.2.0
43
	 */
44
45
	public function testAll()
46
	{
47
		/* actual */
48
49
		$actualArray = $this->_request->get();
50
51
		/* compare */
52
53
		$this->assertArrayHasKey('server', $actualArray);
0 ignored issues
show
It seems like $actualArray defined by $this->_request->get() on line 49 can also be of type null or string; however, PHPUnit\Framework\Assert::assertArrayHasKey() does only seem to accept array|object<ArrayAccess>, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
54
	}
55
56
	/**
57
	 * testGlobal
58
	 *
59
	 * @since 2.2.0
60
	 */
61
62
	public function testGlobal()
63
	{
64
		/* setup */
65
66
		$this->_request->set('testKey', 'testValue');
67
68
		/* actual */
69
70
		$actual = $this->_request->get('testKey');
71
72
		/* compare */
73
74
		$this->assertEquals('testValue', $actual);
75
	}
76
77
	/**
78
	 * testServer
79
	 *
80
	 * @since 2.2.0
81
	 */
82
83
	public function testServer()
84
	{
85
		/* setup */
86
87
		$this->_request->setServer('testKey', 'testValue');
88
89
		/* actual */
90
91
		$actual = $this->_request->getServer('testKey');
92
93
		/* compare */
94
95
		$this->assertEquals('testValue', $actual);
96
	}
97
98
	/**
99
	 * testQuery
100
	 *
101
	 * @since 2.2.0
102
	 */
103
104
	public function testQuery()
105
	{
106
		/* setup */
107
108
		$this->_request->setQuery('testKey', 'testValue');
109
110
		/* actual */
111
112
		$actual = $this->_request->getQuery('testKey');
113
114
		/* compare */
115
116
		$this->assertEquals('testValue', $actual);
117
	}
118
119
	/**
120
	 * testPost
121
	 *
122
	 * @since 2.2.0
123
	 */
124
125
	public function testPost()
126
	{
127
		/* setup */
128
129
		$this->_request->setPost('testKey', 'testValue');
130
131
		/* actual */
132
133
		$actual = $this->_request->getPost('testKey');
134
135
		/* compare */
136
137
		$this->assertEquals('testValue', $actual);
138
	}
139
140
	/**
141
	 * testFiles
142
	 *
143
	 * @since 3.9.0
144
	 */
145
146
	public function testFiles()
147
	{
148
		/* setup */
149
150
		$this->_request->setFiles('testKey', 'testValue');
151
152
		/* actual */
153
154
		$actual = $this->_request->getFiles('testKey');
155
156
		/* compare */
157
158
		$this->assertEquals('testValue', $actual);
159
	}
160
161
	/**
162
	 * testSession
163
	 *
164
	 * @since 2.6.2
165
	 */
166
167
	public function testSession()
168
	{
169
		/* setup */
170
171
		$this->_request->setSession('testKey', 'testValue');
172
		$this->_request->refreshSession();
173
174
		/* actual */
175
176
		$actual = $this->_request->getSession('testKey');
177
178
		/* compare */
179
180
		$this->assertEquals('testValue', $actual);
181
	}
182
183
	/**
184
	 * testCookie
185
	 *
186
	 * @since 2.6.2
187
	 */
188
189
	public function testCookie()
190
	{
191
		/* setup */
192
193
		$this->_request->setCookie('testKey', 'testValue');
194
		$this->_request->refreshCookie();
195
196
		/* actual */
197
198
		$actual = $this->_request->getCookie('testKey');
199
200
		/* compare */
201
202
		$this->assertEquals('testValue', $actual);
203
	}
204
205
	/**
206
	 * testGetInvalid
207
	 *
208
	 * @since 3.0.0
209
	 */
210
211
	public function testGetInvalid()
212
	{
213
		/* actual */
214
215
		$actual = $this->_request->get('invalidKey');
216
217
		/* compare */
218
219
		$this->assertNull($actual);
220
	}
221
}
222