diff --git a/.github/workflows/tests-functional.yml b/.github/workflows/tests-functional.yml index 9db731a..b17a851 100644 --- a/.github/workflows/tests-functional.yml +++ b/.github/workflows/tests-functional.yml @@ -23,14 +23,14 @@ jobs: php-version: - "8.3" dependencies: [ highest ] - operating-system: [ ubuntu-latest] + operating-system: [ ubuntu-latest ] services: bitrix24-php-lib-test-database: - image: postgres:16 + image: postgres:16-alpine ports: - 5432:5432 options: >- - --health-cmd="pg_isready -U postgres" + --health-cmd="pg_isready -U b24phpLibTest" --health-interval=10s --health-timeout=5s --health-retries=5 @@ -38,7 +38,6 @@ jobs: POSTGRES_USER: b24phpLibTest POSTGRES_PASSWORD: b24phpLibTest POSTGRES_DB: b24phpLibTest - DATABASE_HOST: localhost steps: - name: "Checkout code" @@ -55,20 +54,26 @@ jobs: run: | composer update ${{ env.COMPOSER_FLAGS }} + - name: "Install PostgreSQL client" + run: | + sudo apt-get update + sudo apt-get install -y postgresql-client + - name: "Wait for PostgreSQL to be ready" run: | - until pg_isready -h localhost -p 5432 -U user; do - echo "Waiting for PostgreSQL to start..." - sleep 2 - done + until pg_isready -h localhost -p 5432 -U b24phpLibTest; do + echo "Waiting for PostgreSQL to start..." + sleep 2 + done - name: "Run functional tests" run: | - php bin/doctrine orm:schema-tool:drop --force - php bin/doctrine orm:schema-tool:create --dump-sql - php bin/doctrine orm:schema-tool:update --dump-sql - php bin/doctrine orm:info - php vendor/bin/phpunit --testsuite=functional_tests --display-warnings --testdox + php bin/doctrine orm:schema-tool:drop --force + php bin/doctrine orm:schema-tool:create --dump-sql + php bin/doctrine orm:schema-tool:update --force + php bin/doctrine orm:info + # Запуск тестов с очисткой состояния между тестами + php vendor/bin/phpunit --testsuite=functional_tests --display-warnings --testdox --process-isolation - name: "is functional tests succeeded" if: ${{ success() }} @@ -78,4 +83,4 @@ jobs: - name: "is functional tests failed" if: ${{ failure() }} run: | - echo '::error:: ❗️ functional tests failed (╯°益°)╯彡┻━┻' \ No newline at end of file + echo '::error:: ❗️ functional tests failed (╯°益°)╯彡┻━┻' diff --git a/docker-compose.yaml b/docker-compose.yaml index fb520fb..fbdff87 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -22,7 +22,7 @@ services: PGDATA: "/var/lib/postgresql/data/pgdata" container_name: bitrix24-php-lib-test-database ports: - - '5432:5432' + - '5438:5432' volumes: - ./docker/init_database/:/docker-entrypoint-initdb.d - ./docker/db:/var/lib/postgresql/data diff --git a/src/Bitrix24Accounts/Entity/Bitrix24Account.php b/src/Bitrix24Accounts/Entity/Bitrix24Account.php index 597c68d..a269988 100644 --- a/src/Bitrix24Accounts/Entity/Bitrix24Account.php +++ b/src/Bitrix24Accounts/Entity/Bitrix24Account.php @@ -309,14 +309,14 @@ public function getComment(): ?string return $this->comment; } - private function guardEmptyToken($applicationToken) + private function guardEmptyToken(string $applicationToken): void { if ('' === $applicationToken) { throw new InvalidArgumentException('application token cannot be empty'); } } - private function guardTokenMismatch($applicationToken): void + private function guardTokenMismatch(string $applicationToken): void { if ($this->applicationToken !== $applicationToken) { throw new InvalidArgumentException( diff --git a/src/Bitrix24Accounts/Infrastructure/Doctrine/Bitrix24AccountRepository.php b/src/Bitrix24Accounts/Infrastructure/Doctrine/Bitrix24AccountRepository.php index 804b299..5fb37ad 100644 --- a/src/Bitrix24Accounts/Infrastructure/Doctrine/Bitrix24AccountRepository.php +++ b/src/Bitrix24Accounts/Infrastructure/Doctrine/Bitrix24AccountRepository.php @@ -38,7 +38,8 @@ public function getById(Uuid $uuid): Bitrix24AccountInterface ->setParameter('id', $uuid) ->setParameter('status', Bitrix24AccountStatus::deleted) ->getQuery() - ->getOneOrNullResult(); + ->getOneOrNullResult() + ; if (null === $account) { throw new Bitrix24AccountNotFoundException( @@ -58,13 +59,10 @@ public function existsById(Uuid $uuid): bool ->setParameter('id', $uuid) ->setParameter('status', Bitrix24AccountStatus::deleted) ->getQuery() - ->getOneOrNullResult(); + ->getOneOrNullResult() + ; - if ($account) { - return true; - } - - return false; + return (bool) $account; } #[\Override] @@ -84,8 +82,7 @@ public function findByMemberId( ?Bitrix24AccountStatus $bitrix24AccountStatus = null, ?int $bitrix24UserId = null, ?bool $isAdmin = null - ): array - { + ): array { if ('' === trim($memberId)) { throw new InvalidArgumentException('memberId cannot be empty'); } @@ -198,15 +195,13 @@ public function findByDomain( string $domainUrl, ?Bitrix24AccountStatus $bitrix24AccountStatus = null, ?bool $isAdmin = null - ): array - { + ): array { if ('' === trim($domainUrl)) { throw new InvalidArgumentException('domainUrl cannot be an empty string'); } - $criteria = [ - 'domainUrl' => $domainUrl, - ]; + $criteria = ['domainUrl' => $domainUrl]; + if ($bitrix24AccountStatus instanceof Bitrix24AccountStatus) { $criteria['status'] = $bitrix24AccountStatus->name; } diff --git a/src/Bitrix24Accounts/ReadModel/Bitrix24AccountFetcher.php b/src/Bitrix24Accounts/ReadModel/Bitrix24AccountFetcher.php deleted file mode 100644 index 73b4900..0000000 --- a/src/Bitrix24Accounts/ReadModel/Bitrix24AccountFetcher.php +++ /dev/null @@ -1,37 +0,0 @@ -em->createQueryBuilder() - ->select( - 'b24account.id as id', - 'b24account.status as status', - 'b24account.memberId as member_id', - 'b24account.domainUrl as domain_url', - 'b24account.applicationVersion as application_version', - 'b24account.createdAt as created_at_utc', - 'b24account.updatedAt as updated_at_utc', - ) - ->from('Bitrix24\Lib\Bitrix24Accounts\Entity\Bitrix24Account', 'b24account') - ->orderBy('b24account.createdAt', 'DESC'); - - return $this->paginator->paginate($qb, $page, $size); - } -} diff --git a/src/Bitrix24Accounts/UseCase/ChangeDomainUrl/Command.php b/src/Bitrix24Accounts/UseCase/ChangeDomainUrl/Command.php index e488548..0304d13 100644 --- a/src/Bitrix24Accounts/UseCase/ChangeDomainUrl/Command.php +++ b/src/Bitrix24Accounts/UseCase/ChangeDomainUrl/Command.php @@ -8,21 +8,32 @@ { public function __construct( /** - * @var non-empty-string $oldDomainUrlHost + * @var non-empty-string $oldDomain */ - public string $oldDomainUrlHost, + public string $oldDomain, /** - * @var non-empty-string $newDomainUrlHost + * @var non-empty-string $newDomain */ - public string $newDomainUrlHost + public string $newDomain ) { - $this->validateDomain($oldDomainUrlHost, 'oldDomainUrlHost'); - $this->validateDomain($newDomainUrlHost, 'newDomainUrlHost'); + $this->validateDomain($oldDomain, 'oldDomainUrlHost'); + $this->validateDomain($newDomain, 'newDomainUrlHost'); } private function validateDomain(string $domain, string $parameterName): void { - if (empty($domain) || !filter_var($domain, FILTER_VALIDATE_URL)) { + // Регулярное выражение для проверки допустимых символов (латиница и кириллица) + $patternValidChars = '/^((?!-)[A-Za-zА-Яа-яЁё0-9-]{1,63}(?logger->info('Bitrix24Accounts.ChangeDomainUrl.start', [ - 'b24_domain_url_old' => $command->oldDomainUrlHost, - 'b24_domain_url_new' => $command->newDomainUrlHost, + 'b24_domain_url_old' => $command->oldDomain, + 'b24_domain_url_new' => $command->newDomain, ]); /** @var AggregateRootEventsEmitterInterface[]|Bitrix24AccountInterface[] $accounts */ - $accounts = $this->bitrix24AccountRepository->findByDomain($command->oldDomainUrlHost); + $accounts = $this->bitrix24AccountRepository->findByDomain($command->oldDomain); foreach ($accounts as $account) { - $account->changeDomainUrl($command->newDomainUrlHost); + $account->changeDomainUrl($command->newDomain); $this->bitrix24AccountRepository->save($account); } @@ -38,8 +38,8 @@ public function handle(Command $command): void $this->logger->info( 'Bitrix24Accounts.ChangeDomainUrl.Finish', [ - 'b24_domain_url_old' => $command->oldDomainUrlHost, - 'b24_domain_url_new' => $command->newDomainUrlHost, + 'b24_domain_url_old' => $command->oldDomain, + 'b24_domain_url_new' => $command->newDomain, ] ); } diff --git a/src/Bitrix24Accounts/UseCase/InstallFinish/Command.php b/src/Bitrix24Accounts/UseCase/InstallFinish/Command.php index 946532e..339d739 100644 --- a/src/Bitrix24Accounts/UseCase/InstallFinish/Command.php +++ b/src/Bitrix24Accounts/UseCase/InstallFinish/Command.php @@ -10,20 +10,42 @@ public function __construct( public string $applicationToken, public string $memberId, public string $domainUrl, - public ?int $bitrix24UserId, + public int $bitrix24UserId, ) { $this->validate(); } private function validate(): void { - if (empty($this->applicationToken)) { + if ('' === $this->applicationToken || '0' === $this->applicationToken) { throw new \InvalidArgumentException('Application token cannot be empty.'); } - if (empty($this->memberId)) { + + if ('' === $this->memberId || '0' === $this->memberId) { throw new \InvalidArgumentException('Member ID cannot be empty.'); } - if (!filter_var($this->domainUrl, FILTER_VALIDATE_URL)) { + + $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}(?memberId) || empty($this->memberId)) { + if (!is_string($this->memberId) || ('' === $this->memberId || '0' === $this->memberId)) { throw new \InvalidArgumentException('Member ID must be a non-empty string.'); } - if (!filter_var($this->domainUrl, FILTER_VALIDATE_URL)) { - throw new \InvalidArgumentException('Domain URL is not valid.'); - } + $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}(?applicationToken)) { + if ('' === $this->applicationToken || '0' === $this->applicationToken) { throw new \InvalidArgumentException('Empty application token application token.'); } } diff --git a/src/Bitrix24Accounts/UseCase/Uninstall/Handler.php b/src/Bitrix24Accounts/UseCase/Uninstall/Handler.php index f72a088..516126b 100644 --- a/src/Bitrix24Accounts/UseCase/Uninstall/Handler.php +++ b/src/Bitrix24Accounts/UseCase/Uninstall/Handler.php @@ -35,6 +35,7 @@ public function handle(Command $command): void $account->applicationUninstalled($command->applicationToken); $this->bitrix24AccountRepository->save($account); } + $this->flusher->flush(...$accounts); $this->logger->info( diff --git a/src/Services/Flusher.php b/src/Services/Flusher.php index bd33cdd..240ff74 100644 --- a/src/Services/Flusher.php +++ b/src/Services/Flusher.php @@ -10,20 +10,13 @@ class Flusher { - private $em; - private $eventDispatcher; + public function __construct(private readonly EntityManagerInterface $em, private readonly EventDispatcherInterface $eventDispatcher) {} - public function __construct(EntityManagerInterface $em, EventDispatcherInterface $eventDispatcher) - { - $this->em = $em; - $this->eventDispatcher = $eventDispatcher; - } - - public function flush(AggregateRootEventsEmitterInterface ...$roots): void + public function flush(AggregateRootEventsEmitterInterface ...$aggregateRootEventsEmitter): void { $this->em->flush(); - foreach ($roots as $root) { - $events = $root->emitEvents(); + foreach ($aggregateRootEventsEmitter as $aggregateRootEventEmitter) { + $events = $aggregateRootEventEmitter->emitEvents(); foreach ($events as $event) { $this->eventDispatcher->dispatch($event); } diff --git a/tests/Functional/Bitrix24Accounts/Builders/Bitrix24AccountBuilder.php b/tests/Functional/Bitrix24Accounts/Builders/Bitrix24AccountBuilder.php index 89423e8..a63331a 100644 --- a/tests/Functional/Bitrix24Accounts/Builders/Bitrix24AccountBuilder.php +++ b/tests/Functional/Bitrix24Accounts/Builders/Bitrix24AccountBuilder.php @@ -55,7 +55,7 @@ public function __construct() $this->bitrix24UserId = random_int(1, 1_000_000); $this->isBitrix24UserAdmin = true; $this->memberId = Uuid::v4()->toRfc4122(); - $this->domainUrl = 'https://'.Uuid::v7()->toRfc4122().'-test.bitrix24.com'; + $this->domainUrl = Uuid::v4()->toRfc4122().'-example.com'; $this->authToken = new AuthToken('old_1', 'old_2', 3600); $this->createdAt = CarbonImmutable::now(); $this->updatedAt = CarbonImmutable::now(); @@ -100,7 +100,7 @@ public function withStatus(Bitrix24AccountStatus $bitrix24AccountStatus): self public function build(): AggregateRootEventsEmitterInterface&Bitrix24AccountInterface { - $account = new Bitrix24Account( + $bitrix24Account = new Bitrix24Account( $this->id, $this->bitrix24UserId, $this->isBitrix24UserAdmin, @@ -114,10 +114,10 @@ public function build(): AggregateRootEventsEmitterInterface&Bitrix24AccountInte $this->applicationScope ); - if (isset($this->applicationToken) && Bitrix24AccountStatus::new == $this->status) { - $account->applicationInstalled($this->applicationToken); + if ($this->applicationToken !== null && Bitrix24AccountStatus::new == $this->status) { + $bitrix24Account->applicationInstalled($this->applicationToken); } - return $account; + return $bitrix24Account; } } diff --git a/tests/Functional/Bitrix24Accounts/UseCase/ChangeDomainUrl/HandlerTest.php b/tests/Functional/Bitrix24Accounts/UseCase/ChangeDomainUrl/HandlerTest.php index c21d48f..36a21f2 100644 --- a/tests/Functional/Bitrix24Accounts/UseCase/ChangeDomainUrl/HandlerTest.php +++ b/tests/Functional/Bitrix24Accounts/UseCase/ChangeDomainUrl/HandlerTest.php @@ -60,8 +60,8 @@ protected function setUp(): void } #[Test] - #[TestDox('Test change domain url with happy path - one account')] - public function testChangeDomainUrlWithHappyPath(): void + #[TestDox('Test change domain url for one account')] + public function testChangeDomainUrlForAccount(): void { $oldDomainUrl = Uuid::v7()->toRfc4122().'-test.bitrix24.com'; $newDomainUrl = 'new-'.$oldDomainUrl; @@ -103,8 +103,8 @@ public function testChangeDomainUrlWithHappyPath(): void } #[Test] - #[TestDox('Test change domain url with happy path - many accounts')] - public function testChangeDomainUrlWithHappyPathForManyAccounts(): void + #[TestDox('Test change domain url for many accounts')] + public function testChangeDomainUrlForManyAccounts(): void { $oldDomainUrl = Uuid::v7()->toRfc4122().'-test.bitrix24.com'; $newDomainUrl = 'new-'.$oldDomainUrl; diff --git a/tests/Functional/Bitrix24Accounts/UseCase/InstallFinish/HandlerTest.php b/tests/Functional/Bitrix24Accounts/UseCase/InstallFinish/HandlerTest.php index 0b1d67b..04a8e05 100644 --- a/tests/Functional/Bitrix24Accounts/UseCase/InstallFinish/HandlerTest.php +++ b/tests/Functional/Bitrix24Accounts/UseCase/InstallFinish/HandlerTest.php @@ -51,6 +51,7 @@ protected function setUp(): void $entityManager = EntityManagerFactory::get(); $eventDispatcher = new EventDispatcher(); $this->eventDispatcher = new TraceableEventDispatcher($eventDispatcher, new Stopwatch()); + $this->repository = new Bitrix24AccountRepository($entityManager); $this->flusher = new Flusher($entityManager, $this->eventDispatcher); @@ -62,8 +63,8 @@ protected function setUp(): void } #[Test] - #[TestDox('test finish installation with happy path')] - public function testFinishInstallationWithHappyPath(): void + #[TestDox('test finish installation application')] + public function testFinishInstallationApplication(): void { $bitrix24Account = (new Bitrix24AccountBuilder()) ->withStatus(Bitrix24AccountStatus::new) diff --git a/tests/Functional/Bitrix24Accounts/UseCase/InstallStart/HandlerTest.php b/tests/Functional/Bitrix24Accounts/UseCase/InstallStart/HandlerTest.php index fc8572e..aecab34 100644 --- a/tests/Functional/Bitrix24Accounts/UseCase/InstallStart/HandlerTest.php +++ b/tests/Functional/Bitrix24Accounts/UseCase/InstallStart/HandlerTest.php @@ -69,7 +69,7 @@ protected function setUp(): void * @throws UnknownScopeCodeException */ #[Test] - public function testInstallStartHappyPath(): void + public function testInstallNewApplication(): void { $bitrix24AccountBuilder = (new Bitrix24AccountBuilder()) ->withApplicationScope(new Scope(['crm'])) @@ -169,7 +169,7 @@ public function testInstallStartHappyPath(): void * @throws UnknownScopeCodeException */ #[Test] - public function testCreateExistingAccount(): void + public function testInstallExistingAccount(): void { $bitrix24Account = (new Bitrix24AccountBuilder()) ->withApplicationScope(new Scope(['crm'])) @@ -207,6 +207,8 @@ public function testCreateExistingAccount(): void ); } + + #[Test] public function testUpdateAppVersion(): void {} } diff --git a/tests/Functional/Bitrix24Accounts/UseCase/RenewAuthToken/HandlerTest.php b/tests/Functional/Bitrix24Accounts/UseCase/RenewAuthToken/HandlerTest.php index 257efde..31a5855 100644 --- a/tests/Functional/Bitrix24Accounts/UseCase/RenewAuthToken/HandlerTest.php +++ b/tests/Functional/Bitrix24Accounts/UseCase/RenewAuthToken/HandlerTest.php @@ -51,6 +51,7 @@ protected function setUp(): void $entityManager = EntityManagerFactory::get(); $eventDispatcher = new EventDispatcher(); $this->eventDispatcher = new TraceableEventDispatcher($eventDispatcher, new Stopwatch()); + $this->repository = new Bitrix24AccountRepository($entityManager); $this->flusher = new Flusher($entityManager, $this->eventDispatcher); $this->handler = new Handler( diff --git a/tests/Functional/Bitrix24Accounts/UseCase/Uninstall/HandlerTest.php b/tests/Functional/Bitrix24Accounts/UseCase/Uninstall/HandlerTest.php index 556af50..a902791 100644 --- a/tests/Functional/Bitrix24Accounts/UseCase/Uninstall/HandlerTest.php +++ b/tests/Functional/Bitrix24Accounts/UseCase/Uninstall/HandlerTest.php @@ -52,6 +52,7 @@ protected function setUp(): void $entityManager = EntityManagerFactory::get(); $eventDispatcher = new EventDispatcher(); $this->eventDispatcher = new TraceableEventDispatcher($eventDispatcher, new Stopwatch()); + $this->repository = new Bitrix24AccountRepository($entityManager); $this->flusher = new Flusher($entityManager, $this->eventDispatcher); @@ -67,7 +68,7 @@ protected function setUp(): void * @throws Bitrix24AccountNotFoundException */ #[Test] - public function testUninstallWithHappyPath(): void + public function testUninstallApplication(): void { $applicationToken = Uuid::v7()->toRfc4122(); @@ -82,7 +83,7 @@ public function testUninstallWithHappyPath(): void $this->handler->handle(new Bitrix24Accounts\UseCase\Uninstall\Command($applicationToken)); $this->expectException(Bitrix24AccountNotFoundException::class); - $updated = $this->repository->getById($bitrix24Account->getId()); + $this->repository->getById($bitrix24Account->getId()); $this->assertTrue( in_array( diff --git a/tests/Unit/Bitrix24Accounts/DomainCheckerTest.php b/tests/Unit/Bitrix24Accounts/DomainCheckerTest.php new file mode 100644 index 0000000..123e0f4 --- /dev/null +++ b/tests/Unit/Bitrix24Accounts/DomainCheckerTest.php @@ -0,0 +1,83 @@ +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 6cd78db..bfd3e1d 100644 --- a/tests/Unit/Bitrix24Accounts/UseCase/ChangeDomainUrl/CommandTest.php +++ b/tests/Unit/Bitrix24Accounts/UseCase/ChangeDomainUrl/CommandTest.php @@ -9,7 +9,7 @@ use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\Attributes\Test; use PHPUnit\Framework\TestCase; -use Symfony\Component\Uid\Uuid; + /** * @internal @@ -20,26 +20,42 @@ class CommandTest extends TestCase #[Test] #[DataProvider('dataForCommand')] public function testValidCommand( - string $oldDomainUrl, - string $newDomainUrl, + string $oldDomain, + string $newDomain, ?string $expectedException - ) { - if (null !== $expectedException) { - $this->expectException($expectedException); + ): void + { + + if ($expectedException !== null) { + $this->expectException(\InvalidArgumentException::class); + } + + $command = new Command($oldDomain, $newDomain); + + if ($expectedException == null) { + $this->assertInstanceOf(Command::class, $command); } - new Command($oldDomainUrl, $newDomainUrl); } public static function dataForCommand(): \Generator { - $oldDomainUrl = 'https://'.Uuid::v7()->toRfc4122().'-test.bitrix24.com'; - $newDomainUrl = Uuid::v7()->toRfc4122().'-test.bitrix24.com'; + $invalidOldDomain = 'invalid_domain.com'; + $invalidNewDomain = 'valid.com'; + + $validOldDomain = 'example.com'; + $validNewDomain = 'example.org'; - yield 'validDomainUrl' => [ - $oldDomainUrl, - $newDomainUrl, + yield 'invalidDomain' => [ + $invalidOldDomain, + $invalidNewDomain, \InvalidArgumentException::class ]; + + yield 'validDomain' => [ + $validOldDomain, + $validNewDomain, + null // Здесь исключение не ожидается + ]; } } diff --git a/tests/Unit/Bitrix24Accounts/UseCase/InstallFinish/CommandTest.php b/tests/Unit/Bitrix24Accounts/UseCase/InstallFinish/CommandTest.php index df1225d..c11824b 100644 --- a/tests/Unit/Bitrix24Accounts/UseCase/InstallFinish/CommandTest.php +++ b/tests/Unit/Bitrix24Accounts/UseCase/InstallFinish/CommandTest.php @@ -28,7 +28,7 @@ public function testValidCommand( int $bitrix24UserId, ?string $expectedException, ?string $expectedExceptionMessage, - ) { + ): void { if (null !== $expectedException) { $this->expectException($expectedException); } @@ -70,7 +70,7 @@ public static function dataForCommand(): \Generator 'Member ID cannot be empty.' ]; - yield 'validDomainUrl' => [ + yield 'validDomain' => [ $applicationToken, $bitrix24Account->getMemberId(), '', diff --git a/tests/Unit/Bitrix24Accounts/UseCase/InstallStart/CommandTest.php b/tests/Unit/Bitrix24Accounts/UseCase/InstallStart/CommandTest.php index a66d531..c9f1a21 100644 --- a/tests/Unit/Bitrix24Accounts/UseCase/InstallStart/CommandTest.php +++ b/tests/Unit/Bitrix24Accounts/UseCase/InstallStart/CommandTest.php @@ -34,7 +34,7 @@ public function testValidCommand( Scope $applicationScope, ?string $expectedException, ?string $expectedExceptionMessage, - ) { + ): void { if (null !== $expectedException) { $this->expectException($expectedException); } @@ -57,7 +57,6 @@ public function testValidCommand( public static function dataForCommand(): \Generator { - $applicationToken = Uuid::v7()->toRfc4122(); $bitrix24Account = (new Bitrix24AccountBuilder()) ->withStatus(Bitrix24AccountStatus::new) ->build(); diff --git a/tests/Unit/Bitrix24Accounts/UseCase/Uninstall/CommandTest.php b/tests/Unit/Bitrix24Accounts/UseCase/Uninstall/CommandTest.php index 36fac0f..db55093 100644 --- a/tests/Unit/Bitrix24Accounts/UseCase/Uninstall/CommandTest.php +++ b/tests/Unit/Bitrix24Accounts/UseCase/Uninstall/CommandTest.php @@ -9,6 +9,7 @@ use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\Attributes\Test; use PHPUnit\Framework\TestCase; +use Symfony\Component\Uid\Uuid; /** * @internal @@ -22,7 +23,7 @@ public function testValidCommand( string $applicationToken, ?string $expectedException, ?string $expectedExceptionMessage, - ) { + ): void { if (null !== $expectedException) { $this->expectException($expectedException); } @@ -31,12 +32,25 @@ public function testValidCommand( $this->expectExceptionMessage($expectedExceptionMessage); } - new Command($applicationToken); + $command = new Command($applicationToken); + + if ($expectedException == null) { + $this->assertInstanceOf(Command::class, $command); + } } public static function dataForCommand(): \Generator { + + $applicationToken = Uuid::v7()->toRfc4122(); + yield 'validApplicationToken' => [ + $applicationToken, + null, + null, + ]; + + yield 'emptyApplicationToken' => [ '', \InvalidArgumentException::class, 'Empty application token application token.',