Skip to content

Commit d94b347

Browse files
committed
:octocat: phpunit 8
1 parent 2eeb15f commit d94b347

13 files changed

+99
-114
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
"psr/log": "^1.0"
3636
},
3737
"require-dev": {
38-
"phpunit/phpunit": "^7.5",
38+
"phpunit/phpunit": "^8.0",
3939
"guzzlehttp/psr7": "^1.5"
4040
},
4141
"autoload": {

tests/HTTPOptionsTest.php

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,18 @@
1414

1515
use chillerlan\HTTP\HTTPOptions;
1616
use PHPUnit\Framework\TestCase;
17+
use Psr\Http\Client\ClientExceptionInterface;
1718

1819
class HTTPOptionsTest extends TestCase{
1920

2021
public function testConvertInvalidCurlOptionsValueToArray(){
2122
$this->assertTrue(is_array((new HTTPOptions(['curl_options' => 'foo']))->curl_options)); //coverage
2223
}
2324

24-
/**
25-
* @expectedException \Psr\Http\Client\ClientExceptionInterface
26-
* @expectedExceptionMessage invalid user agent
27-
*/
2825
public function testInvalidUserAgentException(){
26+
$this->expectException(ClientExceptionInterface::class);
27+
$this->expectExceptionMessage('invalid user agent');
28+
2929
new HTTPOptions(['user_agent' => false]);
3030
}
3131

@@ -64,11 +64,10 @@ public function testCaInfoDir(){
6464
$this->assertArrayNotHasKey(CURLOPT_CAINFO, $o->curl_options);
6565
}
6666

67-
/**
68-
* @expectedException \Psr\Http\Client\ClientExceptionInterface
69-
* @expectedExceptionMessage invalid path to SSL CA bundle (HTTPOptions::$ca_info): foo
70-
*/
7167
public function testCaInfoInvalidException(){
68+
$this->expectException(ClientExceptionInterface::class);
69+
$this->expectExceptionMessage('invalid path to SSL CA bundle (HTTPOptions::$ca_info): foo');
70+
7271
new HTTPOptions(['ca_info' => 'foo']);
7372
}
7473

@@ -92,11 +91,10 @@ public function testCurloptCaInfoDir(){
9291
$this->assertArrayNotHasKey(CURLOPT_CAINFO, $o->curl_options);
9392
}
9493

95-
/**
96-
* @expectedException \Psr\Http\Client\ClientExceptionInterface
97-
* @expectedExceptionMessage invalid path to SSL CA bundle (CURLOPT_CAPATH/CURLOPT_CAINFO): foo
98-
*/
9994
public function testCurloptCaInfoInvalidException(){
95+
$this->expectException(ClientExceptionInterface::class);
96+
$this->expectExceptionMessage('invalid path to SSL CA bundle (CURLOPT_CAPATH/CURLOPT_CAINFO): foo');
97+
10098
new HTTPOptions(['curl_options' => [CURLOPT_CAINFO => 'foo']]);
10199
}
102100

tests/Psr17/FactoryHelpersTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
use chillerlan\HTTP\Psr17;
1616
use chillerlan\HTTP\Psr7\{UploadedFile, Uri};
17+
use InvalidArgumentException;
1718
use PHPUnit\Framework\TestCase;
1819
use Psr\Http\Message\StreamInterface;
1920

@@ -203,11 +204,10 @@ public function testCreateStreamFromInput($input, string $content){
203204
$this->assertSame($content, Psr17\create_stream_from_input($input)->getContents());
204205
}
205206

206-
/**
207-
* @expectedException \InvalidArgumentException
208-
* @expectedExceptionMessage Invalid resource type: object
209-
*/
210207
public function testCreateStreamFromInputException(){
208+
$this->expectException(InvalidArgumentException::class);
209+
$this->expectExceptionMessage('Invalid resource type: object');
210+
211211
Psr17\create_stream_from_input(new \stdClass());
212212
}
213213

tests/Psr18/CurlClientTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
class CurlClientTest extends HTTPClientTestAbstract{
1818

19-
protected function setUp(){
19+
protected function setUp():void{
2020
$options = new HTTPOptions([
2121
'ca_info' => __DIR__.'/../cacert.pem',
2222
'user_agent' => $this::USER_AGENT,

tests/Psr18/HTTPClientTestAbstract.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
use chillerlan\HTTP\Psr7\Request;
1616
use PHPUnit\Framework\TestCase;
17+
use Psr\Http\Client\ClientExceptionInterface;
1718

1819
abstract class HTTPClientTestAbstract extends TestCase{
1920

@@ -103,10 +104,9 @@ public function testRequest(string $method, array $extra_headers){
103104

104105
}
105106

106-
/**
107-
* @expectedException \Psr\Http\Client\ClientExceptionInterface
108-
*/
109107
public function testNetworkError(){
108+
$this->expectException(ClientExceptionInterface::class);
109+
110110
$this->http->sendRequest(new Request(Request::METHOD_GET, 'http://foo'));
111111
}
112112

tests/Psr18/StreamClientTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
class StreamClientTest extends HTTPClientTestAbstract{
1818

19-
protected function setUp(){
19+
protected function setUp():void{
2020
$options = new HTTPOptions([
2121
'ca_info' => __DIR__.'/../cacert.pem',
2222
'user_agent' => $this::USER_AGENT,

tests/Psr7/MultipartStreamTest.php

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@
1515
use chillerlan\HTTP\Psr17;
1616
use chillerlan\HTTP\Psr7\MultipartStream;
1717
use GuzzleHttp\Psr7\FnStream;
18+
use InvalidArgumentException;
1819
use PHPUnit\Framework\TestCase;
20+
use RuntimeException;
1921

2022
class MultipartStreamTest extends TestCase{
2123

@@ -34,19 +36,17 @@ public function testIsAlwaysReadableNotWritable(){
3436
$this->assertFalse($s->isWritable());
3537
}
3638

37-
/**
38-
* @expectedException \RuntimeException
39-
* @expectedExceptionMessage Cannot write to a MultipartStream, use MultipartStream::addElement() instead.
40-
*/
4139
public function testWriteError(){
40+
$this->expectException(RuntimeException::class);
41+
$this->expectExceptionMessage('Cannot write to a MultipartStream, use MultipartStream::addElement() instead.');
42+
4243
(new MultipartStream)->write('foo');
4344
}
4445

45-
/**
46-
* @expectedException \RuntimeException
47-
* @expectedExceptionMessage Stream already built
48-
*/
4946
public function testAlreadyBuiltError(){
47+
$this->expectException(RuntimeException::class);
48+
$this->expectExceptionMessage('Stream already built');
49+
5050
(new MultipartStream)->build()->addElement([]);
5151
}
5252

@@ -57,19 +57,17 @@ public function testCanCreateEmptyStream(){
5757
$this->assertSame("--{$boundary}--\r\n", $stream->getContents());
5858
}
5959

60-
/**
61-
* @expectedException \InvalidArgumentException
62-
* @expectedExceptionMessage A "contents" element is required
63-
*/
6460
public function testEnsureContentsElement(){
61+
$this->expectException(InvalidArgumentException::class);
62+
$this->expectExceptionMessage('A "contents" element is required');
63+
6564
new MultipartStream([['foo' => 'bar']]);
6665
}
6766

68-
/**
69-
* @expectedException \InvalidArgumentException
70-
* @expectedExceptionMessage A "name" element is required
71-
*/
7267
public function testEnsureNameElement(){
68+
$this->expectException(InvalidArgumentException::class);
69+
$this->expectExceptionMessage('A "name" element is required');
70+
7371
new MultipartStream([['contents' => 'bar']]);
7472
}
7573

tests/Psr7/RequestTest.php

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
use chillerlan\HTTP\Psr7\{Request, Uri};
1818
use chillerlan\HTTP\Psr17\RequestFactory;
19+
use InvalidArgumentException;
1920
use Psr\Http\Message\StreamInterface;
2021
use PHPUnit\Framework\TestCase;
2122

@@ -26,7 +27,7 @@ class RequestTest extends TestCase{
2627
*/
2728
protected $requestFactory;
2829

29-
protected function setUp(){
30+
protected function setUp():void{
3031
$this->requestFactory = new RequestFactory;
3132
}
3233

@@ -40,10 +41,9 @@ public function testRequestUriMayBeUri(){
4041
$this->assertSame($uri, (new Request('GET', $uri))->getUri());
4142
}
4243

43-
/**
44-
* @expectedException \InvalidArgumentException
45-
*/
4644
public function testValidateRequestUri(){
45+
$this->expectException(InvalidArgumentException::class);
46+
4747
new Request('GET', '///');
4848
}
4949

@@ -110,10 +110,9 @@ public function testWithRequestTarget(){
110110
$this->assertEquals('/', $r1->getRequestTarget());
111111
}
112112

113-
/**
114-
* @expectedException \InvalidArgumentException
115-
*/
116113
public function testRequestTargetDoesNotAllowSpaces(){
114+
$this->expectException(InvalidArgumentException::class);
115+
117116
(new Request('GET', '/'))->withRequestTarget('/foo bar');
118117
}
119118

@@ -190,11 +189,10 @@ public function testAddsPortToHeaderAndReplacePreviousPort(){
190189
$this->assertEquals('foo.com:8125', $r->getHeaderLine('host'));
191190
}
192191

193-
/**
194-
* @expectedException \InvalidArgumentException
195-
* @expectedExceptionMessage Method must be a string
196-
*/
197192
public function testWithMethodInvalidMethod(){
193+
$this->expectException(InvalidArgumentException::class);
194+
$this->expectExceptionMessage('Method must be a string');
195+
198196
(new Request('GET', '/foo'))->withMethod([]);
199197
}
200198

tests/Psr7/ResponseTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ class ResponseTest extends TestCase{
3131
*/
3232
protected $streamFactory;
3333

34-
protected function setUp(){
34+
protected function setUp():void{
3535
$this->responseFactory = new ResponseFactory;
3636
$this->streamFactory = new StreamFactory;
3737
}

tests/Psr7/ServerRequestTest.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
use chillerlan\HTTP\Psr7\{ServerRequest, UploadedFile, Uri};
1818
use chillerlan\HTTP\Psr17;
1919
use chillerlan\HTTP\Psr17\ServerRequestFactory;
20+
use InvalidArgumentException;
2021
use PHPUnit\Framework\TestCase;
2122

2223
class ServerRequestTest extends TestCase{
@@ -26,7 +27,7 @@ class ServerRequestTest extends TestCase{
2627
*/
2728
protected $serverRequestFactory;
2829

29-
protected function setUp(){
30+
protected function setUp():void{
3031
$this->serverRequestFactory = new ServerRequestFactory;
3132
}
3233

@@ -74,11 +75,10 @@ public function testParsedBody(){
7475
$this->assertSame($params, $r2->getParsedBody());
7576
}
7677

77-
/**
78-
* @expectedException \InvalidArgumentException
79-
* @expectedExceptionMessage parsed body value must be an array, object or null
80-
*/
8178
public function testParsedBodyInvalidArg(){
79+
$this->expectException(InvalidArgumentException::class);
80+
$this->expectExceptionMessage('parsed body value must be an array, object or null');
81+
8282
(new ServerRequest('GET', '/'))->withParsedBody('');
8383
}
8484

0 commit comments

Comments
 (0)