1 | <?php |
||
8 | use PHPUnit\Framework\TestCase; |
||
9 | |||
10 | class Bitrix24 extends TestCase |
||
11 | { |
||
12 | /** |
||
13 | * @covers \OAuth\OAuth2\Service\Bitrix24::__construct |
||
14 | */ |
||
15 | public function testConstructCorrectInstanceWithCustomUri(): void |
||
27 | |||
28 | /** |
||
29 | * @covers \OAuth\OAuth2\Service\Bitrix24::__construct |
||
30 | * @covers \OAuth\OAuth2\Service\Bitrix24::getAuthorizationEndpoint |
||
31 | */ |
||
32 | public function testGetAuthorizationEndpoint(): void |
||
44 | |||
45 | /** |
||
46 | * @covers \OAuth\OAuth2\Service\Bitrix24::__construct |
||
47 | * @covers \OAuth\OAuth2\Service\Bitrix24::getAccessTokenEndpoint |
||
48 | */ |
||
49 | public function testGetAccessTokenEndpoint(): void |
||
61 | |||
62 | /** |
||
63 | * @covers \OAuth\OAuth2\Service\Bitrix24::__construct |
||
64 | * @covers \OAuth\OAuth2\Service\Bitrix24::getAuthorizationMethod |
||
65 | */ |
||
66 | public function testGetAuthorizationMethod(): void |
||
91 | |||
92 | /** |
||
93 | * @covers \OAuth\OAuth2\Service\Bitrix24::__construct |
||
94 | * @covers \OAuth\OAuth2\Service\Bitrix24::parseAccessTokenResponse |
||
95 | */ |
||
96 | public function testParseAccessTokenResponseThrowsExceptionOnNulledResponse(): void |
||
113 | |||
114 | /** |
||
115 | * @covers \OAuth\OAuth2\Service\Bitrix24::__construct |
||
116 | * @covers \OAuth\OAuth2\Service\Bitrix24::parseAccessTokenResponse |
||
117 | */ |
||
118 | public function testParseAccessTokenResponseThrowsExceptionOnError(): void |
||
135 | |||
136 | /** |
||
137 | * @covers \OAuth\OAuth2\Service\Bitrix24::__construct |
||
138 | * @covers \OAuth\OAuth2\Service\Bitrix24::parseAccessTokenResponse |
||
139 | */ |
||
140 | public function testParseAccessTokenResponseValidWithoutRefreshToken(): void |
||
155 | |||
156 | /** |
||
157 | * @covers \OAuth\OAuth2\Service\Bitrix24::__construct |
||
158 | * @covers \OAuth\OAuth2\Service\Bitrix24::getExtraOAuthHeaders |
||
159 | */ |
||
160 | public function testGetExtraOAuthHeaders(): void |
||
161 | { |
||
162 | $client = $this->createMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'); |
||
163 | $client->expects(self::once())->method('retrieveResponse')->willReturnCallback(function ($uri, $params, $extraHeaders) { |
||
164 | Assert::assertTrue(array_key_exists('Accept', $extraHeaders)); |
||
165 | Assert::assertTrue(in_array('application/json', $extraHeaders, true)); |
||
166 | |||
167 | return '{"access_token":"foo","expires_in":"bar"}'; |
||
168 | }); |
||
169 | |||
170 | $service = new Bitrix24( |
||
171 | $this->createMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'), |
||
172 | $client, |
||
173 | $this->createMock('\\OAuth\\Common\\Storage\\TokenStorageInterface'), |
||
174 | [], |
||
175 | $this->createMock('\\OAuth\\Common\\Http\\Uri\\UriInterface') |
||
176 | ); |
||
177 | |||
178 | self::assertInstanceOf('\\OAuth\\OAuth2\\Token\\StdOAuth2Token', $service->requestAccessToken('foo')); |
||
179 | } |
||
181 |
Let’s assume that you have a directory layout like this:
and let’s assume the following content of
Bar.php
:If both files
OtherDir/Foo.php
andSomeDir/Foo.php
are loaded in the same runtime, you will see a PHP error such as the following:PHP Fatal error: Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php
However, as
OtherDir/Foo.php
does not necessarily have to be loaded and the error is only triggered if it is loaded beforeOtherDir/Bar.php
, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias: