Skip to content

Commit 6b517c4

Browse files
author
Южаков Георгий
committed
Code style fix
1 parent ba4c0b5 commit 6b517c4

3 files changed

Lines changed: 71 additions & 72 deletions

File tree

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
],
2020
"scripts" : {
2121
"tests" : [
22-
"./vendor/bin/phpunit"
22+
"./vendor/bin/phpunit --color=always"
2323
],
2424
"check" : [
2525
"./vendor/bin/php-cs-fixer fix --ansi --dry-run --diff",

src/OAuth/OAuth2/Service/Xing.php

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22

33
namespace OAuth\OAuth2\Service;
44

5-
use OAuth\OAuth2\Token\StdOAuth2Token;
5+
use OAuth\Common\Consumer\CredentialsInterface;
6+
use OAuth\Common\Http\Client\ClientInterface;
67
use OAuth\Common\Http\Exception\TokenResponseException;
78
use OAuth\Common\Http\Uri\Uri;
8-
use OAuth\Common\Consumer\CredentialsInterface;
99
use OAuth\Common\Http\Uri\UriInterface;
1010
use OAuth\Common\Storage\TokenStorageInterface;
11-
use OAuth\Common\Http\Client\ClientInterface;
11+
use OAuth\OAuth2\Token\StdOAuth2Token;
1212

1313
/**
1414
* @see https://dev.xing.com/docs/authentication
@@ -19,10 +19,10 @@ public function __construct(
1919
CredentialsInterface $credentials,
2020
ClientInterface $httpClient,
2121
TokenStorageInterface $storage,
22-
$scopes = array(),
23-
UriInterface $baseApiUri = null,
22+
$scopes = [],
23+
?UriInterface $baseApiUri = null,
2424
$stateParameterInAutUrl = false,
25-
$apiVersion = ""
25+
$apiVersion = ''
2626
) {
2727
parent::__construct($credentials, $httpClient, $storage, $scopes, $baseApiUri, $stateParameterInAutUrl, $apiVersion);
2828

@@ -79,9 +79,7 @@ protected function parseAccessTokenResponse($responseBody)
7979
$token->setLifeTime($data['expires_in']);
8080
$token->setRefreshToken($data['refresh_token']);
8181

82-
unset($data['access_token']);
83-
unset($data['expires_in']);
84-
unset($data['refresh_token']);
82+
unset($data['access_token'], $data['expires_in'], $data['refresh_token']);
8583

8684
$token->setExtraParams($data);
8785

tests/Unit/OAuth2/Service/XingTest.php

Lines changed: 63 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -3,144 +3,145 @@
33
namespace OAuthTest\Unit\OAuth2\Service;
44

55
use OAuth\OAuth2\Service\Xing;
6+
use PHPUnit\Framework\TestCase;
67

7-
class XingTest extends \PHPUnit_Framework_TestCase
8+
class XingTest extends TestCase
89
{
910
/**
10-
* @covers OAuth\OAuth2\Service\Xing::__construct
11+
* @covers \OAuth\OAuth2\Service\Xing::__construct
1112
*/
12-
public function testConstructCorrectInterfaceWithoutCustomUri()
13+
public function testConstructCorrectInterfaceWithoutCustomUri(): void
1314
{
1415
$service = new Xing(
15-
$this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'),
16-
$this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'),
17-
$this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface')
16+
$this->createMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'),
17+
$this->createMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'),
18+
$this->createMock('\\OAuth\\Common\\Storage\\TokenStorageInterface')
1819
);
1920

20-
$this->assertInstanceOf('\\OAuth\\OAuth2\\Service\\ServiceInterface', $service);
21+
self::assertInstanceOf('\\OAuth\\OAuth2\\Service\\ServiceInterface', $service);
2122
}
2223

2324
/**
24-
* @covers OAuth\OAuth2\Service\Xing::__construct
25+
* @covers \OAuth\OAuth2\Service\Xing::__construct
2526
*/
26-
public function testConstructCorrectInstanceWithoutCustomUri()
27+
public function testConstructCorrectInstanceWithoutCustomUri(): void
2728
{
2829
$service = new Xing(
29-
$this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'),
30-
$this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'),
31-
$this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface')
30+
$this->createMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'),
31+
$this->createMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'),
32+
$this->createMock('\\OAuth\\Common\\Storage\\TokenStorageInterface')
3233
);
3334

34-
$this->assertInstanceOf('\\OAuth\\OAuth2\\Service\\AbstractService', $service);
35+
self::assertInstanceOf('\\OAuth\\OAuth2\\Service\\AbstractService', $service);
3536
}
3637

3738
/**
38-
* @covers OAuth\OAuth2\Service\Xing::__construct
39+
* @covers \OAuth\OAuth2\Service\Xing::__construct
3940
*/
40-
public function testConstructCorrectInstanceWithCustomUri()
41+
public function testConstructCorrectInstanceWithCustomUri(): void
4142
{
4243
$service = new Xing(
43-
$this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'),
44-
$this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'),
45-
$this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface'),
46-
array(),
47-
$this->getMock('\\OAuth\\Common\\Http\\Uri\\UriInterface')
44+
$this->createMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'),
45+
$this->createMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'),
46+
$this->createMock('\\OAuth\\Common\\Storage\\TokenStorageInterface'),
47+
[],
48+
$this->createMock('\\OAuth\\Common\\Http\\Uri\\UriInterface')
4849
);
4950

50-
$this->assertInstanceOf('\\OAuth\\OAuth2\\Service\\AbstractService', $service);
51+
self::assertInstanceOf('\\OAuth\\OAuth2\\Service\\AbstractService', $service);
5152
}
5253

5354
/**
54-
* @covers OAuth\OAuth2\Service\Xing::__construct
55-
* @covers OAuth\OAuth2\Service\Xing::getAuthorizationEndpoint
55+
* @covers \OAuth\OAuth2\Service\Xing::__construct
56+
* @covers \OAuth\OAuth2\Service\Xing::getAuthorizationEndpoint
5657
*/
57-
public function testGetAuthorizationEndpoint()
58+
public function testGetAuthorizationEndpoint(): void
5859
{
5960
$service = new Xing(
60-
$this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'),
61-
$this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'),
62-
$this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface')
61+
$this->createMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'),
62+
$this->createMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'),
63+
$this->createMock('\\OAuth\\Common\\Storage\\TokenStorageInterface')
6364
);
6465

65-
$this->assertSame('https://api.xing.com/auth/oauth2/authorize', $service->getAuthorizationEndpoint()->getAbsoluteUri());
66+
self::assertSame('https://api.xing.com/auth/oauth2/authorize', $service->getAuthorizationEndpoint()->getAbsoluteUri());
6667
}
6768

6869
/**
69-
* @covers OAuth\OAuth2\Service\Xing::__construct
70-
* @covers OAuth\OAuth2\Service\Xing::getAccessTokenEndpoint
70+
* @covers \OAuth\OAuth2\Service\Xing::__construct
71+
* @covers \OAuth\OAuth2\Service\Xing::getAccessTokenEndpoint
7172
*/
72-
public function testGetAccessTokenEndpoint()
73+
public function testGetAccessTokenEndpoint(): void
7374
{
7475
$service = new Xing(
75-
$this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'),
76-
$this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'),
77-
$this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface')
76+
$this->createMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'),
77+
$this->createMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'),
78+
$this->createMock('\\OAuth\\Common\\Storage\\TokenStorageInterface')
7879
);
7980

80-
$this->assertSame('https://api.xing.com/auth/oauth2/token', $service->getAccessTokenEndpoint()->getAbsoluteUri());
81+
self::assertSame('https://api.xing.com/auth/oauth2/token', $service->getAccessTokenEndpoint()->getAbsoluteUri());
8182
}
8283

8384
/**
84-
* @covers OAuth\OAuth2\Service\Xing::__construct
85-
* @covers OAuth\OAuth2\Service\Xing::parseAccessTokenResponse
85+
* @covers \OAuth\OAuth2\Service\Xing::__construct
86+
* @covers \OAuth\OAuth2\Service\Xing::parseAccessTokenResponse
8687
*/
87-
public function testParseAccessTokenResponseThrowsExceptionOnNulledResponse()
88+
public function testParseAccessTokenResponseThrowsExceptionOnNulledResponse(): void
8889
{
89-
$client = $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface');
90-
$client->expects($this->once())->method('retrieveResponse')->will($this->returnValue(null));
90+
$client = $this->createMock('\\OAuth\\Common\\Http\\Client\\ClientInterface');
91+
$client->expects(self::once())->method('retrieveResponse')->willReturn(null);
9192

9293
$service = new Xing(
93-
$this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'),
94+
$this->createMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'),
9495
$client,
95-
$this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface')
96+
$this->createMock('\\OAuth\\Common\\Storage\\TokenStorageInterface')
9697
);
9798

98-
$this->setExpectedException('\\OAuth\\Common\\Http\\Exception\\TokenResponseException');
99+
$this->expectException('\\OAuth\\Common\\Http\\Exception\\TokenResponseException');
99100

100101
$service->requestAccessToken('foo');
101102
}
102103

103104
/**
104-
* @covers OAuth\OAuth2\Service\Xing::__construct
105-
* @covers OAuth\OAuth2\Service\Xing::parseAccessTokenResponse
105+
* @covers \OAuth\OAuth2\Service\Xing::__construct
106+
* @covers \OAuth\OAuth2\Service\Xing::parseAccessTokenResponse
106107
*/
107-
public function testParseAccessTokenResponseThrowsExceptionOnError()
108+
public function testParseAccessTokenResponseThrowsExceptionOnError(): void
108109
{
109-
$error = array(
110+
$error = [
110111
'error' => 'some_error',
111112
'error_description' => 'something went very wrong',
112-
'error_uri' => 'this imaginary link contains more information'
113-
);
113+
'error_uri' => 'this imaginary link contains more information',
114+
];
114115

115-
$client = $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface');
116-
$client->expects($this->once())->method('retrieveResponse')->will($this->returnValue(json_encode($error)));
116+
$client = $this->createMock('\\OAuth\\Common\\Http\\Client\\ClientInterface');
117+
$client->expects(self::once())->method('retrieveResponse')->willReturn(json_encode($error));
117118

118119
$service = new Xing(
119-
$this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'),
120+
$this->createMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'),
120121
$client,
121-
$this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface')
122+
$this->createMock('\\OAuth\\Common\\Storage\\TokenStorageInterface')
122123
);
123124

124-
$this->setExpectedException('\\OAuth\\Common\\Http\\Exception\\TokenResponseException');
125+
$this->expectException('\\OAuth\\Common\\Http\\Exception\\TokenResponseException');
125126

126127
$service->requestAccessToken('foo');
127128
}
128129

129130
/**
130-
* @covers OAuth\OAuth2\Service\Xing::__construct
131-
* @covers OAuth\OAuth2\Service\Xing::parseAccessTokenResponse
131+
* @covers \OAuth\OAuth2\Service\Xing::__construct
132+
* @covers \OAuth\OAuth2\Service\Xing::parseAccessTokenResponse
132133
*/
133-
public function testParseAccessTokenResponseValidWithRefreshToken()
134+
public function testParseAccessTokenResponseValidWithRefreshToken(): void
134135
{
135-
$client = $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface');
136-
$client->expects($this->once())->method('retrieveResponse')->will($this->returnValue('{"access_token":"foo","expires_in":"bar","refresh_token":"baz"}'));
136+
$client = $this->createMock('\\OAuth\\Common\\Http\\Client\\ClientInterface');
137+
$client->expects(self::once())->method('retrieveResponse')->willReturn('{"access_token":"foo","expires_in":"bar","refresh_token":"baz"}');
137138

138139
$service = new Xing(
139-
$this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'),
140+
$this->createMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'),
140141
$client,
141-
$this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface')
142+
$this->createMock('\\OAuth\\Common\\Storage\\TokenStorageInterface')
142143
);
143144

144-
$this->assertInstanceOf('\\OAuth\\OAuth2\\Token\\StdOAuth2Token', $service->requestAccessToken('foo'));
145+
self::assertInstanceOf('\\OAuth\\OAuth2\\Token\\StdOAuth2Token', $service->requestAccessToken('foo'));
145146
}
146147
}

0 commit comments

Comments
 (0)