Skip to content

Commit f1240c7

Browse files
Run tests on PHP 8.0
1 parent ba0f9e2 commit f1240c7

24 files changed

+329
-207
lines changed

.travis.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,17 @@ matrix:
2626
dist: bionic
2727
- php: 7.4
2828
dist: bionic
29+
- php: nightly
30+
dist: bionic
2931
fast_finish: true
3032

3133
before_install:
3234
- if [[ "$TRAVIS_PHP_VERSION" != "hhvm-3.24" ]]; then echo "xdebug.overload_var_dump = 1" >> ~/.phpenv/versions/$(phpenv version-name)/etc/php.ini; fi
3335
- if [[ "$TRAVIS_PHP_VERSION" == "hhvm-3.24" ]]; then travis_retry composer require "phpunit/phpunit:^5.7.27" --dev --no-update -n; fi
3436

3537
install:
36-
- travis_retry composer update --prefer-dist
38+
- if [[ "$TRAVIS_PHP_VERSION" != "nightly" ]]; then travis_retry composer update --prefer-dist; fi
39+
- if [[ "$TRAVIS_PHP_VERSION" == "nightly" ]]; then travis_retry composer update --prefer-dist --ignore-platform-reqs; fi
3740

3841
script:
3942
- make test

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
"ralouphie/getallheaders": "^2.0.5 || ^3.0.0"
2222
},
2323
"require-dev": {
24-
"phpunit/phpunit": "~4.8.36 || ^5.7.27 || ^6.5.8",
24+
"phpunit/phpunit": "~4.8.36 || ^5.7.27 || ^6.5.14 || ^7.5.20 || ^8.5.8 || ^9.3.10",
2525
"ext-zlib": "*"
2626
},
2727
"provide": {

phpunit.xml.dist

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,19 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<phpunit
3-
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4-
xsi:noNamespaceSchemaLocation="vendor/phpunit/phpunit/phpunit.xsd"
5-
bootstrap="tests/bootstrap.php"
3+
backupGlobals="true"
64
colors="true"
5+
beStrictAboutOutputDuringTests="true"
6+
beStrictAboutTestsThatDoNotTestAnything="true"
7+
bootstrap="vendor/autoload.php"
78
>
89
<testsuites>
9-
<testsuite>
10-
<directory>tests</directory>
10+
<testsuite name="GuzzleHttp PSR7 Test Suite">
11+
<directory>tests/</directory>
1112
</testsuite>
1213
</testsuites>
1314
<filter>
1415
<whitelist>
15-
<directory suffix=".php">src</directory>
16+
<directory suffix=".php">src/</directory>
1617
</whitelist>
1718
</filter>
1819
</phpunit>

tests/AppendStreamTest.php

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,6 @@
77

88
class AppendStreamTest extends BaseTest
99
{
10-
/**
11-
* @expectedException \InvalidArgumentException
12-
* @expectedExceptionMessage Each stream must be readable
13-
*/
1410
public function testValidatesStreamsAreReadable()
1511
{
1612
$a = new AppendStream();
@@ -20,23 +16,21 @@ public function testValidatesStreamsAreReadable()
2016
$s->expects($this->once())
2117
->method('isReadable')
2218
->will($this->returnValue(false));
19+
20+
$this->expectExceptionGuzzle('InvalidArgumentException', 'Each stream must be readable');
21+
2322
$a->addStream($s);
2423
}
2524

26-
/**
27-
* @expectedException \RuntimeException
28-
* @expectedExceptionMessage The AppendStream can only seek with SEEK_SET
29-
*/
3025
public function testValidatesSeekType()
3126
{
3227
$a = new AppendStream();
28+
29+
$this->expectExceptionGuzzle('RuntimeException', 'The AppendStream can only seek with SEEK_SET');
30+
3331
$a->seek(100, SEEK_CUR);
3432
}
3533

36-
/**
37-
* @expectedException \RuntimeException
38-
* @expectedExceptionMessage Unable to seek stream 0 of the AppendStream
39-
*/
4034
public function testTriesToRewindOnSeek()
4135
{
4236
$a = new AppendStream();
@@ -53,6 +47,9 @@ public function testTriesToRewindOnSeek()
5347
->method('rewind')
5448
->will($this->throwException(new \RuntimeException()));
5549
$a->addStream($s);
50+
51+
$this->expectExceptionGuzzle('RuntimeException', 'Unable to seek stream 0 of the AppendStream');
52+
5653
$a->seek(10);
5754
}
5855

@@ -104,7 +101,7 @@ public function testDetachesEachStream()
104101
$this->assertFalse($a->isWritable());
105102

106103
$this->assertNull($s1->detach());
107-
$this->assertInternalType('resource', $handle, 'resource is not closed when detaching');
104+
$this->assertInternalTypeGuzzle('resource', $handle, 'resource is not closed when detaching');
108105
fclose($handle);
109106
}
110107

@@ -128,16 +125,15 @@ public function testClosesEachStream()
128125
$this->assertFalse(is_resource($handle));
129126
}
130127

