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

Commit 94cc2d2

Browse files
committed
🚿 test coverage
1 parent 1d065b5 commit 94cc2d2

File tree

3 files changed

+54
-7
lines changed

3 files changed

+54
-7
lines changed

src/Foursquare/Foursquare.php

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,7 @@ public function request(
4747
array $headers = null
4848
):ResponseInterface{
4949

50-
$queryparams = [];
51-
$querystring = parseUrl($this->apiURL.$path)['query'] ?? '';
52-
53-
if(!empty($querystring)){
54-
$queryparams = $this->parseQuery($querystring);
55-
}
50+
$queryparams = $this->parseQuery(parseUrl($this->apiURL.$path)['query'] ?? '');
5651

5752
$queryparams['v'] = $this::API_VERSIONDATE;
5853
$queryparams['m'] = 'foursquare';

src/Steam/SteamOpenID.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,7 @@ protected function parseTokenResponse(ResponseInterface $response):AccessToken{
134134

135135
// the response is only validation, so we'll just return an empty token and add the id in the next step
136136
return new AccessToken([
137+
'accessToken' => 'SteamID',
137138
'provider' => $this->serviceName,
138139
'expires' => AccessToken::EOL_NEVER_EXPIRES,
139140
]);

tests/Steam/SteamOpenIDTest.php

Lines changed: 52 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
namespace chillerlan\OAuthTest\Providers\Steam;
1212

13+
use chillerlan\OAuth\Core\ProviderException;
1314
use chillerlan\OAuth\Providers\Steam\SteamOpenID;
1415
use chillerlan\OAuthTest\Providers\OAuthProviderTestAbstract;
1516

@@ -20,16 +21,21 @@
2021
*/
2122
class SteamOpenIDTest extends OAuthProviderTestAbstract{
2223

24+
protected const ID_VALID = "ns:http://specs.openid.net/auth/2.0\x0ais_valid:true\x0a";
25+
protected const ID_INVALID = "ns:http://specs.openid.net/auth/2.0\x0ais_valid:false\x0a";
26+
2327
protected string $FQN = SteamOpenID::class;
2428

2529
protected array $testResponses = [
26-
'/steam/id' => "ns:http://specs.openid.net/auth/2.0\x0ais_valid:true\x0a",
30+
'/steam/id' => self::ID_VALID,
31+
'/steam/api/request' => '{"data":"such data! much wow!"}',
2732
];
2833

2934
protected function setUp():void{
3035
parent::setUp(); // TODO: Change the autogenerated stub
3136

3237
$this->setProperty($this->provider, 'accessTokenURL', 'https://localhost/steam/id');
38+
$this->setProperty($this->provider, 'apiURL', '/steam/api/request');
3339
}
3440

3541
public function testGetAuthURL():void{
@@ -63,4 +69,49 @@ public function testGetAccessToken():void{
6369

6470
$this::assertSame('69420', $this->provider->getAccessToken($received)->accessToken);
6571
}
72+
73+
public function testParseTokenResponse():void{
74+
$r = $this->responseFactory
75+
->createResponse()
76+
->withBody($this->streamFactory->createStream(self::ID_VALID))
77+
;
78+
79+
$token = $this
80+
->getMethod('parseTokenResponse')
81+
->invokeArgs($this->provider, [$r]);
82+
83+
$this::assertSame('SteamID', $token->accessToken);
84+
}
85+
86+
public function testParseTokenResponseNoData():void{
87+
$this->expectException(ProviderException::class);
88+
$this->expectExceptionMessage('unable to parse token response');
89+
90+
$this
91+
->getMethod('parseTokenResponse')
92+
->invokeArgs($this->provider, [$this->responseFactory->createResponse()]);
93+
}
94+
95+
public function testParseTokenResponseInvalidID():void{
96+
$this->expectException(ProviderException::class);
97+
$this->expectExceptionMessage('invalid id');
98+
99+
$r = $this->responseFactory
100+
->createResponse()
101+
->withBody($this->streamFactory->createStream(self::ID_INVALID))
102+
;
103+
104+
$this
105+
->getMethod('parseTokenResponse')
106+
->invokeArgs($this->provider, [$r]);
107+
}
108+
109+
// coverage
110+
public function testRequest():void{
111+
$r = $this->provider->request('');
112+
113+
$this::assertSame('such data! much wow!', $this->responseJson($r)->data);
114+
}
115+
116+
66117
}

0 commit comments

Comments
 (0)