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

Commit e895010

Browse files
committed
:octocat: +OAuthProviderTestAbstract::invokeReflectionMethod()
1 parent 60c029e commit e895010

File tree

6 files changed

+48
-87
lines changed

6 files changed

+48
-87
lines changed

tests/Providers/OAuth1ProviderTestAbstract.php

Lines changed: 9 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -57,12 +57,10 @@ public function testGetAuthURL():void{
5757
}
5858

5959
public function testGetSignature():void{
60-
$signature = $this->reflection
61-
->getMethod('getSignature')
62-
->invokeArgs(
63-
$this->provider,
64-
['http://localhost/api/whatever', ['foo' => 'bar', 'oauth_signature' => 'should not see me!'], 'GET']
65-
);
60+
$signature = $this->invokeReflectionMethod(
61+
'getSignature',
62+
['http://localhost/api/whatever', ['foo' => 'bar', 'oauth_signature' => 'should not see me!'], 'GET'],
63+
);
6664

6765
$this::assertSame('ygg22quLhpyegiyr7yl4hLAP9S8=', $signature);
6866
}
@@ -71,9 +69,7 @@ public function testGetSignatureInvalidURLException():void{
7169
$this->expectException(ProviderException::class);
7270
$this->expectExceptionMessage('getSignature: invalid url');
7371

74-
$this->reflection
75-
->getMethod('getSignature')
76-
->invokeArgs($this->provider, ['whatever', [], 'GET']);
72+
$this->invokeReflectionMethod('getSignature', ['whatever', [], 'GET']);
7773
}
7874