131-
/**
132-
* @expectedExceptionMessage Cannot write to an AppendStream
133-
* @expectedException \RuntimeException
134-
*/
135128
public function testIsNotWritable()
136129
{
137130
$a = new AppendStream([Psr7\Utils::streamFor('foo')]);
138131
$this->assertFalse($a->isWritable());
139132
$this->assertTrue($a->isSeekable());
140133
$this->assertTrue($a->isReadable());
134+
135+
$this->expectExceptionGuzzle('RuntimeException', 'Cannot write to an AppendStream');
136+
141137
$a->write('foo');
142138
}
143139

tests/BaseTest.php

Lines changed: 117 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,133 @@
77
abstract class BaseTest extends TestCase
88
{
99
/**
10-
* Make sure expectException always exists, even on PHPUnit 4
1110
* @param string $exception
1211
* @param string|null $message
1312
*/
14-
public function expectException($exception, $message = null)
13+
public function expectExceptionGuzzle($exception, $message = null)
1514
{
1615
if (method_exists($this, 'setExpectedException')) {
1716
$this->setExpectedException($exception, $message);
1817
} else {
19-
parent::expectException($exception);
18+
$this->expectException($exception);
2019
if (null !== $message) {
2120
$this->expectExceptionMessage($message);
2221
}
2322
}
2423
}
24+
25+
public function expectWarningGuzzle()
26+
{
27+
if (method_exists($this, 'expectWarning')) {
28+
$this->expectWarning();
29+
} elseif (class_exists('PHPUnit\Framework\Error\Warning')) {
30+
$this->expectExceptionGuzzle('PHPUnit\Framework\Error\Warning');
31+
} else {
32+
$this->expectExceptionGuzzle('PHPUnit_Framework_Error_Warning');
33+
}
34+
}
35+
36+
/**
37+
* @param string $type
38+
* @param mixed $input
39+
*/
40+
public function assertInternalTypeGuzzle($type, $input)
41+
{
42+
switch ($type) {
43+
case 'array':
44+
if (method_exists($this, 'assertIsArray')) {
45+
$this->assertIsArray($input);
46+
} else {
47+
$this->assertInternalType('array', $input);
48+
}
49+
break;
50+
case 'bool':
51+
case 'boolean':
52+
if (method_exists($this, 'assertIsBool')) {
53+
$this->assertIsBool($input);
54+
} else {
55+
$this->assertInternalType('bool', $input);
56+
}
57+
break;
58+
case 'double':
59+
case 'float':
60+
case 'real':
61+
if (method_exists($this, 'assertIsFloat')) {
62+
$this->assertIsFloat($input);
63+
} else {
64+
$this->assertInternalType('float', $input);
65+
}
66+
break;
67+
case 'int':
68+
case 'integer':
69+
if (method_exists($this, 'assertIsInt')) {
70+
$this->assertIsInt($input);
71+
} else {
72+
$this->assertInternalType('int', $input);
73+
}
74+
break;
75+
case 'numeric':
76+
if (method_exists($this, 'assertIsNumeric')) {
77+
$this->assertIsNumeric($input);
78+
} else {
79+
$this->assertInternalType('numeric', $input);
80+
}
81+
break;
82+
case 'object':
83+
if (method_exists($this, 'assertIsObject')) {
84+
$this->assertIsObject($input);
85+
} else {
86+
$this->assertInternalType('object', $input);
87+
}
88+
break;
89+
case 'resource':
90+
if (method_exists($this, 'assertIsResource')) {
91+
$this->assertIsResource($input);
92+
} else {
93+
$this->assertInternalType('resource', $input);
94+
}
95+
break;
96+
case 'string':
97+
if (method_exists($this, 'assertIsString')) {
98+
$this->assertIsString($input);
99+
} else {
100+
$this->assertInternalType('string', $input);
101+
}
102+
break;
103+
case 'scalar':
104+
if (method_exists($this, 'assertIsScalar')) {
105+
$this->assertIsScalar($input);
106+
} else {
107+
$this->assertInternalType('scalar', $input);
108+
}
109+
break;
110+
case 'callable':
111+
if (method_exists($this, 'assertIsCallable')) {
112+
$this->assertIsCallable($input);
113+
} else {
114+
$this->assertInternalType('callable', $input);
115+
}
116+
break;
117+
case 'iterable':
118+
if (method_exists($this, 'assertIsIterable')) {
119+
$this->assertIsIterable($input);
120+
} else {
121+
$this->assertInternalType('iterable', $input);
122+
}
123+
break;
124+
}
125+
}
126+
127+
/**
128+
* @param string $needle
129+
* @param string $haystack
130+
*/
131+
public function assertStringContainsStringGuzzle($needle, $haystack)
132+
{
133+
if (method_exists($this, 'assertStringContainsString')) {
134+
$this->assertStringContainsString($needle, $haystack);
135+
} else {
136+
$this->assertContains($needle, $haystack);
137+
}
138+
}
25139
}

