GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Passed
Push — master ( 5cefd1...492078 )
by Anton
04:08
created

FunctionsTest::testReturnsCustomMetadata()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 3
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 5
rs 10
1
<?php
2
namespace RingCentral\Tests\Psr7;
3
4
use RingCentral\Psr7;
5
use RingCentral\Psr7\FnStream;
6
use RingCentral\Psr7\NoSeekStream;
7
8
class FunctionsTest extends \PHPUnit_Framework_TestCase
0 ignored issues
show
Bug introduced by
The type PHPUnit_Framework_TestCase was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
9
{
10
    public function testCopiesToString()
11
    {
12
        $s = Psr7\stream_for('foobaz');
0 ignored issues
show
Bug introduced by
The function stream_for was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

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

12
        $s = /** @scrutinizer ignore-call */ Psr7\stream_for('foobaz');
Loading history...
13
        $this->assertEquals('foobaz', Psr7\copy_to_string($s));
0 ignored issues
show
Bug introduced by
The function copy_to_string was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

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

13
        $this->assertEquals('foobaz', /** @scrutinizer ignore-call */ Psr7\copy_to_string($s));
Loading history...
14
        $s->seek(0);
15
        $this->assertEquals('foo', Psr7\copy_to_string($s, 3));
16
        $this->assertEquals('baz', Psr7\copy_to_string($s, 3));
17
        $this->assertEquals('', Psr7\copy_to_string($s));
18
    }
19
20
    public function testCopiesToStringStopsWhenReadFails()
21
    {
22
        $s1 = Psr7\stream_for('foobaz');
0 ignored issues
show
Bug introduced by
The function stream_for was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

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

22
        $s1 = /** @scrutinizer ignore-call */ Psr7\stream_for('foobaz');
Loading history...
23
        $s1 = FnStream::decorate($s1, array(
24
            'read' => function () { return ''; }
25
        ));
26
        $result = Psr7\copy_to_string($s1);
0 ignored issues
show
Bug introduced by
The function copy_to_string was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

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

26
        $result = /** @scrutinizer ignore-call */ Psr7\copy_to_string($s1);
Loading history...
27
        $this->assertEquals('', $result);
28
    }
29
30
    public function testCopiesToStream()
31
    {
32
        $s1 = Psr7\stream_for('foobaz');
0 ignored issues
show
Bug introduced by
The function stream_for was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

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

32
        $s1 = /** @scrutinizer ignore-call */ Psr7\stream_for('foobaz');
Loading history...
33
        $s2 = Psr7\stream_for('');
34
        Psr7\copy_to_stream($s1, $s2);
0 ignored issues
show
Bug introduced by
The function copy_to_stream was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

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

34
        /** @scrutinizer ignore-call */ 
35
        Psr7\copy_to_stream($s1, $s2);
Loading history...
35
        $this->assertEquals('foobaz', (string) $s2);
36
        $s2 = Psr7\stream_for('');
37
        $s1->seek(0);
38
        Psr7\copy_to_stream($s1, $s2, 3);
39
        $this->assertEquals('foo', (string) $s2);
40
        Psr7\copy_to_stream($s1, $s2, 3);
41
        $this->assertEquals('foobaz', (string) $s2);
42
    }
43
44
    public function testStopsCopyToStreamWhenWriteFails()
45
    {
46
        $s1 = Psr7\stream_for('foobaz');
0 ignored issues
show
Bug introduced by
The function stream_for was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

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

46
        $s1 = /** @scrutinizer ignore-call */ Psr7\stream_for('foobaz');
Loading history...
47
        $s2 = Psr7\stream_for('');
48
        $s2 = FnStream::decorate($s2, array('write' => function () { return 0; }));
49
        Psr7\copy_to_stream($s1, $s2);
0 ignored issues
show
Bug introduced by
The function copy_to_stream was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

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

49
        /** @scrutinizer ignore-call */ 
50
        Psr7\copy_to_stream($s1, $s2);
Loading history...
50
        $this->assertEquals('', (string) $s2);
51
    }
52
53
    public function testStopsCopyToSteamWhenWriteFailsWithMaxLen()
54
    {
55
        $s1 = Psr7\stream_for('foobaz');
0 ignored issues
show
Bug introduced by
The function stream_for was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

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

55
        $s1 = /** @scrutinizer ignore-call */ Psr7\stream_for('foobaz');
Loading history...
56
        $s2 = Psr7\stream_for('');
57
        $s2 = FnStream::decorate($s2, array('write' => function () { return 0; }));
58
        Psr7\copy_to_stream($s1, $s2, 10);
0 ignored issues
show
Bug introduced by
The function copy_to_stream was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

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

58
        /** @scrutinizer ignore-call */ 
59
        Psr7\copy_to_stream($s1, $s2, 10);
Loading history...
59
        $this->assertEquals('', (string) $s2);
60
    }
61
62
    public function testStopsCopyToSteamWhenReadFailsWithMaxLen()
63
    {
64
        $s1 = Psr7\stream_for('foobaz');
0 ignored issues
show
Bug introduced by
The function stream_for was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

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

64
        $s1 = /** @scrutinizer ignore-call */ Psr7\stream_for('foobaz');
Loading history...
65
        $s1 = FnStream::decorate($s1, array('read' => function () { return ''; }));
66
        $s2 = Psr7\stream_for('');
67
        Psr7\copy_to_stream($s1, $s2, 10);
0 ignored issues
show
Bug introduced by
The function copy_to_stream was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

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

67
        /** @scrutinizer ignore-call */ 
68
        Psr7\copy_to_stream($s1, $s2, 10);
Loading history...
68
        $this->assertEquals('', (string) $s2);
69
    }
70
71
    public function testReadsLines()
72
    {
73
        $s = Psr7\stream_for("foo\nbaz\nbar");
0 ignored issues
show
Bug introduced by
The function stream_for was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

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

73
        $s = /** @scrutinizer ignore-call */ Psr7\stream_for("foo\nbaz\nbar");
Loading history...
74
        $this->assertEquals("foo\n", Psr7\readline($s));
75
        $this->assertEquals("baz\n", Psr7\readline($s));
76
        $this->assertEquals("bar", Psr7\readline($s));
77
    }
78
79
    public function testReadsLinesUpToMaxLength()
80
    {
81
        $s = Psr7\stream_for("12345\n");
0 ignored issues
show
Bug introduced by
The function stream_for was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

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

81
        $s = /** @scrutinizer ignore-call */ Psr7\stream_for("12345\n");
Loading history...
82
        $this->assertEquals("123", Psr7\readline($s, 4));
0 ignored issues
show
Unused Code introduced by
The call to readline() has too many arguments starting with 4. ( Ignorable by Annotation )

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

82
        $this->assertEquals("123", /** @scrutinizer ignore-call */ Psr7\readline($s, 4));

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
83
        $this->assertEquals("45\n", Psr7\readline($s));
84
    }
85
86
    public function testReadsLineUntilFalseReturnedFromRead()
87
    {
88
        $s = $this->getMockBuilder('RingCentral\Psr7\Stream')
89
            ->setMethods(array('read', 'eof'))
90
            ->disableOriginalConstructor()
91
            ->getMock();
92
        $s->expects($this->exactly(2))
93
            ->method('read')
94
            ->will($this->returnCallback(function () {
95
                static $c = false;
96
                if ($c) {
97
                    return false;
98
                }
99
                $c = true;
100
                return 'h';
101
            }));
102
        $s->expects($this->exactly(2))
103
            ->method('eof')
104
            ->will($this->returnValue(false));
105
        $this->assertEquals("h", Psr7\readline($s));
106
    }
107
108
    public function testCalculatesHash()
109
    {
110
        $s = Psr7\stream_for('foobazbar');
0 ignored issues
show
Bug introduced by
The function stream_for was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

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

110
        $s = /** @scrutinizer ignore-call */ Psr7\stream_for('foobazbar');
Loading history...
111
        $this->assertEquals(md5('foobazbar'), Psr7\hash($s, 'md5'));
112
    }
113
114
    /**
115
     * @expectedException \RuntimeException
116
     */
117
    public function testCalculatesHashThrowsWhenSeekFails()
118
    {
119
        $s = new NoSeekStream(Psr7\stream_for('foobazbar'));
0 ignored issues
show
Bug introduced by
The function stream_for was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

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

119
        $s = new NoSeekStream(/** @scrutinizer ignore-call */ Psr7\stream_for('foobazbar'));
Loading history...
120
        $s->read(2);
121
        Psr7\hash($s, 'md5');
122
    }
123
124
    public function testCalculatesHashSeeksToOriginalPosition()
125
    {
126
        $s = Psr7\stream_for('foobazbar');
0 ignored issues
show
Bug introduced by
The function stream_for was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

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

126
        $s = /** @scrutinizer ignore-call */ Psr7\stream_for('foobazbar');
Loading history...
127
        $s->seek(4);
128
        $this->assertEquals(md5('foobazbar'), Psr7\hash($s, 'md5'));
129
        $this->assertEquals(4, $s->tell());
130
    }
131
132
    public function testOpensFilesSuccessfully()
133
    {
134
        $r = Psr7\try_fopen(__FILE__, 'r');
0 ignored issues
show
Bug introduced by
The function try_fopen was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

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

134
        $r = /** @scrutinizer ignore-call */ Psr7\try_fopen(__FILE__, 'r');
Loading history...
135
        $this->assertInternalType('resource', $r);
136
        fclose($r);
137
    }
138
139
    /**
140
     * @expectedException \RuntimeException
141
     * @expectedExceptionMessage Unable to open /path/to/does/not/exist using mode r
142
     */
143
    public function testThrowsExceptionNotWarning()
144
    {
145
        Psr7\try_fopen('/path/to/does/not/exist', 'r');
0 ignored issues
show
Bug introduced by
The function try_fopen was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

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

145
        /** @scrutinizer ignore-call */ 
146
        Psr7\try_fopen('/path/to/does/not/exist', 'r');
Loading history...
146
    }
147
148
    public function parseQueryProvider()
149
    {
150
        return array(
151
            // Does not need to parse when the string is empty
152
            array('', array()),
153
            // Can parse mult-values items
154
            array('q=a&q=b', array('q' => array('a', 'b'))),
155
            // Can parse multi-valued items that use numeric indices
156
            array('q[0]=a&q[1]=b', array('q[0]' => 'a', 'q[1]' => 'b')),
157
            // Can parse duplicates and does not include numeric indices
158
            array('q[]=a&q[]=b', array('q[]' => array('a', 'b'))),
159
            // Ensures that the value of "q" is an array even though one value
160
            array('q[]=a', array('q[]' => 'a')),
161
            // Does not modify "." to "_" like PHP's parse_str()
162
            array('q.a=a&q.b=b', array('q.a' => 'a', 'q.b' => 'b')),
163
            // Can decode %20 to " "
164
            array('q%20a=a%20b', array('q a' => 'a b')),
165
            // Can parse funky strings with no values by assigning each to null
166
            array('q&a', array('q' => null, 'a' => null)),
167
            // Does not strip trailing equal signs
168
            array('data=abc=', array('data' => 'abc=')),
169
            // Can store duplicates without affecting other values
170
            array('foo=a&foo=b&?µ=c', array('foo' => array('a', 'b'), '?µ' => 'c')),
171
            // Sets value to null when no "=" is present
172
            array('foo', array('foo' => null)),
173
            // Preserves "0" keys.
174
            array('0', array('0' => null)),
175
            // Sets the value to an empty string when "=" is present
176
            array('0=', array('0' => '')),
177
            // Preserves falsey keys
178
            array('var=0', array('var' => '0')),
179
            array('a[b][c]=1&a[b][c]=2', array('a[b][c]' => array('1', '2'))),
180
            array('a[b]=c&a[d]=e', array('a[b]' => 'c', 'a[d]' => 'e')),
181
            // Ensure it doesn't leave things behind with repeated values
182
            // Can parse mult-values items
183
            array('q=a&q=b&q=c', array('q' => array('a', 'b', 'c'))),
184
        );
185
    }
186
187
    /**
188
     * @dataProvider parseQueryProvider
189
     */
190
    public function testParsesQueries($input, $output)
191
    {
192
        $result = Psr7\parse_query($input);
0 ignored issues
show
Bug introduced by
The function parse_query was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

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

192
        $result = /** @scrutinizer ignore-call */ Psr7\parse_query($input);
Loading history...
193
        $this->assertSame($output, $result);
194
    }
195
196
    public function testDoesNotDecode()
197
    {
198
        $str = 'foo%20=bar';
199
        $data = Psr7\parse_query($str, false);
0 ignored issues
show
Bug introduced by
The function parse_query was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

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

199
        $data = /** @scrutinizer ignore-call */ Psr7\parse_query($str, false);
Loading history...
200
        $this->assertEquals(array('foo%20' => 'bar'), $data);
201
    }
202
203
    /**
204
     * @dataProvider parseQueryProvider
205
     */
206
    public function testParsesAndBuildsQueries($input, $output)
207
    {
208
        $result = Psr7\parse_query($input, false);
0 ignored issues
show
Bug introduced by
The function parse_query was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

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

208
        $result = /** @scrutinizer ignore-call */ Psr7\parse_query($input, false);
Loading history...
209
        $this->assertSame($input, Psr7\build_query($result, false));
0 ignored issues
show
Bug introduced by
The function build_query was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

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

209
        $this->assertSame($input, /** @scrutinizer ignore-call */ Psr7\build_query($result, false));
Loading history...
210
    }
211
212
    public function testEncodesWithRfc1738()
213
    {
214
        $str = Psr7\build_query(array('foo bar' => 'baz+'), PHP_QUERY_RFC1738);
0 ignored issues
show
Bug introduced by
The function build_query was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

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

214
        $str = /** @scrutinizer ignore-call */ Psr7\build_query(array('foo bar' => 'baz+'), PHP_QUERY_RFC1738);
Loading history...
215
        $this->assertEquals('foo+bar=baz%2B', $str);
216
    }
217
218
    public function testEncodesWithRfc3986()
219
    {
220
        $str = Psr7\build_query(array('foo bar' => 'baz+'), PHP_QUERY_RFC3986);
0 ignored issues
show
Bug introduced by
The function build_query was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

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

220
        $str = /** @scrutinizer ignore-call */ Psr7\build_query(array('foo bar' => 'baz+'), PHP_QUERY_RFC3986);
Loading history...
221
        $this->assertEquals('foo%20bar=baz%2B', $str);
222
    }
223
224
    public function testDoesNotEncode()
225
    {
226
        $str = Psr7\build_query(array('foo bar' => 'baz+'), false);
0 ignored issues
show
Bug introduced by
The function build_query was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

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

226
        $str = /** @scrutinizer ignore-call */ Psr7\build_query(array('foo bar' => 'baz+'), false);
Loading history...
227
        $this->assertEquals('foo bar=baz+', $str);
228
    }
229
230
    public function testCanControlDecodingType()
231
    {
232
        $result = Psr7\parse_query('var=foo+bar', PHP_QUERY_RFC3986);
0 ignored issues
show
Bug introduced by
The function parse_query was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

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

232
        $result = /** @scrutinizer ignore-call */ Psr7\parse_query('var=foo+bar', PHP_QUERY_RFC3986);
Loading history...
233
        $this->assertEquals('foo+bar', $result['var']);
234
        $result = Psr7\parse_query('var=foo+bar', PHP_QUERY_RFC1738);
235
        $this->assertEquals('foo bar', $result['var']);
236
    }
237
238
    public function testParsesRequestMessages()
239
    {
240
        $req = "GET /abc HTTP/1.0\r\nHost: foo.com\r\nFoo: Bar\r\nBaz: Bam\r\nBaz: Qux\r\n\r\nTest";
241
        $request = Psr7\parse_request($req);
0 ignored issues
show
Bug introduced by
The function parse_request was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

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

241
        $request = /** @scrutinizer ignore-call */ Psr7\parse_request($req);
Loading history...
242
        $this->assertEquals('GET', $request->getMethod());
243
        $this->assertEquals('/abc', $request->getRequestTarget());
244
        $this->assertEquals('1.0', $request->getProtocolVersion());
245
        $this->assertEquals('foo.com', $request->getHeaderLine('Host'));
246
        $this->assertEquals('Bar', $request->getHeaderLine('Foo'));
247
        $this->assertEquals('Bam, Qux', $request->getHeaderLine('Baz'));
248
        $this->assertEquals('Test', (string) $request->getBody());
249
        $this->assertEquals('http://foo.com/abc', (string) $request->getUri());
250
    }
251
252
    public function testParsesRequestMessagesWithHttpsScheme()
253
    {
254
        $req = "PUT /abc?baz=bar HTTP/1.1\r\nHost: foo.com:443\r\n\r\n";
255
        $request = Psr7\parse_request($req);
0 ignored issues
show
Bug introduced by
The function parse_request was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

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

255
        $request = /** @scrutinizer ignore-call */ Psr7\parse_request($req);
Loading history...
256
        $this->assertEquals('PUT', $request->getMethod());
257
        $this->assertEquals('/abc?baz=bar', $request->getRequestTarget());
258
        $this->assertEquals('1.1', $request->getProtocolVersion());
259
        $this->assertEquals('foo.com:443', $request->getHeaderLine('Host'));
260
        $this->assertEquals('', (string) $request->getBody());
261
        $this->assertEquals('https://foo.com/abc?baz=bar', (string) $request->getUri());
262
    }
263
264
    public function testParsesRequestMessagesWithUriWhenHostIsNotFirst()
265
    {
266
        $req = "PUT / HTTP/1.1\r\nFoo: Bar\r\nHost: foo.com\r\n\r\n";
267
        $request = Psr7\parse_request($req);
0 ignored issues
show
Bug introduced by
The function parse_request was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

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

267
        $request = /** @scrutinizer ignore-call */ Psr7\parse_request($req);
Loading history...
268
        $this->assertEquals('PUT', $request->getMethod());
269
        $this->assertEquals('/', $request->getRequestTarget());
270
        $this->assertEquals('http://foo.com/', (string) $request->getUri());
271
    }
272
273
    public function testParsesRequestMessagesWithFullUri()
274
    {
275
        $req = "GET https://www.google.com:443/search?q=foobar HTTP/1.1\r\nHost: www.google.com\r\n\r\n";
276
        $request = Psr7\parse_request($req);
0 ignored issues
show
Bug introduced by
The function parse_request was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

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

276
        $request = /** @scrutinizer ignore-call */ Psr7\parse_request($req);
Loading history...
277
        $this->assertEquals('GET', $request->getMethod());
278
        $this->assertEquals('https://www.google.com:443/search?q=foobar', $request->getRequestTarget());
279
        $this->assertEquals('1.1', $request->getProtocolVersion());
280
        $this->assertEquals('www.google.com', $request->getHeaderLine('Host'));
281
        $this->assertEquals('', (string) $request->getBody());
282
        $this->assertEquals('https://www.google.com/search?q=foobar', (string) $request->getUri());
283
    }
284
285
    /**
286
     * @expectedException \InvalidArgumentException
287
     */
288
    public function testValidatesRequestMessages()
289
    {
290
        Psr7\parse_request("HTTP/1.1 200 OK\r\n\r\n");
0 ignored issues
show
Bug introduced by
The function parse_request was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

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

290
        /** @scrutinizer ignore-call */ 
291
        Psr7\parse_request("HTTP/1.1 200 OK\r\n\r\n");
Loading history...
291
    }
292
293
    public function testParsesResponseMessages()
294
    {
295
        $res = "HTTP/1.0 200 OK\r\nFoo: Bar\r\nBaz: Bam\r\nBaz: Qux\r\n\r\nTest";
296
        $response = Psr7\parse_response($res);
0 ignored issues
show
Bug introduced by
The function parse_response was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

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

296
        $response = /** @scrutinizer ignore-call */ Psr7\parse_response($res);
Loading history...
297
        $this->assertEquals(200, $response->getStatusCode());
298
        $this->assertEquals('OK', $response->getReasonPhrase());
299
        $this->assertEquals('1.0', $response->getProtocolVersion());
300
        $this->assertEquals('Bar', $response->getHeaderLine('Foo'));
301
        $this->assertEquals('Bam, Qux', $response->getHeaderLine('Baz'));
302
        $this->assertEquals('Test', (string) $response->getBody());
303
    }
304
305
    /**
306
     * @expectedException \InvalidArgumentException
307
     */
308
    public function testValidatesResponseMessages()
309
    {
310
        Psr7\parse_response("GET / HTTP/1.1\r\n\r\n");
0 ignored issues
show
Bug introduced by
The function parse_response was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

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

310
        /** @scrutinizer ignore-call */ 
311
        Psr7\parse_response("GET / HTTP/1.1\r\n\r\n");
Loading history...
311
    }
312
313
    public function testDetermineMimetype()
314
    {
315
        $this->assertNull(Psr7\mimetype_from_extension('not-a-real-extension'));
0 ignored issues
show
Bug introduced by
The function mimetype_from_extension was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

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

315
        $this->assertNull(/** @scrutinizer ignore-call */ Psr7\mimetype_from_extension('not-a-real-extension'));
Loading history...
316
        $this->assertEquals(
317
            'application/json',
318
            Psr7\mimetype_from_extension('json')
319
        );
320
        $this->assertEquals(
321
            'image/jpeg',
322
            Psr7\mimetype_from_filename('/tmp/images/IMG034821.JPEG')
0 ignored issues
show
Bug introduced by
The function mimetype_from_filename was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

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

322
            /** @scrutinizer ignore-call */ 
323
            Psr7\mimetype_from_filename('/tmp/images/IMG034821.JPEG')
Loading history...
323
        );
324
    }
325
326
    public function testCreatesUriForValue()
327
    {
328
        $this->assertInstanceOf('RingCentral\Psr7\Uri', Psr7\uri_for('/foo'));
0 ignored issues
show
Bug introduced by
The function uri_for was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

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

328
        $this->assertInstanceOf('RingCentral\Psr7\Uri', /** @scrutinizer ignore-call */ Psr7\uri_for('/foo'));
Loading history...
329
        $this->assertInstanceOf(
330
            'RingCentral\Psr7\Uri',
331
            Psr7\uri_for(new Psr7\Uri('/foo'))
332
        );
333
    }
334
335
    /**
336
     * @expectedException \InvalidArgumentException
337
     */
338
    public function testValidatesUri()
339
    {
340
        Psr7\uri_for(array());
0 ignored issues
show
Bug introduced by
The function uri_for was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

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

340
        /** @scrutinizer ignore-call */ 
341
        Psr7\uri_for(array());
Loading history...
341
    }
342
343
    public function testKeepsPositionOfResource()
344
    {
345
        $h = fopen(__FILE__, 'r');
346
        fseek($h, 10);
347
        $stream = Psr7\stream_for($h);
0 ignored issues
show
Bug introduced by
The function stream_for was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

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

347
        $stream = /** @scrutinizer ignore-call */ Psr7\stream_for($h);
Loading history...
348
        $this->assertEquals(10, $stream->tell());
349
        $stream->close();
350
    }
351
352
    public function testCreatesWithFactory()
353
    {
354
        $stream = Psr7\stream_for('foo');
0 ignored issues
show
Bug introduced by
The function stream_for was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

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

354
        $stream = /** @scrutinizer ignore-call */ Psr7\stream_for('foo');
Loading history...
355
        $this->assertInstanceOf('RingCentral\Psr7\Stream', $stream);
356
        $this->assertEquals('foo', $stream->getContents());
357
        $stream->close();
358
    }
359
360
    public function testFactoryCreatesFromEmptyString()
361
    {
362
        $s = Psr7\stream_for();
0 ignored issues
show
Bug introduced by
The function stream_for was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

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

362
        $s = /** @scrutinizer ignore-call */ Psr7\stream_for();
Loading history...
363
        $this->assertInstanceOf('RingCentral\Psr7\Stream', $s);
364
    }
365
366
    public function testFactoryCreatesFromNull()
367
    {
368
        $s = Psr7\stream_for(null);
0 ignored issues
show
Bug introduced by
The function stream_for was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

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

368
        $s = /** @scrutinizer ignore-call */ Psr7\stream_for(null);
Loading history...
369
        $this->assertInstanceOf('RingCentral\Psr7\Stream', $s);
370
    }
371
372
    public function testFactoryCreatesFromResource()
373
    {
374
        $r = fopen(__FILE__, 'r');
375
        $s = Psr7\stream_for($r);
0 ignored issues
show
Bug introduced by
The function stream_for was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

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

375
        $s = /** @scrutinizer ignore-call */ Psr7\stream_for($r);
Loading history...
376
        $this->assertInstanceOf('RingCentral\Psr7\Stream', $s);
377
        $this->assertSame(file_get_contents(__FILE__), (string) $s);
378
    }
379
380
    public function testFactoryCreatesFromObjectWithToString()
381
    {
382
        $r = new HasToString();
383
        $s = Psr7\stream_for($r);
0 ignored issues
show
Bug introduced by
The function stream_for was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

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

383
        $s = /** @scrutinizer ignore-call */ Psr7\stream_for($r);
Loading history...
384
        $this->assertInstanceOf('RingCentral\Psr7\Stream', $s);
385
        $this->assertEquals('foo', (string) $s);
386
    }
387
388
    public function testCreatePassesThrough()
389
    {
390
        $s = Psr7\stream_for('foo');
0 ignored issues
show
Bug introduced by
The function stream_for was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

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

390
        $s = /** @scrutinizer ignore-call */ Psr7\stream_for('foo');
Loading history...
391
        $this->assertSame($s, Psr7\stream_for($s));
392
    }
393
394
    /**
395
     * @expectedException \InvalidArgumentException
396
     */
397
    public function testThrowsExceptionForUnknown()
398
    {
399
        Psr7\stream_for(new \stdClass());
0 ignored issues
show
Bug introduced by
The function stream_for was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

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

399
        /** @scrutinizer ignore-call */ 
400
        Psr7\stream_for(new \stdClass());
Loading history...
400
    }
401
402
    public function testReturnsCustomMetadata()
403
    {
404
        $s = Psr7\stream_for('foo', array('metadata' => array('hwm' => 3)));
0 ignored issues
show
Bug introduced by
The function stream_for was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

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

404
        $s = /** @scrutinizer ignore-call */ Psr7\stream_for('foo', array('metadata' => array('hwm' => 3)));
Loading history...
405
        $this->assertEquals(3, $s->getMetadata('hwm'));
406
        $this->assertArrayHasKey('hwm', $s->getMetadata());
407
    }
408
409
    public function testCanSetSize()
410
    {
411
        $s = Psr7\stream_for('', array('size' => 10));
0 ignored issues
show
Bug introduced by
The function stream_for was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

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

411
        $s = /** @scrutinizer ignore-call */ Psr7\stream_for('', array('size' => 10));
Loading history...
412
        $this->assertEquals(10, $s->getSize());
413
    }
414
415
    public function testCanCreateIteratorBasedStream()
416
    {
417
        $a = new \ArrayIterator(array('foo', 'bar', '123'));
418
        $p = Psr7\stream_for($a);
0 ignored issues
show
Bug introduced by
The function stream_for was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

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

418
        $p = /** @scrutinizer ignore-call */ Psr7\stream_for($a);
Loading history...
419
        $this->assertInstanceOf('RingCentral\Psr7\PumpStream', $p);
420
        $this->assertEquals('foo', $p->read(3));
421
        $this->assertFalse($p->eof());
422
        $this->assertEquals('b', $p->read(1));
423
        $this->assertEquals('a', $p->read(1));
424
        $this->assertEquals('r12', $p->read(3));
425
        $this->assertFalse($p->eof());
426
        $this->assertEquals('3', $p->getContents());
427
        $this->assertTrue($p->eof());
428
        $this->assertEquals(9, $p->tell());
429
    }
430
431
    public function testConvertsRequestsToStrings()
432
    {
433
        $request = new Psr7\Request('PUT', 'http://foo.com/hi?123', array(
434
            'Baz' => 'bar',
435
            'Qux' => ' ipsum'
436
        ), 'hello', '1.0');
437
        $this->assertEquals(
438
            "PUT /hi?123 HTTP/1.0\r\nHost: foo.com\r\nBaz: bar\r\nQux: ipsum\r\n\r\nhello",
439
            Psr7\str($request)
0 ignored issues
show
Bug introduced by
The function str was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

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

439
            /** @scrutinizer ignore-call */ 
440
            Psr7\str($request)
Loading history...
440
        );
441
    }
442
443
    public function testConvertsResponsesToStrings()
444
    {
445
        $response = new Psr7\Response(200, array(
446
            'Baz' => 'bar',
447
            'Qux' => ' ipsum'
448
        ), 'hello', '1.0', 'FOO');
449
        $this->assertEquals(
450
            "HTTP/1.0 200 FOO\r\nBaz: bar\r\nQux: ipsum\r\n\r\nhello",
451
            Psr7\str($response)
0 ignored issues
show
Bug introduced by
The function str was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

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

451
            /** @scrutinizer ignore-call */ 
452
            Psr7\str($response)
Loading history...
452
        );
453
    }
454
455
    public function parseParamsProvider()
456
    {
457
        $res1 = array(
458
            array(
459
                '<http:/.../front.jpeg>',
460
                'rel' => 'front',
461
                'type' => 'image/jpeg',
462
            ),
463
            array(
464
                '<http://.../back.jpeg>',
465
                'rel' => 'back',
466
                'type' => 'image/jpeg',
467
            ),
468
        );
469
        return array(
470
            array(
471
                '<http:/.../front.jpeg>; rel="front"; type="image/jpeg", <http://.../back.jpeg>; rel=back; type="image/jpeg"',
472
                $res1
473
            ),
474
            array(
475
                '<http:/.../front.jpeg>; rel="front"; type="image/jpeg",<http://.../back.jpeg>; rel=back; type="image/jpeg"',
476
                $res1
477
            ),
478
            array(
479
                'foo="baz"; bar=123, boo, test="123", foobar="foo;bar"',
480
                array(
481
                    array('foo' => 'baz', 'bar' => '123'),
482
                    array('boo'),
483
                    array('test' => '123'),
484
                    array('foobar' => 'foo;bar')
485
                )
486
            ),
487
            array(
488
                '<http://.../side.jpeg?test=1>; rel="side"; type="image/jpeg",<http://.../side.jpeg?test=2>; rel=side; type="image/jpeg"',
489
                array(
490
                    array('<http://.../side.jpeg?test=1>', 'rel' => 'side', 'type' => 'image/jpeg'),
491
                    array('<http://.../side.jpeg?test=2>', 'rel' => 'side', 'type' => 'image/jpeg')
492
                )
493
            ),
494
            array(
495
                '',
496
                array()
497
            )
498
        );
499
    }
500
    /**
501
     * @dataProvider parseParamsProvider
502
     */
503
    public function testParseParams($header, $result)
504
    {
505
        $this->assertEquals($result, Psr7\parse_header($header));
0 ignored issues
show
Bug introduced by
The function parse_header was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

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

505
        $this->assertEquals($result, /** @scrutinizer ignore-call */ Psr7\parse_header($header));
Loading history...
506
    }
507
508
    public function testParsesArrayHeaders()
509
    {
510
        $header = array('a, b', 'c', 'd, e');
511
        $this->assertEquals(array('a', 'b', 'c', 'd', 'e'), Psr7\normalize_header($header));
0 ignored issues
show
Bug introduced by
The function normalize_header was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

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

511
        $this->assertEquals(array('a', 'b', 'c', 'd', 'e'), /** @scrutinizer ignore-call */ Psr7\normalize_header($header));
Loading history...
512
    }
513
514
    public function testRewindsBody()
515
    {
516
        $body = Psr7\stream_for('abc');
0 ignored issues
show
Bug introduced by
The function stream_for was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

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

516
        $body = /** @scrutinizer ignore-call */ Psr7\stream_for('abc');
Loading history...
517
        $res = new Psr7\Response(200, array(), $body);
518
        Psr7\rewind_body($res);
0 ignored issues
show
Bug introduced by
The function rewind_body was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

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

518
        /** @scrutinizer ignore-call */ 
519
        Psr7\rewind_body($res);
Loading history...
519
        $this->assertEquals(0, $body->tell());
520
        $body->rewind(1);
521
        Psr7\rewind_body($res);
522
        $this->assertEquals(0, $body->tell());
523
    }
524
525
    /**
526
     * @expectedException \RuntimeException
527
     */
528
    public function testThrowsWhenBodyCannotBeRewound()
529
    {
530
        $body = Psr7\stream_for('abc');
0 ignored issues
show
Bug introduced by
The function stream_for was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

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

530
        $body = /** @scrutinizer ignore-call */ Psr7\stream_for('abc');
Loading history...
531
        $body->read(1);
532
        $body = FnStream::decorate($body, array(
533
            'rewind' => function () { throw new \RuntimeException('a'); }
534
        ));
535
        $res = new Psr7\Response(200, array(), $body);
536
        Psr7\rewind_body($res);
0 ignored issues
show
Bug introduced by
The function rewind_body was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

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

536
        /** @scrutinizer ignore-call */ 
537
        Psr7\rewind_body($res);
Loading history...
537
    }
538
539
    public function testCanModifyRequestWithUri()
540
    {
541
        $r1 = new Psr7\Request('GET', 'http://foo.com');
542
        $r2 = Psr7\modify_request($r1, array(
0 ignored issues
show
Bug introduced by
The function modify_request was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

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

542
        $r2 = /** @scrutinizer ignore-call */ Psr7\modify_request($r1, array(
Loading history...
543
            'uri' => new Psr7\Uri('http://www.foo.com')
544
        ));
545
        $this->assertEquals('http://www.foo.com', (string) $r2->getUri());
546
        $this->assertEquals('www.foo.com', (string) $r2->getHeaderLine('host'));
547
    }
548
549
    public function testCanModifyRequestWithCaseInsensitiveHeader()
550
    {
551
        $r1 = new Psr7\Request('GET', 'http://foo.com', array('User-Agent' => 'foo'));
552
        $r2 = Psr7\modify_request($r1, array('set_headers' => array('User-agent' => 'bar')));
0 ignored issues
show
Bug introduced by
The function modify_request was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

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

552
        $r2 = /** @scrutinizer ignore-call */ Psr7\modify_request($r1, array('set_headers' => array('User-agent' => 'bar')));
Loading history...
553
        $this->assertEquals('bar', $r2->getHeaderLine('User-Agent'));
554
        $this->assertEquals('bar', $r2->getHeaderLine('User-agent'));
555
    }
556
557
    public function testReturnsAsIsWhenNoChanges()
558
    {
559
        $request = new Psr7\Request('GET', 'http://foo.com');
560
        $this->assertSame($request, Psr7\modify_request($request, array()));
0 ignored issues
show
Bug introduced by
The function modify_request was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

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

560
        $this->assertSame($request, /** @scrutinizer ignore-call */ Psr7\modify_request($request, array()));
Loading history...
561
    }
562
563
    public function testReturnsUriAsIsWhenNoChanges()
564
    {
565
        $r1 = new Psr7\Request('GET', 'http://foo.com');
566
        $r2 = Psr7\modify_request($r1, array('set_headers' => array('foo' => 'bar')));
0 ignored issues
show
Bug introduced by
The function modify_request was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

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

566
        $r2 = /** @scrutinizer ignore-call */ Psr7\modify_request($r1, array('set_headers' => array('foo' => 'bar')));
Loading history...
567
        $this->assertNotSame($r1, $r2);
568
        $this->assertEquals('bar', $r2->getHeaderLine('foo'));
569
    }
570
571
    public function testRemovesHeadersFromMessage()
572
    {
573
        $r1 = new Psr7\Request('GET', 'http://foo.com', array('foo' => 'bar'));
574
        $r2 = Psr7\modify_request($r1, array('remove_headers' => array('foo')));
0 ignored issues
show
Bug introduced by
The function modify_request was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

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

574
        $r2 = /** @scrutinizer ignore-call */ Psr7\modify_request($r1, array('remove_headers' => array('foo')));
Loading history...
575
        $this->assertNotSame($r1, $r2);
576
        $this->assertFalse($r2->hasHeader('foo'));
577
    }
578
579
    public function testAddsQueryToUri()
580
    {
581
        $r1 = new Psr7\Request('GET', 'http://foo.com');
582
        $r2 = Psr7\modify_request($r1, array('query' => 'foo=bar'));
0 ignored issues
show
Bug introduced by
The function modify_request was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

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

582
        $r2 = /** @scrutinizer ignore-call */ Psr7\modify_request($r1, array('query' => 'foo=bar'));
Loading history...
583
        $this->assertNotSame($r1, $r2);
584
        $this->assertEquals('foo=bar', $r2->getUri()->getQuery());
585
    }
586
587
    public function testServerRequestWithServerParams()
588
    {
589
        $requestString = "GET /abc HTTP/1.1\r\nHost: foo.com\r\n\r\n";
590
        $request = Psr7\parse_server_request($requestString);
0 ignored issues
show
Bug introduced by
The function parse_server_request was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

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

590
        $request = /** @scrutinizer ignore-call */ Psr7\parse_server_request($requestString);
Loading history...
591
592
        $this->assertEquals(array(), $request->getServerParams());
593
    }
594
595
    public function testServerRequestWithoutServerParams()
596
    {
597
        $requestString = "GET /abc HTTP/1.1\r\nHost: foo.com\r\n\r\n";
598
        $serverParams = array('server_address' => '127.0.0.1', 'server_port' => 80);
599
600
        $request = Psr7\parse_server_request($requestString, $serverParams);
0 ignored issues
show
Bug introduced by
The function parse_server_request was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

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

600
        $request = /** @scrutinizer ignore-call */ Psr7\parse_server_request($requestString, $serverParams);
Loading history...
601
602
        $this->assertEquals(array('server_address' => '127.0.0.1', 'server_port' => 80), $request->getServerParams());
603
    }
604
}
605