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

Commit 10162fb

Browse files
committedMar 6, 2024
:octocat: +OAuthProviderTestAbstract::get/setReflectionProperty()
1 parent e895010 commit 10162fb

File tree

4 files changed

+19
-11
lines changed

4 files changed

+19
-11
lines changed
 

Diff for: ‎tests/Providers/OAuth2ProviderTestAbstract.php

+5-5
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ public function testGetAuthURL():void{
6262
$this::assertArrayNotHasKey('client_secret', $query);
6363
$this::assertSame($this->options->key, $query['client_id']);
6464
$this::assertSame('code', $query['response_type']);
65-
$this::assertSame(explode('?', (string)$url)[0], $this->reflection->getProperty('authURL')->getValue($this->provider));
65+
$this::assertSame(explode('?', (string)$url)[0], $this->getReflectionProperty('authURL'));
6666
}
6767

6868
public function testGetAccessToken():void{
@@ -107,19 +107,19 @@ public function testGetRequestAuthorization():void{
107107
$request = $this->requestFactory->createRequest('GET', 'https://foo.bar');
108108
$token = new AccessToken(['accessTokenSecret' => 'test_token_secret', 'accessToken' => 'test_token']);
109109

110-
$authMethod = $this->reflection->getProperty('authMethod')->getValue($this->provider);
110+
$authMethod = $this->getReflectionProperty('authMethod');
111111

112112
// header (default)
113113
if($authMethod === OAuth2Interface::AUTH_METHOD_HEADER){
114114
$this::assertStringContainsString(
115-
$this->reflection->getProperty('authMethodHeader')->getValue($this->provider).' test_token',
115+
$this->getReflectionProperty('authMethodHeader').' test_token',
116116
$this->provider->getRequestAuthorization($request, $token)->getHeaderLine('Authorization')
117117
);
118118
}
119119
// query
120120
elseif($authMethod === OAuth2Interface::AUTH_METHOD_QUERY){
121121
$this::assertStringContainsString(
122-
$this->reflection->getProperty('authMethodQuery')->getValue($this->provider).'=test_token',
122+
$this->getReflectionProperty('authMethodQuery').'=test_token',
123123
$this->provider->getRequestAuthorization($request, $token)->getUri()->getQuery()
124124
);
125125
}
@@ -137,7 +137,7 @@ public function testRequestInvalidAuthTypeException():void{
137137
$this->expectException(OAuthException::class);
138138
$this->expectExceptionMessage('invalid auth type');
139139

140-
$this->reflection->getProperty('authMethod')->setValue($this->provider, -1);
140+
$this->setReflectionProperty('authMethod', -1);
141141

142142
$token = new AccessToken(['accessToken' => 'test_access_token_secret', 'expires' => 1]);
143143
$this->provider->storeAccessToken($token);

Diff for: ‎tests/Providers/OAuthProviderTestAbstract.php

+10-2
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,15 @@ protected function initTestProperties(array $properties):void{
123123
}
124124
}
125125

126-
protected function invokeReflectionMethod(string $method, array $args = []){
126+
protected function setReflectionProperty(string $property, mixed $value):void{
127+
$this->reflection->getProperty($property)->setValue($this->provider, $value);
128+
}
129+
130+
protected function getReflectionProperty(string $property):mixed{
131+
return $this->reflection->getProperty($property)->getValue($this->provider);
132+
}
133+
134+
protected function invokeReflectionMethod(string $method, array $args = []):mixed{
127135
return $this->reflection->getMethod($method)->invokeArgs($this->provider, $args);
128136
}
129137

@@ -166,7 +174,7 @@ public static function requestTargetProvider():array{
166174

167175
#[DataProvider('requestTargetProvider')]
168176
public function testGetRequestTarget(string $path, string $expected):void{
169-
$this->reflection->getProperty('apiURL')->setValue($this->provider, 'https://localhost/api/');
177+
$this->setReflectionProperty('apiURL', 'https://localhost/api/');
170178

171179
$this::assertSame($expected, $this->invokeReflectionMethod('getRequestTarget', [$path]));
172180
}

Diff for: ‎tests/Providers/Unit/MailChimpTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ public function testRequestInvalidAuthTypeException():void{
6060
$this->expectException(OAuthException::class);
6161
$this->expectExceptionMessage('invalid auth type');
6262

63-
$this->reflection->getProperty('authMethod')->setValue($this->provider, -1);
63+
$this->setReflectionProperty('authMethod', -1);
6464

6565
$this->storage->storeAccessToken($this->token, $this->provider->serviceName);
6666

Diff for: ‎tests/Providers/Unit/NPROneTest.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public function testRequestInvalidAuthTypeException():void{
5050
$this->expectException(OAuthException::class);
5151
$this->expectExceptionMessage('invalid auth type');
5252

53-
$this->reflection->getProperty('authMethod')->setValue($this->provider, -1);
53+
$this->setReflectionProperty('authMethod', -1);
5454

5555
$token = new AccessToken(['accessToken' => 'test_access_token_secret', 'expires' => 1]);
5656
$this->storage->storeAccessToken($token, $this->provider->serviceName);
@@ -73,11 +73,11 @@ public static function requestTargetProvider():array{
7373
public function testSetAPI():void{
7474
$this->provider = $this->initProvider($this->getProviderFQCN());
7575

76-
$this::assertSame('https://listening.api.npr.org', $this->reflection->getProperty('apiURL')->getValue($this->provider));
76+
$this::assertSame('https://listening.api.npr.org', $this->getReflectionProperty('apiURL'));
7777

7878
$this->provider->setAPI('station');
7979

80-
$this::assertSame('https://station.api.npr.org', $this->reflection->getProperty('apiURL')->getValue($this->provider));
80+
$this::assertSame('https://station.api.npr.org', $this->getReflectionProperty('apiURL'));
8181
}
8282

8383
}

0 commit comments

Comments
 (0)
This repository has been archived.