tests/BufferStreamTest.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,6 @@ public function testRemovesReadDataFromBuffer()
2828
$this->assertSame('', $b->read(10));
2929
}
3030

31-
/**
32-
* @expectedException \RuntimeException
33-
* @expectedExceptionMessage Cannot determine the position of a BufferStream
34-
*/
3531
public function testCanCastToStringOrGetContents()
3632
{
3733
$b = new BufferStream();
@@ -40,6 +36,9 @@ public function testCanCastToStringOrGetContents()
4036
$this->assertSame('foo', $b->read(3));
4137
$b->write('bar');
4238
$this->assertSame('bazbar', (string) $b);
39+
40+
$this->expectExceptionGuzzle('RuntimeException', 'Cannot determine the position of a BufferStream');
41+
4342
$b->tell();
4443
}
4544

tests/CachingStreamTest.php

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,19 @@ class CachingStreamTest extends BaseTest
1616
/** @var Stream */
1717
private $decorated;
1818

19-
protected function setUp()
19+
/**
20+
* @before
21+
*/
22+
public function setUpTest()
2023
{
2124
$this->decorated = Psr7\Utils::streamFor('testing');
2225
$this->body = new CachingStream($this->decorated);
2326
}
2427

25-
protected function tearDown()
28+
/**
29+
* @after
30+
*/
31+
public function tearDownTest()
2632
{
2733
$this->decorated->close();
2834
$this->body->close();
@@ -150,31 +156,31 @@ public function testSkipsOverwrittenBytes()
150156
$this->assertSame("0001\n", Psr7\Utils::readLine($body));
151157
// Write over part of the body yet to be read, so skip some bytes
152158
$this->assertSame(5, $body->write("TEST\n"));
153-
$this->assertSame(5, $this->readAttribute($body, 'skipReadBytes'));
159+
$this->assertSame(5, Helpers::readObjectAttribute($body, 'skipReadBytes'));
154160
// Read, which skips bytes, then reads
155161
$this->assertSame("0003\n", Psr7\Utils::readLine($body));
156-
$this->assertSame(0, $this->readAttribute($body, 'skipReadBytes'));
162+
$this->assertSame(0, Helpers::readObjectAttribute($body, 'skipReadBytes'));
157163
$this->assertSame("0004\n", Psr7\Utils::readLine($body));
158164
$this->assertSame("0005\n", Psr7\Utils::readLine($body));
159165

160166
// Overwrite part of the cached body (so don't skip any bytes)
161167
$body->seek(5);
162168
$this->assertSame(5, $body->write("ABCD\n"));
163-
$this->assertSame(0, $this->readAttribute($body, 'skipReadBytes'));
169+
$this->assertSame(0, Helpers::readObjectAttribute($body, 'skipReadBytes'));
164170
$this->assertSame("TEST\n", Psr7\Utils::readLine($body));
165171
$this->assertSame("0003\n", Psr7\Utils::readLine($body));
166172
$this->assertSame("0004\n", Psr7\Utils::readLine($body));
167173
$this->assertSame("0005\n", Psr7\Utils::readLine($body));
168174
$this->assertSame("0006\n", Psr7\Utils::readLine($body));
169175
$this->assertSame(5, $body->write("1234\n"));
170-
$this->assertSame(5, $this->readAttribute($body, 'skipReadBytes'));
176+
$this->assertSame(5, Helpers::readObjectAttribute($body, 'skipReadBytes'));
171177

172178
// Seek to 0 and ensure the overwritten bit is replaced
173179
$body->seek(0);
174180
$this->assertSame("0000\nABCD\nTEST\n0003\n0004\n0005\n0006\n1234\n0008\n0009\n", $body->read(50));
175181

176182
// Ensure that casting it to a string does not include the bit that was overwritten
177-
$this->assertContains("0000\nABCD\nTEST\n0003\n0004\n0005\n0006\n1234\n0008\n0009\n", (string) $body);
183+
$this->assertStringContainsStringGuzzle("0000\nABCD\nTEST\n0003\n0004\n0005\n0006\n1234\n0008\n0009\n", (string) $body);
178184
}
179185

