|
3 | 3 | namespace OAuthTest\Unit\OAuth2\Service; |
4 | 4 |
|
5 | 5 | use OAuth\OAuth2\Service\Xing; |
| 6 | +use PHPUnit\Framework\TestCase; |
6 | 7 |
|
7 | | -class XingTest extends \PHPUnit_Framework_TestCase |
| 8 | +class XingTest extends TestCase |
8 | 9 | { |
9 | 10 | /** |
10 | | - * @covers OAuth\OAuth2\Service\Xing::__construct |
| 11 | + * @covers \OAuth\OAuth2\Service\Xing::__construct |
11 | 12 | */ |
12 | | - public function testConstructCorrectInterfaceWithoutCustomUri() |
| 13 | + public function testConstructCorrectInterfaceWithoutCustomUri(): void |
13 | 14 | { |
14 | 15 | $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') |
18 | 19 | ); |
19 | 20 |
|
20 | | - $this->assertInstanceOf('\\OAuth\\OAuth2\\Service\\ServiceInterface', $service); |
| 21 | + self::assertInstanceOf('\\OAuth\\OAuth2\\Service\\ServiceInterface', $service); |
21 | 22 | } |
22 | 23 |
|
23 | 24 | /** |
24 | | - * @covers OAuth\OAuth2\Service\Xing::__construct |
| 25 | + * @covers \OAuth\OAuth2\Service\Xing::__construct |
25 | 26 | */ |
26 | | - public function testConstructCorrectInstanceWithoutCustomUri() |
| 27 | + public function testConstructCorrectInstanceWithoutCustomUri(): void |
27 | 28 | { |
28 | 29 | $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') |
32 | 33 | ); |
33 | 34 |
|
34 | | - $this->assertInstanceOf('\\OAuth\\OAuth2\\Service\\AbstractService', $service); |
| 35 | + self::assertInstanceOf('\\OAuth\\OAuth2\\Service\\AbstractService', $service); |
35 | 36 | } |
36 | 37 |
|
37 | 38 | /** |
38 | | - * @covers OAuth\OAuth2\Service\Xing::__construct |
| 39 | + * @covers \OAuth\OAuth2\Service\Xing::__construct |
39 | 40 | */ |
40 | | - public function testConstructCorrectInstanceWithCustomUri() |
| 41 | + public function testConstructCorrectInstanceWithCustomUri(): void |
41 | 42 | { |
42 | 43 | $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') |
48 | 49 | ); |
49 | 50 |
|
50 | | - $this->assertInstanceOf('\\OAuth\\OAuth2\\Service\\AbstractService', $service); |
| 51 | + self::assertInstanceOf('\\OAuth\\OAuth2\\Service\\AbstractService', $service); |
51 | 52 | } |
52 | 53 |
|
53 | 54 | /** |
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 |
56 | 57 | */ |
57 | | - public function testGetAuthorizationEndpoint() |
| 58 | + public function testGetAuthorizationEndpoint(): void |
58 | 59 | { |
59 | 60 | $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') |
63 | 64 | ); |
64 | 65 |
|
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()); |
66 | 67 | } |
67 | 68 |
|
68 | 69 | /** |
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 |
71 | 72 | */ |
72 | | - public function testGetAccessTokenEndpoint() |
| 73 | + public function testGetAccessTokenEndpoint(): void |
73 | 74 | { |
74 | 75 | $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') |
78 | 79 | ); |
79 | 80 |
|
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()); |
81 | 82 | } |
82 | 83 |
|
83 | 84 | /** |
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 |
86 | 87 | */ |
87 | | - public function testParseAccessTokenResponseThrowsExceptionOnNulledResponse() |
| 88 | + public function testParseAccessTokenResponseThrowsExceptionOnNulledResponse(): void |
88 | 89 | { |
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); |
91 | 92 |
|
92 | 93 | $service = new Xing( |
93 | | - $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'), |
| 94 | + $this->createMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'), |
94 | 95 | $client, |
95 | | - $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface') |
| 96 | + $this->createMock('\\OAuth\\Common\\Storage\\TokenStorageInterface') |
96 | 97 | ); |
97 | 98 |
|
98 | | - $this->setExpectedException('\\OAuth\\Common\\Http\\Exception\\TokenResponseException'); |
| 99 | + $this->expectException('\\OAuth\\Common\\Http\\Exception\\TokenResponseException'); |
99 | 100 |
|
100 | 101 | $service->requestAccessToken('foo'); |
101 | 102 | } |
102 | 103 |
|
103 | 104 | /** |
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 |
106 | 107 | */ |
107 | | - public function testParseAccessTokenResponseThrowsExceptionOnError() |
| 108 | + public function testParseAccessTokenResponseThrowsExceptionOnError(): void |
108 | 109 | { |
109 | | - $error = array( |
| 110 | + $error = [ |
110 | 111 | 'error' => 'some_error', |
111 | 112 | '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 | + ]; |
114 | 115 |
|
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)); |
117 | 118 |
|
118 | 119 | $service = new Xing( |
119 | | - $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'), |
| 120 | + $this->createMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'), |
120 | 121 | $client, |
121 | | - $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface') |
| 122 | + $this->createMock('\\OAuth\\Common\\Storage\\TokenStorageInterface') |
122 | 123 | ); |
123 | 124 |
|
124 | | - $this->setExpectedException('\\OAuth\\Common\\Http\\Exception\\TokenResponseException'); |
| 125 | + $this->expectException('\\OAuth\\Common\\Http\\Exception\\TokenResponseException'); |
125 | 126 |
|
126 | 127 | $service->requestAccessToken('foo'); |
127 | 128 | } |
128 | 129 |
|
129 | 130 | /** |
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 |
132 | 133 | */ |
133 | | - public function testParseAccessTokenResponseValidWithRefreshToken() |
| 134 | + public function testParseAccessTokenResponseValidWithRefreshToken(): void |
134 | 135 | { |
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"}'); |
137 | 138 |
|
138 | 139 | $service = new Xing( |
139 | | - $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'), |
| 140 | + $this->createMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'), |
140 | 141 | $client, |
141 | | - $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface') |
| 142 | + $this->createMock('\\OAuth\\Common\\Storage\\TokenStorageInterface') |
142 | 143 | ); |
143 | 144 |
|
144 | | - $this->assertInstanceOf('\\OAuth\\OAuth2\\Token\\StdOAuth2Token', $service->requestAccessToken('foo')); |
| 145 | + self::assertInstanceOf('\\OAuth\\OAuth2\\Token\\StdOAuth2Token', $service->requestAccessToken('foo')); |
145 | 146 | } |
146 | 147 | } |
0 commit comments