Skip to content
This repository was archived by the owner on Mar 23, 2024. It is now read-only.

Commit bf51d58

Browse files
committed
:octocat: phpunit 8.0
1 parent 92020e5 commit bf51d58

9 files changed

+80
-93
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
},
3131
"require-dev": {
3232
"chillerlan/php-log": "^3.0",
33-
"phpunit/phpunit": "^7.5"
33+
"phpunit/phpunit": "^8.0"
3434
},
3535
"autoload": {
3636
"psr-4": {

tests/API/APITestAbstract.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@
1616
use chillerlan\HTTP\Psr18\CurlClient;
1717
use chillerlan\HTTP\Psr7;
1818
use chillerlan\Logger\{Log, LogOptionsTrait, Output\LogOutputAbstract};
19-
use chillerlan\OAuth\{OAuthOptions, Core\AccessToken, Core\OAuthInterface, Storage\MemoryStorage};
19+
use chillerlan\OAuth\{Core\AccessToken, Core\OAuthInterface, OAuthOptions, Storage\MemoryStorage};
2020
use chillerlan\Settings\SettingsContainerInterface;
21-
use Psr\Http\Client\ClientInterface;
2221
use PHPUnit\Framework\TestCase;
22+
use Psr\Http\Client\ClientInterface;
2323
use Psr\Http\Message\{RequestInterface, ResponseInterface};
2424
use Psr\Log\LoggerInterface;
2525

@@ -65,7 +65,7 @@ abstract class APITestAbstract extends TestCase{
6565
*/
6666
protected $requestDelay = 0.25;
6767

68-
protected function setUp(){
68+
protected function setUp():void{
6969
ini_set('date.timezone', 'Europe/Amsterdam');
7070

7171
$file = file_exists($this->CFG.'/.env') ? '.env' : '.env_travis';

tests/Core/AccessTokenTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ class AccessTokenTest extends TestCase{
2121
*/
2222
protected $token;
2323

24-
protected function setUp(){
24+
protected function setUp():void{
2525
$this->token = new AccessToken;
2626
}
2727

tests/Providers/OAuth1ProviderTestAbstract.php

Lines changed: 24 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@
1212

1313
namespace chillerlan\OAuthTest\Providers;
1414

15-
use chillerlan\HTTP\Psr7\{Request, Response};
1615
use chillerlan\HTTP\Psr17;
17-
use chillerlan\OAuth\Core\{AccessToken, OAuth1Interface};
16+
use chillerlan\HTTP\Psr7\{Request, Response};
17+
use chillerlan\OAuth\Core\{AccessToken, OAuth1Interface, ProviderException};
1818

1919
/**
2020
* @property \chillerlan\OAuth\Core\OAuth1Interface $provider
@@ -27,7 +27,7 @@ abstract class OAuth1ProviderTestAbstract extends ProviderTestAbstract{
2727
'/oauth1/api/request' => '{"data":"such data! much wow!"}',
2828
];
2929

30-
protected function setUp(){
30+
protected function setUp():void{
3131
parent::setUp();
3232

3333
$this->setProperty($this->provider, 'requestTokenURL', 'https://localhost/oauth1/request_token');
@@ -54,11 +54,10 @@ public function testGetSignature(){
5454
$this->assertSame('ygg22quLhpyegiyr7yl4hLAP9S8=', $signature);
5555
}
5656

57-
/**
58-
* @expectedException \chillerlan\OAuth\Core\ProviderException
59-
* @expectedExceptionMessage getSignature: invalid url
60-
*/
6157
public function testGetSignatureInvalidURLException(){
58+
$this->expectException(ProviderException::class);
59+
$this->expectExceptionMessage('getSignature: invalid url');
60+
6261
$this
6362
->getMethod('getSignature')
6463
->invokeArgs($this->provider, ['whatever', [], 'GET']);
@@ -74,41 +73,37 @@ public function testGetAccessToken(){
7473
$this->assertSame('test_access_token_secret', $token->accessTokenSecret);
7574
}
7675

77-
/**
78-
* @expectedException \chillerlan\OAuth\Core\ProviderException
79-
* @expectedExceptionMessage unable to parse token response
80-
*/
81-
public function testParseTokenResponseNoData(){
76+
public function testParseTokenResponseNoDataException(){
77+
$this->expectException(ProviderException::class);
78+
$this->expectExceptionMessage('unable to parse token response');
79+
8280
$this->getMethod('parseTokenResponse')->invokeArgs($this->provider, [new Response]);
8381
}
8482

85-
/**
86-
* @expectedException \chillerlan\OAuth\Core\ProviderException
87-
* @expectedExceptionMessage error retrieving access token
88-
*/
89-
public function testParseTokenResponseError(){
83+
public function testParseTokenResponseErrorException(){
84+
$this->expectException(ProviderException::class);
85+
$this->expectExceptionMessage('error retrieving access token');
86+
9087
$this
9188
->getMethod('parseTokenResponse')
9289
->invokeArgs($this->provider, [(new Response)->withBody(Psr17\create_stream_from_input('error=whatever'))])
9390
;
9491
}
9592

96-
/**
97-
* @expectedException \chillerlan\OAuth\Core\ProviderException
98-
* @expectedExceptionMessage invalid token
99-
*/
100-
public function testParseTokenResponseNoToken(){
93+
public function testParseTokenResponseNoTokenException(){
94+
$this->expectException(ProviderException::class);
95+
$this->expectExceptionMessage('invalid token');
96+
10197
$this
10298
->getMethod('parseTokenResponse')
10399
->invokeArgs($this->provider, [(new Response)->withBody(Psr17\create_stream_from_input('oauth_token=whatever'))])
104100
;
105101
}
106102

107-
/**
108-
* @expectedException \chillerlan\OAuth\Core\ProviderException
109-
* @expectedExceptionMessage oauth callback unconfirmed
110-
*/
111-
public function testParseTokenResponseCallbackUnconfirmed(){
103+
public function testParseTokenResponseCallbackUnconfirmedException(){
104+
$this->expectException(ProviderException::class);
105+
$this->expectExceptionMessage('oauth callback unconfirmed');
106+
112107
$this
113108
->getMethod('parseTokenResponse')
114109
->invokeArgs($this->provider, [(new Response)->withBody(Psr17\create_stream_from_input('oauth_token=whatever&oauth_token_secret=whatever_secret')), true])
@@ -124,8 +119,8 @@ public function testGetRequestAuthorization(){
124119
)
125120
->getHeaderLine('Authorization');
126121

127-
$this->assertContains('OAuth oauth_consumer_key="'.$this->options->key.'"', $authHeader);
128-
$this->assertContains('oauth_token="test_token"', $authHeader);
122+
$this->assertStringContainsString('OAuth oauth_consumer_key="'.$this->options->key.'"', $authHeader);
123+
$this->assertStringContainsString('oauth_token="test_token"', $authHeader);
129124
}
130125

131126
public function testRequest(){

tests/Providers/OAuth2ProviderTestAbstract.php

Lines changed: 30 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,10 @@
1212

1313
namespace chillerlan\OAuthTest\Providers;
1414

15-
use chillerlan\HTTP\Psr7\{Request, Response};
1615
use chillerlan\HTTP\Psr17;
17-
use chillerlan\OAuth\Core\{AccessToken, AccessTokenForRefresh, ClientCredentials, CSRFToken, OAuth2Interface, TokenRefresh};
16+
use chillerlan\HTTP\Psr7\{Request, Response};
17+
use chillerlan\OAuth\Core\{AccessToken, AccessTokenForRefresh, ClientCredentials, CSRFToken, OAuth2Interface, ProviderException, TokenRefresh};
18+
use chillerlan\OAuth\OAuthException;
1819

1920
/**
2021
* @property \chillerlan\OAuth\Core\OAuth2Interface $provider
@@ -43,7 +44,7 @@ abstract class OAuth2ProviderTestAbstract extends ProviderTestAbstract{
4344
'/oauth2/api/request/test/get' => ['foo'],
4445
];
4546

46-
protected function setUp(){
47+
protected function setUp():void{
4748
parent::setUp();
4849

4950
$this->setProperty($this->provider, 'apiURL', 'https://localhost/oauth2/api/request');
@@ -84,33 +85,30 @@ public function testGetAccessToken(){
8485
$this->assertGreaterThan(time(), $token->expires);
8586
}
8687

87-
/**
88-
* @expectedException \chillerlan\OAuth\Core\ProviderException
89-
* @expectedExceptionMessage unable to parse token response
90-
*/
91-
public function testParseTokenResponseNoData(){
88+
public function testParseTokenResponseNoDataException(){
89+
$this->expectException(ProviderException::class);
90+
$this->expectExceptionMessage('unable to parse token response');
91+
9292
$this
9393
->getMethod('parseTokenResponse')
9494
->invokeArgs($this->provider, [(new Response)->withBody(Psr17\create_stream_from_input(''))])
9595
;
9696
}
9797

98-
/**
99-
* @expectedException \chillerlan\OAuth\Core\ProviderException
100-
* @expectedExceptionMessage error retrieving access token
101-
*/
102-
public function testParseTokenResponseError(){
98+
public function testParseTokenResponseErrorException(){
99+
$this->expectException(ProviderException::class);
100+
$this->expectExceptionMessage('error retrieving access token');
101+
103102
$this
104103
->getMethod('parseTokenResponse')
105104
->invokeArgs($this->provider, [(new Response)->withBody(Psr17\create_stream_from_input('{"error":"whatever"}'))])
106105
;
107106
}
108107

109-
/**
110-
* @expectedException \chillerlan\OAuth\Core\ProviderException
111-
* @expectedExceptionMessage token missing
112-
*/
113-
public function testParseTokenResponseNoToken(){
108+
public function testParseTokenResponseNoTokenException(){
109+
$this->expectException(ProviderException::class);
110+
$this->expectExceptionMessage('token missing');
111+
114112
$this
115113
->getMethod('parseTokenResponse')
116114
->invokeArgs($this->provider, [(new Response)->withBody(Psr17\create_stream_from_input('{"foo":"bar"}'))])
@@ -125,11 +123,11 @@ public function testGetRequestAuthorization(){
125123

126124
// header (default)
127125
if(isset(OAuth2Interface::AUTH_METHODS_HEADER[$authMethod])){
128-
$this->assertContains(OAuth2Interface::AUTH_METHODS_HEADER[$authMethod].'test_token', $this->provider->getRequestAuthorization($request, $token)->getHeaderLine('Authorization'));
126+
$this->assertStringContainsString(OAuth2Interface::AUTH_METHODS_HEADER[$authMethod].'test_token', $this->provider->getRequestAuthorization($request, $token)->getHeaderLine('Authorization'));
129127
}
130128
// query
131129
elseif(isset(OAuth2Interface::AUTH_METHODS_QUERY[$authMethod])){
132-
$this->assertContains(OAuth2Interface::AUTH_METHODS_QUERY[$authMethod].'=test_token', $this->provider->getRequestAuthorization($request, $token)->getUri()->getQuery());
130+
$this->assertStringContainsString(OAuth2Interface::AUTH_METHODS_QUERY[$authMethod].'=test_token', $this->provider->getRequestAuthorization($request, $token)->getUri()->getQuery());
133131
}
134132

135133
}
@@ -141,11 +139,10 @@ public function testRequest(){
141139
$this->assertSame('such data! much wow!', json_decode($this->provider->request('')->getBody()->getContents())->data);
142140
}
143141

144-
/**
145-
* @expectedException \chillerlan\OAuth\OAuthException
146-
* @expectedExceptionMessage invalid auth type
147-
*/
148-
public function testRequestInvalidAuthType(){
142+
public function testRequestInvalidAuthTypeException(){
143+
$this->expectException(OAuthException::class);
144+
$this->expectExceptionMessage('invalid auth type');
145+
149146
$this->setProperty($this->provider, 'authMethod', 'foo');
150147
$token = new AccessToken(['accessToken' => 'test_access_token_secret', 'expires' => 1]);
151148
$this->storage->storeAccessToken($this->provider->serviceName, $token);
@@ -168,11 +165,9 @@ public function testCheckCSRFState(){
168165
$this->expectNotToPerformAssertions();
169166
}
170167

171-
/**
172-
* @expectedException \chillerlan\OAuth\Core\ProviderException
173-
* @expectedExceptionMessage invalid state
174-
*/
175-
public function testCheckStateInvalid(){
168+
public function testCheckStateInvalidException(){
169+
$this->expectException(ProviderException::class);
170+
$this->expectExceptionMessage('invalid state');
176171

177172
if(!$this->provider instanceof CSRFToken){
178173
$this->markTestSkipped('CSRFToken N/A');
@@ -184,11 +179,9 @@ public function testCheckStateInvalid(){
184179
->invoke($this->provider);
185180
}
186181

187-
/**
188-
* @expectedException \chillerlan\OAuth\Core\ProviderException
189-
* @expectedExceptionMessage invalid CSRF state
190-
*/
191-
public function testCheckStateInvalidCSRFState(){
182+
public function testCheckStateInvalidCSRFStateException(){
183+
$this->expectException(ProviderException::class);
184+
$this->expectExceptionMessage('invalid CSRF state');
192185

193186
if(!$this->provider instanceof CSRFToken){
194187
$this->markTestSkipped('CSRFToken N/A');
@@ -200,11 +193,9 @@ public function testCheckStateInvalidCSRFState(){
200193
->invokeArgs($this->provider, ['invalid_test_state']);
201194
}
202195

203-
/**
204-
* @expectedException \chillerlan\OAuth\OAuthException
205-
* @expectedExceptionMessage no refresh token available, token expired [
206-
*/
207196
public function testRefreshAccessTokenNoRefreshTokenAvailable(){
197+
$this->expectException(OAuthException::class);
198+
$this->expectExceptionMessage('no refresh token available, token expired [');
208199

209200
if(!$this->provider instanceof TokenRefresh){
210201
$this->markTestSkipped('TokenRefresh N/A');

tests/Providers/ProviderTestAbstract.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@
1313
namespace chillerlan\OAuthTest\Providers;
1414

1515
use chillerlan\HTTP\{Psr17, Psr7\Response};
16-
use chillerlan\OAuth\Core\{AccessToken, OAuth1Interface, OAuth2Interface, OAuthInterface};
1716
use chillerlan\OAuth\{OAuthOptions, Storage\MemoryStorage};
18-
use Psr\Http\Client\ClientInterface;
17+
use chillerlan\OAuth\Core\{AccessToken, OAuth1Interface, OAuth2Interface, OAuthInterface};
1918
use PHPUnit\Framework\TestCase;
19+
use Psr\Http\Client\ClientInterface;
2020
use Psr\Http\Message\{RequestInterface, ResponseInterface};
2121
use ReflectionClass, ReflectionMethod, ReflectionProperty;
2222

@@ -52,7 +52,7 @@ abstract class ProviderTestAbstract extends TestCase{
5252
*/
5353
protected $responses;
5454

55-
protected function setUp(){
55+
protected function setUp():void{
5656

5757
$this->options = new OAuthOptions([
5858
'key' => 'testkey',

tests/Storage/MemoryStorageTest.php

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

1717
class MemoryStorageTest extends StorageTestAbstract{
1818

19-
protected function setUp(){
19+
protected function setUp():void{
2020
parent::setUp();
2121

2222
$this->storage = new MemoryStorage;

tests/Storage/SessionStorageTest.php

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,14 @@
1212

1313
namespace chillerlan\OAuthTest\Storage;
1414

15-
use chillerlan\OAuth\Storage\SessionStorage;
15+
use chillerlan\OAuth\Storage\{OAuthStorageException, SessionStorage};
1616

1717
/**
1818
* @runInSeparateProcess
1919
*/
2020
class SessionStorageTest extends StorageTestAbstract{
2121

22-
protected function setUp(){
22+
protected function setUp():void{
2323
parent::setUp();
2424

2525
$this->storage = new SessionStorage;
@@ -40,20 +40,22 @@ public function testClearAllAccessTokens(){
4040
}
4141

4242
/**
43-
* @expectedException \chillerlan\OAuth\Storage\OAuthStorageException
44-
* @expectedExceptionMessage state not found
4543
* @runInSeparateProcess
4644
*/
4745
public function testRetrieveCSRFStateNotFoundException(){
46+
$this->expectException(OAuthStorageException::class);
47+
$this->expectExceptionMessage('state not found');
48+
4849
parent::testRetrieveCSRFStateNotFoundException();
4950
}
5051

5152
/**
52-
* @expectedException \chillerlan\OAuth\Storage\OAuthStorageException
53-
* @expectedExceptionMessage token not found
5453
* @runInSeparateProcess
5554
*/
5655
public function testRetrieveAccessTokenNotFoundException(){
56+
$this->expectException(OAuthStorageException::class);
57+
$this->expectExceptionMessage('token not found');
58+
5759
parent::testRetrieveAccessTokenNotFoundException();
5860
}
5961

0 commit comments

Comments
 (0)