From 9abee5e9a9d57783148a2a7bff68f9d447e9068e Mon Sep 17 00:00:00 2001 From: mesilov Date: Mon, 29 Jul 2024 02:01:40 +0600 Subject: [PATCH] Add repository interface and tests for installations Added a new method `getById` to `ApplicationInstallationRepositoryInterface`. Renamed the test path prefix to `Unit`. Included various new tests for application installations, updating and reorganizing the existing structure. Signed-off-by: mesilov --- .../Docs/ApplicationInstallations.md | 144 ++++++- ...tallationApplicationStatusChangedEvent.php | 20 + ...nstallationBitrix24PartnerChangedEvent.php | 20 + ...trix24PartnerContactPersonChangedEvent.php | 20 + .../ApplicationInstallationBlockedEvent.php | 19 + ...nInstallationContactPersonChangedEvent.php | 20 + .../ApplicationInstallationCreatedEvent.php | 19 + ...tionInstallationExternalIdChangedEvent.php | 20 + .../ApplicationInstallationFinishedEvent.php | 24 ++ ...llationPortalLicenseFamilyChangedEvent.php | 21 ++ ...stallationPortalUsersCountChangedEvent.php | 20 + .../ApplicationInstallationUnblockedEvent.php | 19 + ...pplicationInstallationUninstalledEvent.php | 23 ++ ...icationInstallationRepositoryInterface.php | 12 +- ...ionInstallationRepositoryInterfaceTest.php | 354 ++++++++++++++++++ ...onInstallationRepositoryImplementation.php | 14 +- ...stallationRepositoryImplementationTest.php | 44 +++ 17 files changed, 777 insertions(+), 36 deletions(-) create mode 100644 src/Application/Contracts/ApplicationInstallations/Events/ApplicationInstallationApplicationStatusChangedEvent.php create mode 100644 src/Application/Contracts/ApplicationInstallations/Events/ApplicationInstallationBitrix24PartnerChangedEvent.php create mode 100644 src/Application/Contracts/ApplicationInstallations/Events/ApplicationInstallationBitrix24PartnerContactPersonChangedEvent.php create mode 100644 src/Application/Contracts/ApplicationInstallations/Events/ApplicationInstallationBlockedEvent.php create mode 100644 src/Application/Contracts/ApplicationInstallations/Events/ApplicationInstallationContactPersonChangedEvent.php create mode 100644 src/Application/Contracts/ApplicationInstallations/Events/ApplicationInstallationCreatedEvent.php create mode 100644 src/Application/Contracts/ApplicationInstallations/Events/ApplicationInstallationExternalIdChangedEvent.php create mode 100644 src/Application/Contracts/ApplicationInstallations/Events/ApplicationInstallationFinishedEvent.php create mode 100644 src/Application/Contracts/ApplicationInstallations/Events/ApplicationInstallationPortalLicenseFamilyChangedEvent.php create mode 100644 src/Application/Contracts/ApplicationInstallations/Events/ApplicationInstallationPortalUsersCountChangedEvent.php create mode 100644 src/Application/Contracts/ApplicationInstallations/Events/ApplicationInstallationUnblockedEvent.php create mode 100644 src/Application/Contracts/ApplicationInstallations/Events/ApplicationInstallationUninstalledEvent.php create mode 100644 tests/Application/Contracts/ApplicationInstallations/Repository/ApplicationInstallationRepositoryInterfaceTest.php rename tests/{ => Unit}/Application/Contracts/ApplicationInstallations/Repository/InMemoryApplicationInstallationRepositoryImplementation.php (81%) create mode 100644 tests/Unit/Application/Contracts/ApplicationInstallations/Repository/InMemoryApplicationInstallationRepositoryImplementationTest.php diff --git a/src/Application/Contracts/ApplicationInstallations/Docs/ApplicationInstallations.md b/src/Application/Contracts/ApplicationInstallations/Docs/ApplicationInstallations.md index 6eb0e7b8..625935e9 100644 --- a/src/Application/Contracts/ApplicationInstallations/Docs/ApplicationInstallations.md +++ b/src/Application/Contracts/ApplicationInstallations/Docs/ApplicationInstallations.md @@ -1,30 +1,134 @@ -Install Start +# Application installation entity -- add ?contact person -- add b24 Account -- add / find b24 partner -- add new installation in mode new +Store information about application installation, linked with Bitrix24 Account with auth tokens. +Optional can store links to: -Install Finish +- Client contact person: client person who responsible for application usage +- Bitrix24 Partner contact person: partner contact person who supports client and configure application +- Bitrix24 Partner: partner who supports client portal -- b24 account mark as active -- installation mark as active +| Method | Return Type | Description | Throws | +|----------------------------------------|---------------------------------|----------------------------------------------------------------------------------------|----------------------------| +| `getId()` | `Uuid` | Returns unique application installation id | | +| `getCreatedAt()` | `CarbonImmutable` | Returns date and time application installation was created | | +| `getUpdatedAt()` | `CarbonImmutable` | Returns date and time of last application installation change | | +| `getBitrix24AccountId()` | `Uuid` | Returns Bitrix24 Account id related to this installation | | +| `getContactPersonId()` | `?Uuid` | Returns contact person id who installed the application on portal (optional) | | +| `changeContactPerson()` | `void` | Changes client contact person | | +| `getBitrix24PartnerContactPersonId()` | `?Uuid` | Returns Bitrix24 partner contact person id (optional) | | +| `changeBitrix24PartnerContactPerson()` | `void` | Changes Bitrix24 partner contact person | | +| `getBitrix24PartnerId()` | `?Uuid` | Returns Bitrix24 Partner id related to this installation (optional) | | +| `changeBitrix24Partner()` | `void` | Changes Bitrix24 partner | | +| `getExternalId()` | `?string` | Returns external id for application installation | | +| `setExternalId()` | `void` | Sets external id for application installation | `InvalidArgumentException` | +| `getStatus()` | `ApplicationInstallationStatus` | Returns application installation status | | +| `applicationInstalled()` | `void` | Finishes application installation | `InvalidArgumentException` | +| `applicationUninstalled()` | `void` | Marks application as uninstalled | `InvalidArgumentException` | +| `markAsActive()` | `void` | Changes status to active for blocked application installation accounts | `InvalidArgumentException` | +| `markAsBlocked()` | `void` | Changes status to blocked for application installation accounts in state new or active | `InvalidArgumentException` | +| `getApplicationStatus()` | `ApplicationStatus` | Returns current application status stored in persistence storage | | +| `changeApplicationStatus()` | `void` | Changes application status | | +| `getPortalLicenseFamily()` | `PortalLicenseFamily` | Returns current Bitrix24 tariff plan designation without specified region | | +| `changePortalLicenseFamily()` | `void` | Changes plan designation without specified region | | +| `getPortalUsersCount()` | `?int` | Returns Bitrix24 portal users count stored in persistence storage | | +| `changePortalUsersCount()` | `void` | Changes Bitrix24 portal users count | | +| `getComment()` | `?string` | Returns comment | | -Application Active +## Application installation state diagram -- change contact person -- change bitrix24 partner contact person -- change bitrix24 partner -- change bitrix24 licence family -- change bitrix24 application status +```mermaid +stateDiagram-v2 + [*] --> New: New installation started + New --> Active : Installation completed successfully + New --> Blocked : Installation aborted + Active --> Blocked : Connection lost or\nforcibly deactivated + Active --> Deleted : Application\n uninstalled + Blocked --> Active : Reconnected or\nreactivated + Blocked --> Deleted : Delete blocked installation + Deleted --> [*]: Installation can be removed\n from persistence storage +``` -Uninstall +## Repository methods -- ?delete contact person -- delete b24 account -- mark installation as deleted +- `public function save(ApplicationInstallationInterface $applicationInstallation): void;` + - use case InstallStart + - use case InstallFinish + - use case Uninstall + - use case Activate + - use case Block + - use case ChangeContactPerson + - use case ChangeBitrix24PartnerContactPerson + - use case ChangeBitrix24Partner + - use case LinkToExternalEntity + - use case ChangeApplicationStatus + - use case ChangePortalLicenseFamily + - use case ChangePortalUsersCount +- `public function getById(Uuid $uuid): ApplicationInstallationInterface;` + - use case Activate + - use case Block + - use case InstallFinish + - use case Uninstall + - use case ChangeContactPerson + - use case ChangeBitrix24PartnerContactPerson + - use case ChangeBitrix24Partner + - use case LinkToExternalEntity + - use case ChangeApplicationStatus + - use case ChangePortalLicenseFamily + - use case ChangePortalUsersCount +- `public function delete(Uuid $uuid): void;` + - use case Uninstall +- `public function findByBitrix24AccountId(Uuid $uuid): array;` + - use case InstallFinish + - use case Uninstall + - use case ChangeApplicationStatus + - use case ChangePortalLicenseFamily + - use case ChangePortalUsersCount +- `public function findByExternalId(string $externalId): array;` + - use case LinkToExternalEntity -Background periodical tasks -- check portal license type +## Events + +- `ApplicationInstallationCreatedEvent` – Event triggered when a new installation flow was started +- `ApplicationInstallationFinishedEvent` – Event triggered when application installation flow is finished +- `ApplicationInstallationBlockedEvent` — Event triggered when application installation entity mark as blocked for + administration or technical reasons e.g. application installation was failed +- `ApplicationInstallationApplicationStatusChangedEvent` — Event triggered when background task check actual application + status +- `ApplicationInstallationContactPersonChangedEvent` — Event triggered when user in UI or admin changed client contact + person who responsible for the application +- `ApplicationInstallationBitrix24PartnerContactPersonChangedEvent` — Event triggered when user in UI or admin changed + bitrix24 partner contact person who responsible for application support +- `ApplicationInstallationBitrix24PartnerChangedEvent` — Event triggered when user in UI or admin changed bitrix24 + partner who responsible for application support +- `ApplicationInstallationExternalIdChangedEvent` – Event triggered when application installation linked with external + entity in other system +- `ApplicationInstallationPortalLicenseFamilyChangedEvent` – Event triggered when background task check actual + PortalLicenseFamily +- `ApplicationInstallationPortalUsersCountChangedEvent` – Event triggered when background task check actual users count +- `ApplicationInstallationUnblockedEvent` – Event triggered when application installation entity mark as active +- `ApplicationInstallationUninstalledEvent` — Event triggered when application uninstalled from portal + +```mermaid +%%{init: { 'logLevel': 'debug', 'theme': 'neutral' } }%% +timeline + title Application Installation timeline + section Application installation period + Create new Application Installation entity when install start : «Application Installation Created Event» + Activate Application Installation entity if install finish : «Application Installation Finished Event» + Block Application Installation entity if install failure : «Application Installation Blocked Event» + section Application active period + Change application status : «Application Installation Application Status Changed Event» + Change client contact person who responsible for application : «Application Installation Contact Person Changed Event» + Change Bitrix24 partner contact who responsible for support application : «Application Installation Bitrix24 Partner Contact Person Changed Event» + Change Bitrix24 partner whor responsible for portal support : «Application Installation Bitrix24 Partner Changed Event» + Link application installation to another entity in external system : «Application Installation ExternalId Changed Event» + Request Bitrix24 portal license type : «Application Installation Portal License Family Changed Event» + Calculate Bitrix24 portal users count: «Application Installation Portal Users Count Changed Event» + Unblock Application Installation entity : «Application Installation Unblocked Event» + section Application uninstall period + Administrator Uninstalled Application : «Application Installation Uninstalled Event» +``` +## Background periodical tasks +- check portal license type - check application status - check users count \ No newline at end of file diff --git a/src/Application/Contracts/ApplicationInstallations/Events/ApplicationInstallationApplicationStatusChangedEvent.php b/src/Application/Contracts/ApplicationInstallations/Events/ApplicationInstallationApplicationStatusChangedEvent.php new file mode 100644 index 00000000..8da8046f --- /dev/null +++ b/src/Application/Contracts/ApplicationInstallations/Events/ApplicationInstallationApplicationStatusChangedEvent.php @@ -0,0 +1,20 @@ +createApplicationInstallationRepositoryImplementation(); + + $installation = $this->createApplicationInstallationImplementation($uuid, $applicationInstallationStatus, $createdAt, $updatedAt, $bitrix24AccountUuid, $applicationStatus, $portalLicenseFamily, $portalUsersCount, $clientContactPersonUuid, $partnerContactPersonUuid, $partnerUuid, $externalId); + $appInstallationRepo->save($installation); + + $this->assertEquals($installation, $appInstallationRepo->getById($installation->getId())); + } + + #[Test] + #[DataProvider('applicationInstallationDataProvider')] + #[TestDox('test getById method for install start use case')] + final public function testGetByIdHappyPath( + Uuid $uuid, + ApplicationInstallationStatus $applicationInstallationStatus, + CarbonImmutable $createdAt, + CarbonImmutable $updatedAt, + Uuid $bitrix24AccountUuid, + ApplicationStatus $applicationStatus, + PortalLicenseFamily $portalLicenseFamily, + ?int $portalUsersCount, + ?Uuid $clientContactPersonUuid, + ?Uuid $partnerContactPersonUuid, + ?Uuid $partnerUuid, + ?string $externalId, + ): void + { + $appInstallationRepo = $this->createApplicationInstallationRepositoryImplementation(); + + $installation = $this->createApplicationInstallationImplementation($uuid, $applicationInstallationStatus, $createdAt, $updatedAt, $bitrix24AccountUuid, $applicationStatus, $portalLicenseFamily, $portalUsersCount, $clientContactPersonUuid, $partnerContactPersonUuid, $partnerUuid, $externalId); + $appInstallationRepo->save($installation); + + $this->assertEquals($installation, $appInstallationRepo->getById($installation->getId())); + } + + #[Test] + #[DataProvider('applicationInstallationDataProvider')] + #[TestDox('test getById method for install start use case')] + final public function testGetByIdWithNonExistsEntity( + Uuid $uuid, + ApplicationInstallationStatus $applicationInstallationStatus, + CarbonImmutable $createdAt, + CarbonImmutable $updatedAt, + Uuid $bitrix24AccountUuid, + ApplicationStatus $applicationStatus, + PortalLicenseFamily $portalLicenseFamily, + ?int $portalUsersCount, + ?Uuid $clientContactPersonUuid, + ?Uuid $partnerContactPersonUuid, + ?Uuid $partnerUuid, + ?string $externalId, + ): void + { + $appInstallationRepo = $this->createApplicationInstallationRepositoryImplementation(); + + $this->expectException(ApplicationInstallationNotFoundException::class); + $appInstallationRepo->getById(Uuid::v7()); + } + + /** + * @throws ApplicationInstallationNotFoundException + * @throws InvalidArgumentException + */ + #[Test] + #[DataProvider('applicationInstallationDataProvider')] + #[TestDox('test delete method')] + final public function testDeleteWithHappyPath( + Uuid $uuid, + ApplicationInstallationStatus $applicationInstallationStatus, + CarbonImmutable $createdAt, + CarbonImmutable $updatedAt, + Uuid $bitrix24AccountUuid, + ApplicationStatus $applicationStatus, + PortalLicenseFamily $portalLicenseFamily, + ?int $portalUsersCount, + ?Uuid $clientContactPersonUuid, + ?Uuid $partnerContactPersonUuid, + ?Uuid $partnerUuid, + ?string $externalId, + ): void + { + $appInstallationRepo = $this->createApplicationInstallationRepositoryImplementation(); + + $installation = $this->createApplicationInstallationImplementation($uuid, $applicationInstallationStatus, $createdAt, $updatedAt, $bitrix24AccountUuid, $applicationStatus, $portalLicenseFamily, $portalUsersCount, $clientContactPersonUuid, $partnerContactPersonUuid, $partnerUuid, $externalId); + // successfully finish installation flow + $installation->applicationInstalled(); + + // few moments later application uninstalled + // we receive ON_APPLICATION_UNINSTALL event and mark application installation as uninstalled: status = deleted + $installation->applicationUninstalled(); + $appInstallationRepo->save($installation); + + // if we want we can delete application installation from repository + $appInstallationRepo->delete($installation->getId()); + + $this->expectException(ApplicationInstallationNotFoundException::class); + $appInstallationRepo->getById($installation->getId()); + } + + /** + * @throws InvalidArgumentException + */ + #[Test] + #[DataProvider('applicationInstallationDataProvider')] + #[TestDox('test delete method with unknown id')] + final public function testDeleteWithUnknownId( + Uuid $uuid, + ApplicationInstallationStatus $applicationInstallationStatus, + CarbonImmutable $createdAt, + CarbonImmutable $updatedAt, + Uuid $bitrix24AccountUuid, + ApplicationStatus $applicationStatus, + PortalLicenseFamily $portalLicenseFamily, + ?int $portalUsersCount, + ?Uuid $clientContactPersonUuid, + ?Uuid $partnerContactPersonUuid, + ?Uuid $partnerUuid, + ?string $externalId, + ): void + { + $appInstallationRepo = $this->createApplicationInstallationRepositoryImplementation(); + + // try to delete unknown installation + $this->expectException(ApplicationInstallationNotFoundException::class); + $appInstallationRepo->delete(Uuid::v7()); + } + + #[Test] + #[DataProvider('applicationInstallationDataProvider')] + #[TestDox('test delete method with wrong state')] + final public function testDeleteWithWrongState( + Uuid $uuid, + ApplicationInstallationStatus $applicationInstallationStatus, + CarbonImmutable $createdAt, + CarbonImmutable $updatedAt, + Uuid $bitrix24AccountUuid, + ApplicationStatus $applicationStatus, + PortalLicenseFamily $portalLicenseFamily, + ?int $portalUsersCount, + ?Uuid $clientContactPersonUuid, + ?Uuid $partnerContactPersonUuid, + ?Uuid $partnerUuid, + ?string $externalId, + ): void + { + $appInstallationRepo = $this->createApplicationInstallationRepositoryImplementation(); + + $installation = $this->createApplicationInstallationImplementation($uuid, $applicationInstallationStatus, $createdAt, $updatedAt, $bitrix24AccountUuid, $applicationStatus, $portalLicenseFamily, $portalUsersCount, $clientContactPersonUuid, $partnerContactPersonUuid, $partnerUuid, $externalId); + $appInstallationRepo->save($installation); + + $this->expectException(InvalidArgumentException::class); + $appInstallationRepo->delete($installation->getId()); + } + + #[Test] + #[DataProvider('applicationInstallationDataProvider')] + #[TestDox('test findByBitrix24AccountId method')] + final public function testFindByBitrix24AccountId( + Uuid $uuid, + ApplicationInstallationStatus $applicationInstallationStatus, + CarbonImmutable $createdAt, + CarbonImmutable $updatedAt, + Uuid $bitrix24AccountUuid, + ApplicationStatus $applicationStatus, + PortalLicenseFamily $portalLicenseFamily, + ?int $portalUsersCount, + ?Uuid $clientContactPersonUuid, + ?Uuid $partnerContactPersonUuid, + ?Uuid $partnerUuid, + ?string $externalId, + ): void + { + $appInstallationRepo = $this->createApplicationInstallationRepositoryImplementation(); + + $installation = $this->createApplicationInstallationImplementation($uuid, $applicationInstallationStatus, $createdAt, $updatedAt, $bitrix24AccountUuid, $applicationStatus, $portalLicenseFamily, $portalUsersCount, $clientContactPersonUuid, $partnerContactPersonUuid, $partnerUuid, $externalId); + $appInstallationRepo->save($installation); + + $this->assertEquals([$installation], $appInstallationRepo->findByBitrix24AccountId($bitrix24AccountUuid)); + } + + #[Test] + #[DataProvider('applicationInstallationDataProvider')] + #[TestDox('test findByBitrix24AccountId method with unknown id')] + final public function testFindByBitrix24AccountIdWithUnknownId( + Uuid $uuid, + ApplicationInstallationStatus $applicationInstallationStatus, + CarbonImmutable $createdAt, + CarbonImmutable $updatedAt, + Uuid $bitrix24AccountUuid, + ApplicationStatus $applicationStatus, + PortalLicenseFamily $portalLicenseFamily, + ?int $portalUsersCount, + ?Uuid $clientContactPersonUuid, + ?Uuid $partnerContactPersonUuid, + ?Uuid $partnerUuid, + ?string $externalId, + ): void + { + $appInstallationRepo = $this->createApplicationInstallationRepositoryImplementation(); + + $this->assertEquals([], $appInstallationRepo->findByBitrix24AccountId(Uuid::v7())); + } + + /** + * @throws InvalidArgumentException + */ + #[Test] + #[DataProvider('applicationInstallationDataProvider')] + #[TestDox('test findByExternalId method')] + final public function testFindByExternalId( + Uuid $uuid, + ApplicationInstallationStatus $applicationInstallationStatus, + CarbonImmutable $createdAt, + CarbonImmutable $updatedAt, + Uuid $bitrix24AccountUuid, + ApplicationStatus $applicationStatus, + PortalLicenseFamily $portalLicenseFamily, + ?int $portalUsersCount, + ?Uuid $clientContactPersonUuid, + ?Uuid $partnerContactPersonUuid, + ?Uuid $partnerUuid, + ?string $externalId, + ): void + { + $appInstallationRepo = $this->createApplicationInstallationRepositoryImplementation(); + + $installation = $this->createApplicationInstallationImplementation($uuid, $applicationInstallationStatus, $createdAt, $updatedAt, $bitrix24AccountUuid, $applicationStatus, $portalLicenseFamily, $portalUsersCount, $clientContactPersonUuid, $partnerContactPersonUuid, $partnerUuid, $externalId); + $externalId = Uuid::v7()->toRfc4122(); + $installation->setExternalId($externalId); + $appInstallationRepo->save($installation); + + $this->assertEquals([$installation], $appInstallationRepo->findByExternalId($externalId)); + } + + #[Test] + #[DataProvider('applicationInstallationDataProvider')] + #[TestDox('test findByExternalId method with unknown id')] + final public function testFindByExternalIdWithUnknownId( + Uuid $uuid, + ApplicationInstallationStatus $applicationInstallationStatus, + CarbonImmutable $createdAt, + CarbonImmutable $updatedAt, + Uuid $bitrix24AccountUuid, + ApplicationStatus $applicationStatus, + PortalLicenseFamily $portalLicenseFamily, + ?int $portalUsersCount, + ?Uuid $clientContactPersonUuid, + ?Uuid $partnerContactPersonUuid, + ?Uuid $partnerUuid, + ?string $externalId, + ): void + { + $appInstallationRepo = $this->createApplicationInstallationRepositoryImplementation(); + + $externalId = Uuid::v7()->toRfc4122(); + $this->assertEquals([], $appInstallationRepo->findByExternalId($externalId)); + } + + public static function applicationInstallationDataProvider(): Generator + { + yield 'status-new-all-fields' => [ + Uuid::v7(), // uuid + ApplicationInstallationStatus::new, // application installation status + CarbonImmutable::now(), // created at + CarbonImmutable::createFromMutable((new DateTime())->add(new DateInterval('PT1H'))), // updated at + Uuid::v7(), // bitrix24 account id + ApplicationStatus::subscription(), // application status from bitrix24 api call response + PortalLicenseFamily::nfr, // portal license family value + 42, // bitrix24 portal users count + Uuid::v7(), // ?client contact person id + Uuid::v7(), // ?partner contact person id + Uuid::v7(), // ?partner id + Uuid::v7()->toRfc4122(), // external id + ]; + yield 'status-new-without-all-optional-fields' => [ + Uuid::v7(), // uuid + ApplicationInstallationStatus::new, // application installation status + CarbonImmutable::now(), // created at + CarbonImmutable::createFromMutable((new DateTime())->add(new DateInterval('PT1H'))), // updated at + Uuid::v7(), // bitrix24 account id + ApplicationStatus::subscription(), // application status from bitrix24 api call response + PortalLicenseFamily::nfr, // portal license family value + null, // bitrix24 portal users count + null, // ?client contact person id + null, // ?partner contact person id + null, // ?partner id + null, // external id + ]; + } +} \ No newline at end of file diff --git a/tests/Application/Contracts/ApplicationInstallations/Repository/InMemoryApplicationInstallationRepositoryImplementation.php b/tests/Unit/Application/Contracts/ApplicationInstallations/Repository/InMemoryApplicationInstallationRepositoryImplementation.php similarity index 81% rename from tests/Application/Contracts/ApplicationInstallations/Repository/InMemoryApplicationInstallationRepositoryImplementation.php rename to tests/Unit/Application/Contracts/ApplicationInstallations/Repository/InMemoryApplicationInstallationRepositoryImplementation.php index 5d6a6dc6..c8308294 100644 --- a/tests/Application/Contracts/ApplicationInstallations/Repository/InMemoryApplicationInstallationRepositoryImplementation.php +++ b/tests/Unit/Application/Contracts/ApplicationInstallations/Repository/InMemoryApplicationInstallationRepositoryImplementation.php @@ -2,22 +2,16 @@ declare(strict_types=1); -namespace Bitrix24\SDK\Tests\Application\Contracts\ApplicationInstallations\Repository; +namespace Bitrix24\SDK\Tests\Unit\Application\Contracts\ApplicationInstallations\Repository; use Bitrix24\SDK\Application\Contracts\ApplicationInstallations\Entity\ApplicationInstallationInterface; use Bitrix24\SDK\Application\Contracts\ApplicationInstallations\Entity\ApplicationInstallationStatus; use Bitrix24\SDK\Application\Contracts\ApplicationInstallations\Exceptions\ApplicationInstallationNotFoundException; use Bitrix24\SDK\Application\Contracts\ApplicationInstallations\Repository\ApplicationInstallationRepositoryInterface; -use Bitrix24\SDK\Application\Contracts\ContactPersons\Entity\ContactPersonInterface; -use Bitrix24\SDK\Application\Contracts\ContactPersons\Entity\ContactPersonStatus; -use Bitrix24\SDK\Application\Contracts\ContactPersons\Exceptions\ContactPersonNotFoundException; -use Bitrix24\SDK\Application\Contracts\ContactPersons\Repository\ContactPersonRepositoryInterface; use Bitrix24\SDK\Core\Exceptions\InvalidArgumentException; -use libphonenumber\PhoneNumber; use Psr\Log\LoggerInterface; use Symfony\Component\Uid\Uuid; - class InMemoryApplicationInstallationRepositoryImplementation implements ApplicationInstallationRepositoryInterface { /** @@ -64,13 +58,13 @@ public function getById(Uuid $uuid): ApplicationInstallationInterface return $this->items[$uuid->toRfc4122()]; } - public function findByBitrix24AccountId(Uuid $bitrix24AccountId): array + public function findByBitrix24AccountId(Uuid $uuid): array { - $this->logger->debug('InMemoryApplicationInstallationRepositoryImplementation.findByBitrix24AccountId', ['id' => $bitrix24AccountId->toRfc4122()]); + $this->logger->debug('InMemoryApplicationInstallationRepositoryImplementation.findByBitrix24AccountId', ['id' => $uuid->toRfc4122()]); $result = []; foreach ($this->items as $item) { - if ($item->getBitrix24AccountId() === $bitrix24AccountId) { + if ($item->getBitrix24AccountId() === $uuid) { $result[] = $item; } } diff --git a/tests/Unit/Application/Contracts/ApplicationInstallations/Repository/InMemoryApplicationInstallationRepositoryImplementationTest.php b/tests/Unit/Application/Contracts/ApplicationInstallations/Repository/InMemoryApplicationInstallationRepositoryImplementationTest.php new file mode 100644 index 00000000..17c8e63f --- /dev/null +++ b/tests/Unit/Application/Contracts/ApplicationInstallations/Repository/InMemoryApplicationInstallationRepositoryImplementationTest.php @@ -0,0 +1,44 @@ +