diff --git a/CHANGELOG.md b/CHANGELOG.md index 39555077..a8138f8d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -64,6 +64,7 @@ * fix [add helper metods isError for registerCallResult fortelephony](https://github.com/mesilov/bitrix24-php-sdk/issues/335) * fix [add return type for crm multifields phone, email, im](https://github.com/mesilov/bitrix24-php-sdk/issues/338) * fix errors in `ShowFieldsDescriptionCommand` metadata reader CLI command +* fix errors for `ApplicationProfile` with empty scope ### etc * move CLI entry point to `bin/console` diff --git a/src/Core/Credentials/Scope.php b/src/Core/Credentials/Scope.php index 6e64d1aa..d028e1e7 100644 --- a/src/Core/Credentials/Scope.php +++ b/src/Core/Credentials/Scope.php @@ -6,11 +6,6 @@ use Bitrix24\SDK\Core\Exceptions\UnknownScopeCodeException; -/** - * Class Scope - * - * @package Bitrix24\SDK\Core\Credentials - */ class Scope { /** @@ -84,9 +79,14 @@ class Scope public function __construct(array $scope = []) { $scope = array_unique(array_map('strtolower', $scope)); - foreach ($scope as $item) { - if (!in_array($item, $this->availableScope, true)) { - throw new UnknownScopeCodeException(sprintf('unknown application scope code - %s', $item)); + + if (count($scope) === 1 && $scope[0] === '') { + $scope = []; + } else { + foreach ($scope as $item) { + if (!in_array($item, $this->availableScope, true)) { + throw new UnknownScopeCodeException(sprintf('unknown application scope code - %s', $item)); + } } } diff --git a/tests/Unit/Core/Credentials/ApplicationProfileTest.php b/tests/Unit/Core/Credentials/ApplicationProfileTest.php index a66a38ce..17956aac 100644 --- a/tests/Unit/Core/Credentials/ApplicationProfileTest.php +++ b/tests/Unit/Core/Credentials/ApplicationProfileTest.php @@ -13,11 +13,11 @@ class ApplicationProfileTest extends TestCase { /** * - * @param array $arr + * @param array $arr * @param string|null $expectedException * * @return void - * @throws \Bitrix24\SDK\Core\Exceptions\InvalidArgumentException + * @throws InvalidArgumentException * @dataProvider arrayDataProvider */ public function testFromArray(array $arr, ?string $expectedException): void @@ -35,35 +35,43 @@ public function arrayDataProvider(): Generator { yield 'valid' => [ [ - 'BITRIX24_PHP_SDK_APPLICATION_CLIENT_ID' => '1', + 'BITRIX24_PHP_SDK_APPLICATION_CLIENT_ID' => '1', 'BITRIX24_PHP_SDK_APPLICATION_CLIENT_SECRET' => '2', - 'BITRIX24_PHP_SDK_APPLICATION_SCOPE' => 'user', + 'BITRIX24_PHP_SDK_APPLICATION_SCOPE' => 'user', ], null, ]; yield 'without client id' => [ [ - '' => '1', + '' => '1', 'BITRIX24_PHP_SDK_APPLICATION_CLIENT_SECRET' => '2', - 'BITRIX24_PHP_SDK_APPLICATION_SCOPE' => 'user', + 'BITRIX24_PHP_SDK_APPLICATION_SCOPE' => 'user', ], InvalidArgumentException::class, ]; yield 'without client secret' => [ [ 'BITRIX24_PHP_SDK_APPLICATION_CLIENT_ID' => '1', - '' => '2', - 'BITRIX24_PHP_SDK_APPLICATION_SCOPE' => 'user', + '' => '2', + 'BITRIX24_PHP_SDK_APPLICATION_SCOPE' => 'user', ], InvalidArgumentException::class, ]; yield 'without client application scope' => [ [ - 'BITRIX24_PHP_SDK_APPLICATION_CLIENT_ID' => '1', + 'BITRIX24_PHP_SDK_APPLICATION_CLIENT_ID' => '1', 'BITRIX24_PHP_SDK_APPLICATION_CLIENT_SECRET' => '2', - '' => 'user', + '' => 'user', ], InvalidArgumentException::class, ]; + yield 'with empty scope' => [ + [ + 'BITRIX24_PHP_SDK_APPLICATION_CLIENT_ID' => '1', + 'BITRIX24_PHP_SDK_APPLICATION_CLIENT_SECRET' => '2', + 'BITRIX24_PHP_SDK_APPLICATION_SCOPE' => '', + ], + null + ]; } } diff --git a/tests/Unit/Core/Credentials/ScopeTest.php b/tests/Unit/Core/Credentials/ScopeTest.php index d7d37b32..e974fd36 100644 --- a/tests/Unit/Core/Credentials/ScopeTest.php +++ b/tests/Unit/Core/Credentials/ScopeTest.php @@ -73,6 +73,15 @@ public function testUnknownScope(): void $scope = new Scope(['fooo']); } + /** + * @throws UnknownScopeCodeException + */ + public function testEmptyScope(): void + { + $scope = new Scope(['']); + $this->assertEquals([], $scope->getScopeCodes()); + } + /** * @throws UnknownScopeCodeException */