180186
public function testClosesBothStreams()
@@ -186,11 +192,10 @@ public function testClosesBothStreams()
186192
$this->assertFalse(is_resource($s));
187193
}
188194

189-
/**
190-
* @expectedException \InvalidArgumentException
191-
*/
192195
public function testEnsuresValidWhence()
193196
{
197+
$this->expectExceptionGuzzle('InvalidArgumentException');
198+
194199
$this->body->seek(10, -123456);
195200
}
196201
}

tests/FnStreamTest.php

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,10 @@
1010
*/
1111
class FnStreamTest extends BaseTest
1212
{
13-
/**
14-
* @expectedException \BadMethodCallException
15-
* @expectedExceptionMessage seek() is not implemented in the FnStream
16-
*/
1713
public function testThrowsWhenNotImplemented()
1814
{
15+
$this->expectExceptionGuzzle('BadMethodCallException', 'seek() is not implemented in the FnStream');
16+
1917
(new FnStream([]))->seek(1);
2018
}
2119

@@ -72,7 +70,7 @@ public function testDecoratesStream()
7270
$b->seek(0, SEEK_END);
7371
$b->write('bar');
7472
$this->assertSame('foobar', (string) $b);
75-
$this->assertInternalType('resource', $b->detach());
73+
$this->assertInternalTypeGuzzle('resource', $b->detach());
7674
$b->close();
7775
}
7876

@@ -94,7 +92,7 @@ public function testDoNotAllowUnserialization()
9492
{
9593
$a = new FnStream([]);
9694
$b = serialize($a);
97-
$this->expectException('\LogicException', 'FnStream should never be unserialized');
95+
$this->expectExceptionGuzzle('\LogicException', 'FnStream should never be unserialized');
9896
unserialize($b);
9997
}
10098
}

0 commit comments

Comments
 (0)