diff --git a/Makefile b/Makefile index d61aebf..5927f0a 100644 --- a/Makefile +++ b/Makefile @@ -16,6 +16,8 @@ include $(ENV) -include $(ENV_LOCAL) +start-rector: vendor + vendor/bin/rector process tests --config=rector.php coding-standards: vendor vendor/bin/php-cs-fixer fix --config=.php-cs-fixer.dist.php --diff --verbose @@ -46,6 +48,10 @@ init: @echo "run application…" docker-compose up -d + +clear: + docker-compose run --rm php-cli composer clear-cache + up: @echo "run application…" docker-compose up --build -d @@ -110,7 +116,7 @@ test-run-functional: debug-print-env # Запустить один функциональный тест с дебагером run-one-functional-test: debug-print-env - docker-compose run --rm php-cli php -dxdebug.start_with_request=yes vendor/bin/phpunit --filter 'testCreateExistingAccount' tests/Functional/Bitrix24Accounts/UseCase/InstallStart/HandlerTest.php + docker-compose run --rm php-cli php -dxdebug.start_with_request=yes vendor/bin/phpunit --filter 'testChangeDomainUrlWithHappyPath' tests/Functional/Bitrix24Accounts/UseCase/ChangeDomainUrl/HandlerTest.php schema-drop: docker-compose run --rm php-cli php bin/doctrine orm:schema-tool:drop --force diff --git a/src/Bitrix24Accounts/Entity/Bitrix24Account.php b/src/Bitrix24Accounts/Entity/Bitrix24Account.php index a269988..616f75d 100644 --- a/src/Bitrix24Accounts/Entity/Bitrix24Account.php +++ b/src/Bitrix24Accounts/Entity/Bitrix24Account.php @@ -233,7 +233,7 @@ public function getUpdatedAt(): CarbonImmutable * @throws InvalidArgumentException */ #[\Override] - public function updateApplicationVersion(int $version, ?Scope $newScope): void + public function updateApplicationVersion(AuthToken $authToken, int $b24UserId, int $version, ?Scope $newScope): void { if (Bitrix24AccountStatus::active !== $this->status) { throw new InvalidArgumentException( diff --git a/src/Bitrix24Accounts/UseCase/ChangeDomainUrl/Command.php b/src/Bitrix24Accounts/UseCase/ChangeDomainUrl/Command.php index 0304d13..e93ce70 100644 --- a/src/Bitrix24Accounts/UseCase/ChangeDomainUrl/Command.php +++ b/src/Bitrix24Accounts/UseCase/ChangeDomainUrl/Command.php @@ -4,37 +4,19 @@ namespace Bitrix24\Lib\Bitrix24Accounts\UseCase\ChangeDomainUrl; +use Bitrix24\Lib\Bitrix24Accounts\ValueObjects\Domain; + readonly class Command { - public function __construct( - /** - * @var non-empty-string $oldDomain - */ - public string $oldDomain, - /** - * @var non-empty-string $newDomain - */ - public string $newDomain - ) { - $this->validateDomain($oldDomain, 'oldDomainUrlHost'); - $this->validateDomain($newDomain, 'newDomainUrlHost'); - } + public string $oldDomain; - private function validateDomain(string $domain, string $parameterName): void - { - // Регулярное выражение для проверки допустимых символов (латиница и кириллица) - $patternValidChars = '/^((?!-)[A-Za-zА-Яа-яЁё0-9-]{1,63}(?oldDomain = $oldDomain->getValue(); + $this->newDomain = $newDomain->getValue(); } } diff --git a/src/Bitrix24Accounts/UseCase/InstallFinish/Command.php b/src/Bitrix24Accounts/UseCase/InstallFinish/Command.php index 339d739..2ab9f21 100644 --- a/src/Bitrix24Accounts/UseCase/InstallFinish/Command.php +++ b/src/Bitrix24Accounts/UseCase/InstallFinish/Command.php @@ -4,20 +4,25 @@ namespace Bitrix24\Lib\Bitrix24Accounts\UseCase\InstallFinish; +use Bitrix24\Lib\Bitrix24Accounts\ValueObjects\Domain; + readonly class Command { + public string $domain; + public function __construct( public string $applicationToken, public string $memberId, - public string $domainUrl, + Domain $domain, public int $bitrix24UserId, ) { $this->validate(); + $this->domain = $domain->getValue(); } private function validate(): void { - if ('' === $this->applicationToken || '0' === $this->applicationToken) { + if ('' === $this->applicationToken) { throw new \InvalidArgumentException('Application token cannot be empty.'); } @@ -25,28 +30,8 @@ private function validate(): void throw new \InvalidArgumentException('Member ID cannot be empty.'); } - $this->validateDomain($this->domainUrl); - if ($this->bitrix24UserId <= 0) { throw new \InvalidArgumentException('Bitrix24 User ID must be a positive integer.'); } } - - private function validateDomain(string $domain): void - { - // Регулярное выражение для проверки допустимых символов (латиница и кириллица) - $patternValidChars = '/^((?!-)[A-Za-zА-Яа-яЁё0-9-]{1,63}(?logger->info('Bitrix24Accounts.InstallFinish.start', [ - 'b24_domain_url' => $command->domainUrl, + 'b24_domain_url' => $command->domain, 'b24_member_id' => $command->memberId, 'b24_application_id' => $command->applicationToken, 'b24_user_id' => $command->bitrix24UserId, ]); /** @var AggregateRootEventsEmitterInterface|Bitrix24AccountInterface $bitrix24Account */ - $bitrix24Account = $this->getSingleAccountByMemberId($command->domainUrl, $command->memberId, $command->bitrix24UserId); + $bitrix24Account = $this->getSingleAccountByMemberId($command->domain, $command->memberId, $command->bitrix24UserId); $bitrix24Account->applicationInstalled($command->applicationToken); @@ -47,7 +47,7 @@ public function handle(Command $command): void $this->logger->info( 'Bitrix24Accounts.InstallFinish.Finish', [ - 'b24_domain_url' => $command->domainUrl, + 'b24_domain_url' => $command->domain, 'b24_member_id' => $command->memberId, 'b24_application_id' => $command->applicationToken, 'b24_user_id' => $command->bitrix24UserId, diff --git a/src/Bitrix24Accounts/UseCase/InstallStart/Command.php b/src/Bitrix24Accounts/UseCase/InstallStart/Command.php index e9e8636..3b95869 100644 --- a/src/Bitrix24Accounts/UseCase/InstallStart/Command.php +++ b/src/Bitrix24Accounts/UseCase/InstallStart/Command.php @@ -4,61 +4,41 @@ namespace Bitrix24\Lib\Bitrix24Accounts\UseCase\InstallStart; +use Bitrix24\Lib\Bitrix24Accounts\ValueObjects\Domain; use Bitrix24\SDK\Core\Credentials\AuthToken; use Bitrix24\SDK\Core\Credentials\Scope; use Symfony\Component\Uid\Uuid; readonly class Command { + public string $domain; + public function __construct( public Uuid $uuid, public int $bitrix24UserId, public bool $isBitrix24UserAdmin, public string $memberId, - public string $domainUrl, + Domain $domain, public AuthToken $authToken, public int $applicationVersion, public Scope $applicationScope ) { $this->validate(); + $this->domain = $domain->getValue(); } private function validate(): void { - if (empty($this->uuid)) { - throw new \InvalidArgumentException('Empty UUID provided.'); - } - if ($this->bitrix24UserId <= 0) { throw new \InvalidArgumentException('Bitrix24 User ID must be a positive integer.'); } - if (!is_string($this->memberId) || ('' === $this->memberId || '0' === $this->memberId)) { + if ('' === $this->memberId) { throw new \InvalidArgumentException('Member ID must be a non-empty string.'); } - $this->validateDomain($this->domainUrl); - if ($this->applicationVersion <= 0) { throw new \InvalidArgumentException('Application version must be a positive integer.'); } } - - private function validateDomain(string $domain): void - { - // Регулярное выражение для проверки допустимых символов (латиница и кириллица) - $patternValidChars = '/^((?!-)[A-Za-zА-Яа-яЁё0-9-]{1,63}(?logger->info('Bitrix24Accounts.InstallStart.start', [ 'id' => $command->uuid->toRfc4122(), - 'domain_url' => $command->domainUrl, + 'domain' => $command->domain, 'member_id' => $command->memberId, ]); @@ -33,7 +33,7 @@ public function handle(Command $command): void $command->bitrix24UserId, $command->isBitrix24UserAdmin, $command->memberId, - $command->domainUrl, + $command->domain, Bitrix24AccountStatus::new, $command->authToken, new CarbonImmutable(), @@ -53,7 +53,7 @@ public function handle(Command $command): void 'Bitrix24Accounts.InstallStart.Finish', [ 'id' => $command->uuid->toRfc4122(), - 'domain_url' => $command->domainUrl, + 'domain_url' => $command->domain, 'member_id' => $command->memberId, ] ); @@ -62,7 +62,7 @@ public function handle(Command $command): void 'Bitrix24Accounts.InstallStart.AlreadyExists', [ 'id' => $command->uuid->toRfc4122(), - 'domain_url' => $command->domainUrl, + 'domain' => $command->domain, 'member_id' => $command->memberId, ] ); diff --git a/src/Bitrix24Accounts/UseCase/Uninstall/Command.php b/src/Bitrix24Accounts/UseCase/Uninstall/Command.php index a4a52e1..5a92c6a 100644 --- a/src/Bitrix24Accounts/UseCase/Uninstall/Command.php +++ b/src/Bitrix24Accounts/UseCase/Uninstall/Command.php @@ -17,8 +17,8 @@ public function __construct( private function validate(): void { - if ('' === $this->applicationToken || '0' === $this->applicationToken) { - throw new \InvalidArgumentException('Empty application token application token.'); + if ('' === $this->applicationToken) { + throw new \InvalidArgumentException('Application token must be a non-empty string.'); } } } diff --git a/src/Bitrix24Accounts/ValueObjects/Domain.php b/src/Bitrix24Accounts/ValueObjects/Domain.php new file mode 100644 index 0000000..f958a5a --- /dev/null +++ b/src/Bitrix24Accounts/ValueObjects/Domain.php @@ -0,0 +1,39 @@ +validate($domain); + $this->value = $domain; + } + + public function getValue(): string + { + return $this->value; + } + + private function validate(string $domain): void + { + // Регулярное выражение для проверки допустимых символов (латиница и кириллица) + $patternValidChars = '/^((?!-)[A-Za-zА-Яа-яЁё0-9-]{1,63}(?id, diff --git a/tests/Functional/Bitrix24Accounts/UseCase/ChangeDomainUrl/HandlerTest.php b/tests/Functional/Bitrix24Accounts/UseCase/ChangeDomainUrl/HandlerTest.php index 36a21f2..01e2d5a 100644 --- a/tests/Functional/Bitrix24Accounts/UseCase/ChangeDomainUrl/HandlerTest.php +++ b/tests/Functional/Bitrix24Accounts/UseCase/ChangeDomainUrl/HandlerTest.php @@ -29,6 +29,7 @@ use Symfony\Component\EventDispatcher\EventDispatcher; use Symfony\Component\Stopwatch\Stopwatch; use Symfony\Component\Uid\Uuid; +use Bitrix24\Lib\Bitrix24Accounts\ValueObjects\Domain; /** * @internal @@ -74,8 +75,8 @@ public function testChangeDomainUrlForAccount(): void $this->handler->handle( new Bitrix24Accounts\UseCase\ChangeDomainUrl\Command( - $oldDomainUrl, - $newDomainUrl + new Domain($oldDomainUrl), + new Domain($newDomainUrl) ) ); @@ -126,8 +127,8 @@ public function testChangeDomainUrlForManyAccounts(): void $this->handler->handle( new Bitrix24Accounts\UseCase\ChangeDomainUrl\Command( - $oldDomainUrl, - $newDomainUrl + new Domain($oldDomainUrl), + new Domain($newDomainUrl) ) ); diff --git a/tests/Functional/Bitrix24Accounts/UseCase/InstallFinish/HandlerTest.php b/tests/Functional/Bitrix24Accounts/UseCase/InstallFinish/HandlerTest.php index 04a8e05..f0d1ac0 100644 --- a/tests/Functional/Bitrix24Accounts/UseCase/InstallFinish/HandlerTest.php +++ b/tests/Functional/Bitrix24Accounts/UseCase/InstallFinish/HandlerTest.php @@ -30,6 +30,7 @@ use Symfony\Component\EventDispatcher\EventDispatcher; use Symfony\Component\Stopwatch\Stopwatch; use Symfony\Component\Uid\Uuid; +use Bitrix24\Lib\Bitrix24Accounts\ValueObjects\Domain; /** * @internal @@ -78,7 +79,7 @@ public function testFinishInstallationApplication(): void new Bitrix24Accounts\UseCase\InstallFinish\Command( $applicationToken, $bitrix24Account->getMemberId(), - $bitrix24Account->getDomainUrl(), + new Domain($bitrix24Account->getDomainUrl()), $bitrix24Account->getBitrix24UserId() ) ); diff --git a/tests/Functional/Bitrix24Accounts/UseCase/InstallStart/HandlerTest.php b/tests/Functional/Bitrix24Accounts/UseCase/InstallStart/HandlerTest.php index aecab34..8fe33ba 100644 --- a/tests/Functional/Bitrix24Accounts/UseCase/InstallStart/HandlerTest.php +++ b/tests/Functional/Bitrix24Accounts/UseCase/InstallStart/HandlerTest.php @@ -33,6 +33,7 @@ use Symfony\Component\EventDispatcher\Debug\TraceableEventDispatcher; use Symfony\Component\EventDispatcher\EventDispatcher; use Symfony\Component\Stopwatch\Stopwatch; +use Bitrix24\Lib\Bitrix24Accounts\ValueObjects\Domain; /** * @internal @@ -65,7 +66,6 @@ protected function setUp(): void /** * @throws InvalidArgumentException * @throws Bitrix24AccountNotFoundException - * @throws RandomException * @throws UnknownScopeCodeException */ #[Test] @@ -81,7 +81,7 @@ public function testInstallNewApplication(): void $bitrix24AccountBuilder->getBitrix24UserId(), $bitrix24AccountBuilder->isBitrix24UserAdmin(), $bitrix24AccountBuilder->getMemberId(), - $bitrix24AccountBuilder->getDomainUrl(), + new Domain($bitrix24AccountBuilder->getDomainUrl()), $bitrix24AccountBuilder->getAuthToken(), $bitrix24AccountBuilder->getApplicationVersion(), $bitrix24AccountBuilder->getApplicationScope() @@ -181,7 +181,7 @@ public function testInstallExistingAccount(): void $bitrix24Account->getBitrix24UserId(), $bitrix24Account->isBitrix24UserAdmin(), $bitrix24Account->getMemberId(), - $bitrix24Account->getDomainUrl(), + new Domain($bitrix24Account->getDomainUrl()), $bitrix24Account->getAuthToken(), $bitrix24Account->getApplicationVersion(), $bitrix24Account->getApplicationScope() @@ -199,7 +199,7 @@ public function testInstallExistingAccount(): void $bitrix24Account->getBitrix24UserId(), $bitrix24Account->isBitrix24UserAdmin(), $bitrix24Account->getMemberId(), - $bitrix24Account->getDomainUrl(), + new Domain($bitrix24Account->getDomainUrl()), $bitrix24Account->getAuthToken(), $bitrix24Account->getApplicationVersion(), $bitrix24Account->getApplicationScope() diff --git a/tests/Unit/Bitrix24Accounts/DomainCheckerTest.php b/tests/Unit/Bitrix24Accounts/DomainCheckerTest.php deleted file mode 100644 index 123e0f4..0000000 --- a/tests/Unit/Bitrix24Accounts/DomainCheckerTest.php +++ /dev/null @@ -1,83 +0,0 @@ -assertEquals(6, $exceptionCount, 'Expected 6 invalid exception and received ' . $exceptionCount); - } else { - // Если ожидается отсутствие исключений, проверяем что их не было - $this->assertEquals(0, $exceptionCount, sprintf('No exceptions were expected but %d were thrown.', $exceptionCount)); - } - - } - - public static function dataForCommand(): \Generator - { - - // Примеры недопустимых доменов - $arrInvalidDomains = [ - ['oldDomain' => 'invalid_domain.com', 'newDomain' => 'valid.com'], // Неправильный формат (подчеркивание) - ['oldDomain' => '-invalid.com', 'newDomain' => 'valid.com'], // Домен не может начинаться с дефиса - ['oldDomain' => 'invalid-.com', 'newDomain' => 'valid.com'], // Домен не может заканчиваться на дефис - ['oldDomain' => '123.456.789.0', 'newDomain' => 'valid.com'], // Неправильный формат (IP-адрес) - ['oldDomain' => 'example..com', 'newDomain' => 'valid.com'], // Два подряд идущих точки - ['oldDomain' => 'example.c', 'newDomain' => 'valid.com'] // Слишком короткая доменная зона - ]; - - // Примеры допустимых доменов - $arrValidDomains = [ - ['oldDomain' => 'example.com', 'newDomain' => 'example.org'], - ['oldDomain' => 'пример.рф', 'newDomain' => 'пример.рус'], - ['oldDomain' => 'test-site.org', 'newDomain' => 'test-site.ru'], - ['oldDomain' => 'valid-domain.co.uk', 'newDomain' => 'valid-domain.net'], - ['oldDomain' => 'subdomain.example.com', 'newDomain' => 'subdomain2.example.com'], - ['oldDomain' => 'тест.рус', 'newDomain' => 'тест2.рус'], // Пример с кириллицей - ]; - - yield 'invalidDomain' => [ - [$arrInvalidDomains], // Оборачиваем в массив для передачи в testValidCommand - \InvalidArgumentException::class - ]; - - yield 'validDomain' => [ - [$arrValidDomains], // Оборачиваем в массив для передачи в testValidCommand - null // Здесь исключение не ожидается - ]; - } -} diff --git a/tests/Unit/Bitrix24Accounts/UseCase/ChangeDomainUrl/CommandTest.php b/tests/Unit/Bitrix24Accounts/UseCase/ChangeDomainUrl/CommandTest.php index bfd3e1d..23b1435 100644 --- a/tests/Unit/Bitrix24Accounts/UseCase/ChangeDomainUrl/CommandTest.php +++ b/tests/Unit/Bitrix24Accounts/UseCase/ChangeDomainUrl/CommandTest.php @@ -5,6 +5,7 @@ namespace Bitrix24\Lib\Tests\Unit\Bitrix24Accounts\UseCase\ChangeDomainUrl; use Bitrix24\Lib\Bitrix24Accounts\UseCase\ChangeDomainUrl\Command; +use Bitrix24\Lib\Bitrix24Accounts\ValueObjects\Domain; use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\Attributes\Test; @@ -18,44 +19,98 @@ class CommandTest extends TestCase { #[Test] - #[DataProvider('dataForCommand')] - public function testValidCommand( - string $oldDomain, - string $newDomain, + #[DataProvider('dataForValidateInvalidDomain')] + public function testValidateDomain( + array $arrDomains, ?string $expectedException - ): void - { + ): void { + + $exceptionCount = 0; + foreach ($arrDomains as $arrDomain) { + try { + $oldDomain = new Domain($arrDomain['oldDomain']); + $newDomain = new Domain($arrDomain['newDomain']); + new Command($oldDomain, $newDomain); + } catch (\InvalidArgumentException) { + // Увеличиваем счетчик при каждом выбросе исключения + $exceptionCount++; + } + } + // Проверяем, сколько исключений было выброшено if ($expectedException !== null) { - $this->expectException(\InvalidArgumentException::class); + $this->assertEquals(6, $exceptionCount, 'Expected 6 invalid exception and received ' . $exceptionCount); + } else { + // Если ожидается отсутствие исключений, проверяем что их не было + $this->assertEquals(0, $exceptionCount, sprintf('No exceptions were expected but %d were thrown.', $exceptionCount)); } - $command = new Command($oldDomain, $newDomain); + } - if ($expectedException == null) { - $this->assertInstanceOf(Command::class, $command); + #[Test] + #[DataProvider('dataForValidateValidDomain')] + public function testValidateInvalidDomain( + array $arrDomains, + ?string $expectedException + ): void { + + $exceptionCount = 0; + foreach ($arrDomains as $arrDomain) { + try { + $oldDomain = new Domain($arrDomain['oldDomain']); + $newDomain = new Domain($arrDomain['newDomain']); + new Command($oldDomain, $newDomain); + } catch (\InvalidArgumentException) { + // Увеличиваем счетчик при каждом выбросе исключения + $exceptionCount++; + } + } + + // Проверяем, сколько исключений было выброшено + if ($expectedException !== null) { + $this->assertEquals(6, $exceptionCount, 'Expected 6 invalid exception and received ' . $exceptionCount); + } else { + // Если ожидается отсутствие исключений, проверяем что их не было + $this->assertEquals(0, $exceptionCount, sprintf('No exceptions were expected but %d were thrown.', $exceptionCount)); } } - public static function dataForCommand(): \Generator + public static function dataForValidateValidDomain(): \Generator { - $invalidOldDomain = 'invalid_domain.com'; - $invalidNewDomain = 'valid.com'; - - $validOldDomain = 'example.com'; - $validNewDomain = 'example.org'; - yield 'invalidDomain' => [ - $invalidOldDomain, - $invalidNewDomain, - \InvalidArgumentException::class + // Примеры допустимых доменов + $arrValidDomains = [ + ['oldDomain' => 'example.com', 'newDomain' => 'example.org'], + ['oldDomain' => 'пример.рф', 'newDomain' => 'пример.рус'], + ['oldDomain' => 'test-site.org', 'newDomain' => 'test-site.ru'], + ['oldDomain' => 'valid-domain.co.uk', 'newDomain' => 'valid-domain.net'], + ['oldDomain' => 'subdomain.example.com', 'newDomain' => 'subdomain2.example.com'], + ['oldDomain' => 'тест.рус', 'newDomain' => 'тест2.рус'], // Пример с кириллицей ]; yield 'validDomain' => [ - $validOldDomain, - $validNewDomain, + $arrValidDomains, // Оборачиваем в массив для передачи в testValidCommand null // Здесь исключение не ожидается ]; } + + public static function dataForValidateInvalidDomain(): \Generator + { + + // Примеры недопустимых доменов + $arrInvalidDomains = [ + ['oldDomain' => 'invalid_domain.com', 'newDomain' => 'valid.com'], // Неправильный формат (подчеркивание) + ['oldDomain' => '-invalid.com', 'newDomain' => 'valid.com'], // Домен не может начинаться с дефиса + ['oldDomain' => 'invalid-.com', 'newDomain' => 'valid.com'], // Домен не может заканчиваться на дефис + ['oldDomain' => '123.456.789.0', 'newDomain' => 'valid.com'], // Неправильный формат (IP-адрес) + ['oldDomain' => 'example..com', 'newDomain' => 'valid.com'], // Два подряд идущих точки + ['oldDomain' => 'example.c', 'newDomain' => 'valid.com'] // Слишком короткая доменная зона + ]; + + yield 'invalidDomain' => [ + $arrInvalidDomains, // Оборачиваем в массив для передачи в testValidCommand + \InvalidArgumentException::class + ]; + } } diff --git a/tests/Unit/Bitrix24Accounts/UseCase/InstallFinish/CommandTest.php b/tests/Unit/Bitrix24Accounts/UseCase/InstallFinish/CommandTest.php index c11824b..71d250f 100644 --- a/tests/Unit/Bitrix24Accounts/UseCase/InstallFinish/CommandTest.php +++ b/tests/Unit/Bitrix24Accounts/UseCase/InstallFinish/CommandTest.php @@ -12,6 +12,8 @@ use PHPUnit\Framework\Attributes\Test; use PHPUnit\Framework\TestCase; use Symfony\Component\Uid\Uuid; +use Bitrix24\Lib\Bitrix24Accounts\ValueObjects\Domain; + /** * @internal @@ -22,13 +24,14 @@ class CommandTest extends TestCase #[Test] #[DataProvider('dataForCommand')] public function testValidCommand( - string $applicationToken, - string $memberId, - string $domainUrl, - int $bitrix24UserId, + string $applicationToken, + string $memberId, + string $domainUrl, + int $bitrix24UserId, ?string $expectedException, ?string $expectedExceptionMessage, - ): void { + ): void + { if (null !== $expectedException) { $this->expectException($expectedException); } @@ -37,12 +40,15 @@ public function testValidCommand( $this->expectExceptionMessage($expectedExceptionMessage); } - new Command( + $domain = new Domain($domainUrl); + + new Command( $applicationToken, $memberId, - $domainUrl, + $domain, $bitrix24UserId ); + } public static function dataForCommand(): \Generator @@ -76,7 +82,7 @@ public static function dataForCommand(): \Generator '', $bitrix24Account->getBitrix24UserId(), \InvalidArgumentException::class, - 'Domain URL is not valid.' + sprintf('Invalid domain: %s', '') ]; } } diff --git a/tests/Unit/Bitrix24Accounts/UseCase/InstallStart/CommandTest.php b/tests/Unit/Bitrix24Accounts/UseCase/InstallStart/CommandTest.php index c9f1a21..3369550 100644 --- a/tests/Unit/Bitrix24Accounts/UseCase/InstallStart/CommandTest.php +++ b/tests/Unit/Bitrix24Accounts/UseCase/InstallStart/CommandTest.php @@ -14,6 +14,8 @@ use PHPUnit\Framework\Attributes\Test; use PHPUnit\Framework\TestCase; use Symfony\Component\Uid\Uuid; +use Bitrix24\Lib\Bitrix24Accounts\ValueObjects\Domain; + /** * @internal @@ -24,17 +26,18 @@ class CommandTest extends TestCase #[Test] #[DataProvider('dataForCommand')] public function testValidCommand( - Uuid $uuid, - int $bitrix24UserId, - bool $isBitrix24UserAdmin, - string $memberId, - string $domainUrl, + Uuid $uuid, + int $bitrix24UserId, + bool $isBitrix24UserAdmin, + string $memberId, + string $domainUrl, AuthToken $authToken, - int $applicationVersion, - Scope $applicationScope, - ?string $expectedException, - ?string $expectedExceptionMessage, - ): void { + int $applicationVersion, + Scope $applicationScope, + ?string $expectedException, + ?string $expectedExceptionMessage, + ): void + { if (null !== $expectedException) { $this->expectException($expectedException); } @@ -43,16 +46,19 @@ public function testValidCommand( $this->expectExceptionMessage($expectedExceptionMessage); } + $domain = new Domain($domainUrl); + new Command( $uuid, $bitrix24UserId, $isBitrix24UserAdmin, $memberId, - $domainUrl, + $domain, $authToken, $applicationVersion, $applicationScope ); + } public static function dataForCommand(): \Generator @@ -84,7 +90,7 @@ public static function dataForCommand(): \Generator $bitrix24Account->getApplicationVersion(), $bitrix24Account->getApplicationScope(), \InvalidArgumentException::class, - 'Domain URL is not valid.' + sprintf('Invalid domain: %s', '') ]; yield 'validBitrix24UserId' => [ diff --git a/tests/Unit/Bitrix24Accounts/UseCase/Uninstall/CommandTest.php b/tests/Unit/Bitrix24Accounts/UseCase/Uninstall/CommandTest.php index db55093..817dbb0 100644 --- a/tests/Unit/Bitrix24Accounts/UseCase/Uninstall/CommandTest.php +++ b/tests/Unit/Bitrix24Accounts/UseCase/Uninstall/CommandTest.php @@ -18,8 +18,17 @@ class CommandTest extends TestCase { #[Test] - #[DataProvider('dataForCommand')] - public function testValidCommand( + #[DataProvider('dataForCommandValidToken')] + public function testValidTokenForCommand( + string $applicationToken, + ): void { + $command = new Command($applicationToken); + $this->assertInstanceOf(Command::class, $command); + } + + #[Test] + #[DataProvider('dataForCommandEmptyToken')] + public function testEmptyTokenForCommand( string $applicationToken, ?string $expectedException, ?string $expectedExceptionMessage, @@ -32,28 +41,22 @@ public function testValidCommand( $this->expectExceptionMessage($expectedExceptionMessage); } - $command = new Command($applicationToken); - - if ($expectedException == null) { - $this->assertInstanceOf(Command::class, $command); - } + new Command($applicationToken); } - public static function dataForCommand(): \Generator + public static function dataForCommandValidToken(): \Generator { - - $applicationToken = Uuid::v7()->toRfc4122(); - yield 'validApplicationToken' => [ - $applicationToken, - null, - null, + Uuid::v7()->toRfc4122() ]; + } + public static function dataForCommandEmptyToken(): \Generator + { yield 'emptyApplicationToken' => [ '', \InvalidArgumentException::class, - 'Empty application token application token.', + 'Application token must be a non-empty string.', ]; } }