7975
public function testGetAccessToken():void{
@@ -90,9 +86,7 @@ public function testParseTokenResponseNoDataException():void{
9086
$this->expectException(ProviderException::class);
9187
$this->expectExceptionMessage('unable to parse token response');
9288

93-
$this->reflection
94-
->getMethod('parseTokenResponse')
95-
->invokeArgs($this->provider, [$this->responseFactory->createResponse(), false]);
89+
$this->invokeReflectionMethod('parseTokenResponse', [$this->responseFactory->createResponse(), false]);
9690
}
9791

9892
public function testParseTokenResponseErrorException():void{
@@ -101,10 +95,7 @@ public function testParseTokenResponseErrorException():void{
10195

10296
$body = $this->streamFactory->createStream('error=whatever');
10397

104-
$this->reflection
105-
->getMethod('parseTokenResponse')
106-
->invokeArgs($this->provider, [$this->responseFactory->createResponse()->withBody($body), false])
107-
;
98+
$this->invokeReflectionMethod('parseTokenResponse', [$this->responseFactory->createResponse()->withBody($body), false]);
10899
}
109100

110101
public function testParseTokenResponseNoTokenException():void{
@@ -113,10 +104,7 @@ public function testParseTokenResponseNoTokenException():void{
113104

114105
$body = $this->streamFactory->createStream('oauth_token=whatever');
115106

116-
$this->reflection
117-
->getMethod('parseTokenResponse')
118-
->invokeArgs($this->provider, [$this->responseFactory->createResponse()->withBody($body), false])
119-
;
107+
$this->invokeReflectionMethod('parseTokenResponse', [$this->responseFactory->createResponse()->withBody($body), false]);
120108
}
121109

122110
public function testParseTokenResponseCallbackUnconfirmedException():void{
@@ -125,10 +113,7 @@ public function testParseTokenResponseCallbackUnconfirmedException():void{
125113

126114
$body = $this->streamFactory->createStream('oauth_token=whatever&oauth_token_secret=whatever_secret');
127115

128-
$this->reflection
129-
->getMethod('parseTokenResponse')
130-
->invokeArgs($this->provider, [$this->responseFactory->createResponse()->withBody($body), true])
131-
;
116+
$this->invokeReflectionMethod('parseTokenResponse', [$this->responseFactory->createResponse()->withBody($body), true]);
132117
}
133118

134119
public function testGetRequestAuthorization():void{

tests/Providers/OAuth2ProviderTestAbstract.php

Lines changed: 15 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -77,36 +77,30 @@ public function testParseTokenResponseNoDataException():void{
7777
$this->expectException(ProviderException::class);
7878
$this->expectExceptionMessage('unable to parse token response');
7979

80-
$this->reflection
81-
->getMethod('parseTokenResponse')
82-
->invokeArgs($this->provider, [
83-
$this->responseFactory->createResponse()->withBody($this->streamFactory->createStream('""')),
84-
])
85-
;
80+
$this->invokeReflectionMethod(
81+
'parseTokenResponse',
82+
[$this->responseFactory->createResponse()->withBody($this->streamFactory->createStream('""'))],
83+
);
8684
}
8785

8886
public function testParseTokenResponseErrorException():void{
8987
$this->expectException(ProviderException::class);
9088
$this->expectExceptionMessage('error retrieving access token');
9189

92-
$this->reflection
93-
->getMethod('parseTokenResponse')
94-
->invokeArgs($this->provider, [
95-
$this->responseFactory->createResponse()->withBody($this->streamFactory->createStream('{"error":"whatever"}')),
96-
])
97-
;
90+
$this->invokeReflectionMethod(
91+
'parseTokenResponse',
92+
[$this->responseFactory->createResponse()->withBody($this->streamFactory->createStream('{"error":"whatever"}'))],
93+
);
9894
}
9995

10096
public function testParseTokenResponseNoTokenException():void{
10197
$this->expectException(ProviderException::class);
10298
$this->expectExceptionMessage('token missing');
10399

104-
$this->reflection
105-
->getMethod('parseTokenResponse')
106-
->invokeArgs($this->provider, [
107-
$this->responseFactory->createResponse()->withBody($this->streamFactory->createStream('{"foo":"bar"}')),
108-
])
109-
;
100+
$this->invokeReflectionMethod(
101+
'parseTokenResponse',
102+
[$this->responseFactory->createResponse()->withBody($this->streamFactory->createStream('{"foo":"bar"}'))],
103+
);
110104
}
111105

112106
public function testGetRequestAuthorization():void{
@@ -158,9 +152,7 @@ public function testCheckCSRFState():void{
158152
}
159153

160154
// will throw an exception if it goes wrong
161-
$this->reflection
162-
->getMethod('checkState')
163-
->invokeArgs($this->provider, ['test_state']);
155+
$this->invokeReflectionMethod('checkState', ['test_state']);
164156

165157
$this->expectNotToPerformAssertions();
166158
}
@@ -174,9 +166,7 @@ public function testCheckStateInvalidException():void{
174166
$this->expectException(ProviderException::class);
175167
$this->expectExceptionMessage('invalid state');
176168

177-
$this->reflection
178-
->getMethod('checkState')
179-
->invoke($this->provider);
169+
$this->invokeReflectionMethod('checkState');
180170
}
181171

182172
public function testCheckStateInvalidCSRFStateException():void{
@@ -188,9 +178,7 @@ public function testCheckStateInvalidCSRFStateException():void{
188178
$this->expectException(ProviderException::class);
189179
$this->expectExceptionMessage('invalid CSRF state');
190180

191-
$this->reflection
192-
->getMethod('checkState')
193-
->invokeArgs($this->provider, ['invalid_test_state']);
181+
$this->invokeReflectionMethod('checkState', ['invalid_test_state']);
194182
}
195183

196184
public function testRefreshAccessTokenNoRefreshTokenAvailable():void{

tests/Providers/OAuthProviderTestAbstract.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,10 @@ protected function initTestProperties(array $properties):void{
123123
}
124124
}
125125

126+
protected function invokeReflectionMethod(string $method, array $args = []){
127+
return $this->reflection->getMethod($method)->invokeArgs($this->provider, $args);
128+
}
129+
126130
public function testOAuthInstance():void{
127131
$this::assertInstanceOf(OAuthInterface::class, $this->provider);
128132
}
@@ -163,9 +167,8 @@ public static function requestTargetProvider():array{
163167
#[DataProvider('requestTargetProvider')]
164168
public function testGetRequestTarget(string $path, string $expected):void{
165169
$this->reflection->getProperty('apiURL')->setValue($this->provider, 'https://localhost/api/');
166-
$requestTarget = $this->reflection->getMethod('getRequestTarget')->invokeArgs($this->provider, [$path]);
167170

168-
$this::assertSame($expected, $requestTarget);
171+
$this::assertSame($expected, $this->invokeReflectionMethod('getRequestTarget', [$path]));
169172
}
170173

171174
}

tests/Providers/Unit/DeezerTest.php

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,10 @@ public function testGetAuthURL():void{
4747
}
4848

4949
public function testParseTokenResponse():void{
50-
$token = $this->reflection
51-
->getMethod('parseTokenResponse')
52-
->invokeArgs($this->provider, [
53-
$this->responseFactory->createResponse()->withBody($this->streamFactory->createStream('access_token=whatever'))
54-
]);
50+
$token = $this->invokeReflectionMethod(
51+
'parseTokenResponse',
52+
[$this->responseFactory->createResponse()->withBody($this->streamFactory->createStream('access_token=whatever'))],
53+
);
5554

5655
$this::assertInstanceOf(AccessToken::class, $token);
5756
$this::assertSame('whatever', $token->accessToken);
@@ -61,11 +60,10 @@ public function testParseTokenResponseErrorException():void{
6160
$this->expectException(ProviderException::class);
6261
$this->expectExceptionMessage('error retrieving access token:');
6362

64-
$this->reflection
65-
->getMethod('parseTokenResponse')
66-
->invokeArgs($this->provider, [
67-
$this->responseFactory->createResponse()->withBody($this->streamFactory->createStream('error_reason=whatever'))
68-
]);
63+
$this->invokeReflectionMethod(
64+
'parseTokenResponse',
65+
[$this->responseFactory->createResponse()->withBody($this->streamFactory->createStream('error_reason=whatever'))],
66+
);
6967
}
7068

7169
public function testParseTokenResponseNoDataException():void{

tests/Providers/Unit/LastFMTest.php

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,10 @@ public function testGetAuthURL():void{
4848
}
4949

5050
public function testGetSignature():void{
51-
$signature = $this->reflection
52-
->getMethod('getSignature')
53-
->invokeArgs($this->provider, [['foo' => 'bar', 'format' => 'whatever', 'callback' => 'nope']]);
51+
$signature = $this->invokeReflectionMethod(
52+
'getSignature',
53+
[['foo' => 'bar', 'format' => 'whatever', 'callback' => 'nope']],
54+
);
5455

5556
$this::assertSame('cb143650fa678449f5492a2aa6fab216', $signature);
5657
}
@@ -61,9 +62,7 @@ public function testParseTokenResponse():void{
6162
->withBody($this->streamFactory->createStream('{"session":{"key":"whatever"}}'))
6263
;
6364

64-
$token = $this->reflection
65-
->getMethod('parseTokenResponse')
66-
->invokeArgs($this->provider, [$r]);
65+
$token = $this->invokeReflectionMethod('parseTokenResponse', [$r]);
6766

6867
$this::assertSame('whatever', $token->accessToken);
6968
}
@@ -72,9 +71,7 @@ public function testParseTokenResponseNoData():void{
7271
$this->expectException(ProviderException::class);
7372
$this->expectExceptionMessage('unable to parse token response');
7473

75-
$this->reflection
76-
->getMethod('parseTokenResponse')
77-
->invokeArgs($this->provider, [$this->responseFactory->createResponse()]);
74+
$this->invokeReflectionMethod('parseTokenResponse', [$this->responseFactory->createResponse()]);
7875
}
7976

8077
public function testParseTokenResponseError():void{
@@ -86,9 +83,7 @@ public function testParseTokenResponseError():void{
8683
->withBody($this->streamFactory->createStream('{"error":42,"message":"whatever"}'))
8784
;
8885

89-
$this->reflection
90-
->getMethod('parseTokenResponse')
91-
->invokeArgs($this->provider, [$r]);
86+
$this->invokeReflectionMethod('parseTokenResponse', [$r]);
9287
}
9388

9489
public function testParseTokenResponseNoToken():void{
@@ -97,9 +92,7 @@ public function testParseTokenResponseNoToken():void{
9792

9893
$r = $this->responseFactory->createResponse()->withBody($this->streamFactory->createStream('{"session":[]}'));
9994

100-
$this->reflection
101-
->getMethod('parseTokenResponse')
102-
->invokeArgs($this->provider, [$r]);
95+
$this->invokeReflectionMethod('parseTokenResponse', [$r]);
10396
}
10497

10598
public function testGetAccessToken():void{

tests/Providers/Unit/SteamOpenIDTest.php

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -83,9 +83,7 @@ public function testParseTokenResponse():void{
8383
->withBody($this->streamFactory->createStream(self::ID_VALID))
8484
;
8585

86-
$token = $this->reflection
87-
->getMethod('parseTokenResponse')
88-
->invokeArgs($this->provider, [$r]);
86+
$token = $this->invokeReflectionMethod('parseTokenResponse', [$r]);
8987

9088
$this::assertSame('SteamID', $token->accessToken);
9189
}
@@ -94,9 +92,7 @@ public function testParseTokenResponseNoData():void{
9492
$this->expectException(ProviderException::class);
9593
$this->expectExceptionMessage('unable to parse token response');
9694

97-
$this->reflection
98-
->getMethod('parseTokenResponse')
99-
->invokeArgs($this->provider, [$this->responseFactory->createResponse()]);
95+
$this->invokeReflectionMethod('parseTokenResponse', [$this->responseFactory->createResponse()]);
10096
}
10197

10298
public function testParseTokenResponseInvalidID():void{
@@ -108,9 +104,7 @@ public function testParseTokenResponseInvalidID():void{
108104
->withBody($this->streamFactory->createStream(self::ID_INVALID))
109105
;
110106

111-
$this->reflection
112-
->getMethod('parseTokenResponse')
113-
->invokeArgs($this->provider, [$r]);
107+
$this->invokeReflectionMethod('parseTokenResponse', [$r]);
114108
}
115109

116110
// coverage

0 commit comments

Comments
 (0)