From 1e565046bf301e1416c6b695488e112386bea75c Mon Sep 17 00:00:00 2001 From: KarlsonComplete Date: Wed, 16 Oct 2024 01:03:57 +0300 Subject: [PATCH 1/4] =?UTF-8?q?-=20=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=B8?= =?UTF-8?q?=D0=BB=20Flusher.php=20-=20=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=B8?= =?UTF-8?q?=D0=BB=20=D0=B2=D1=8B=D0=B7=D0=BE=D0=B2=20flusher=20=D0=B2=20Bi?= =?UTF-8?q?trix24AccountRepository.php=20,=20=D0=BD=D0=BE=20=D1=87=D1=82?= =?UTF-8?q?=D0=BE=20=D1=82=D0=BE=20=D0=BF=D0=BE=D0=BB=D1=83=D1=87=D0=B0?= =?UTF-8?q?=D0=B5=D1=82=D1=81=D1=8F=20=D0=BD=D0=B5=20=D1=82=D0=B0=D0=BA.?= =?UTF-8?q?=20-=20=D0=92=20=D1=84=D1=83=D0=BD=D0=BA=D1=86=D0=B8=D0=BE?= =?UTF-8?q?=D0=BD=D0=B0=D0=BB=D1=8C=D0=BD=D1=8B=D1=85=20=D1=82=D0=B5=D1=81?= =?UTF-8?q?=D1=82=D0=B0=D1=85=20=D0=BF=D0=BE=D0=BB=D1=83=D1=87=D0=B0=D0=B5?= =?UTF-8?q?=D1=82=D1=81=D1=8F=20=D0=B1=D0=BE=D0=BB=D1=8C=D1=88=D0=B5=20?= =?UTF-8?q?=D0=BE=D1=88=D0=B8=D0=B1=D0=BE=D0=BA=20=D0=B8=D0=B7=20=D0=B7?= =?UTF-8?q?=D0=B0=20=D0=B2=D1=8B=D0=B7=D0=BE=D0=B2=D0=B0=20flusher.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Doctrine/Bitrix24AccountRepository.php | 9 +++++++-- .../UseCase/Command/Flusher.php | 17 +++++++++++++++++ 2 files changed, 24 insertions(+), 2 deletions(-) create mode 100644 src/Bitrix24Accounts/UseCase/Command/Flusher.php diff --git a/src/Bitrix24Accounts/Infrastructure/Doctrine/Bitrix24AccountRepository.php b/src/Bitrix24Accounts/Infrastructure/Doctrine/Bitrix24AccountRepository.php index fe5f33e..f11398e 100644 --- a/src/Bitrix24Accounts/Infrastructure/Doctrine/Bitrix24AccountRepository.php +++ b/src/Bitrix24Accounts/Infrastructure/Doctrine/Bitrix24AccountRepository.php @@ -11,6 +11,7 @@ use Bitrix24\SDK\Application\Contracts\Events\AggregateRootEventsEmitterInterface; use Bitrix24\SDK\Core\Exceptions\InvalidArgumentException; use Bitrix24\SDK\Lib\Bitrix24Accounts\Entity\Bitrix24Account; +use Bitrix24\SDK\Lib\Bitrix24Accounts\UseCase\Command\Flusher; use Doctrine\ORM\EntityManagerInterface; use Doctrine\ORM\EntityRepository; use Override; @@ -19,10 +20,12 @@ class Bitrix24AccountRepository extends EntityRepository implements Bitrix24AccountRepositoryInterface { public function __construct( - EntityManagerInterface $entityManager + EntityManagerInterface $entityManager, + Flusher $flusher ) { parent::__construct($entityManager, $entityManager->getClassMetadata(Bitrix24Account::class)); + $this->flusher = $flusher; } /** @@ -48,7 +51,9 @@ public function save(Bitrix24AccountInterface $bitrix24Account): void { $this->getEntityManager()->persist($bitrix24Account); //todo discuss add flush arg to contract or add flusher in usecases? - $this->getEntityManager()->flush(); + + // $this->getEntityManager()->flush(); + $this->flusher->flush(); } /** diff --git a/src/Bitrix24Accounts/UseCase/Command/Flusher.php b/src/Bitrix24Accounts/UseCase/Command/Flusher.php new file mode 100644 index 0000000..c832cb6 --- /dev/null +++ b/src/Bitrix24Accounts/UseCase/Command/Flusher.php @@ -0,0 +1,17 @@ +em->flush(); + } +} \ No newline at end of file From 04c6547d38be0c4bb3470c25572c2d42ef62e14b Mon Sep 17 00:00:00 2001 From: KarlsonComplete Date: Thu, 17 Oct 2024 00:01:45 +0300 Subject: [PATCH 2/4] =?UTF-8?q?-=20=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=B8?= =?UTF-8?q?=D0=BB=20=D0=B2=20=D1=82=D0=B5=D1=81=D1=82=D0=B0=D1=85=20=D0=BF?= =?UTF-8?q?=D1=80=D0=B8=20=D1=81=D0=BE=D0=B7=D0=B4=D0=B0=D0=BD=D0=B8=D0=B8?= =?UTF-8?q?=20=D1=8D=D0=BA=D0=B7=D0=B5=D0=BC=D0=BF=D0=BB=D1=8F=D1=80=D0=B0?= =?UTF-8?q?=20Bitrix24AccountRepository=20=D0=B2=D1=82=D0=BE=D1=80=D0=BE?= =?UTF-8?q?=D0=B9=20=D0=BF=D0=B0=D1=80=D0=B0=D0=BC=D0=B5=D1=82=D1=80=20Flu?= =?UTF-8?q?sher.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Doctrine/Bitrix24AccountRepository.php | 2 +- .../Doctrine/Bitrix24AccountRepositoryTest.php | 5 ++++- .../UseCase/RenewAuthToken/HandlerTest.php | 10 +++++++++- 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/src/Bitrix24Accounts/Infrastructure/Doctrine/Bitrix24AccountRepository.php b/src/Bitrix24Accounts/Infrastructure/Doctrine/Bitrix24AccountRepository.php index f11398e..08f7978 100644 --- a/src/Bitrix24Accounts/Infrastructure/Doctrine/Bitrix24AccountRepository.php +++ b/src/Bitrix24Accounts/Infrastructure/Doctrine/Bitrix24AccountRepository.php @@ -19,6 +19,7 @@ class Bitrix24AccountRepository extends EntityRepository implements Bitrix24AccountRepositoryInterface { + private Flusher $flusher; public function __construct( EntityManagerInterface $entityManager, Flusher $flusher @@ -51,7 +52,6 @@ public function save(Bitrix24AccountInterface $bitrix24Account): void { $this->getEntityManager()->persist($bitrix24Account); //todo discuss add flush arg to contract or add flusher in usecases? - // $this->getEntityManager()->flush(); $this->flusher->flush(); } diff --git a/tests/Functional/Bitrix24Accounts/Infrastructure/Doctrine/Bitrix24AccountRepositoryTest.php b/tests/Functional/Bitrix24Accounts/Infrastructure/Doctrine/Bitrix24AccountRepositoryTest.php index a4ff8d8..c80fdca 100644 --- a/tests/Functional/Bitrix24Accounts/Infrastructure/Doctrine/Bitrix24AccountRepositoryTest.php +++ b/tests/Functional/Bitrix24Accounts/Infrastructure/Doctrine/Bitrix24AccountRepositoryTest.php @@ -20,6 +20,7 @@ use Bitrix24\SDK\Core\Credentials\AuthToken; use Bitrix24\SDK\Core\Credentials\Scope; use Bitrix24\SDK\Lib\Bitrix24Accounts\Infrastructure\Doctrine\Bitrix24AccountRepository; +use Bitrix24\SDK\Lib\Bitrix24Accounts\UseCase\Command\Flusher; use Bitrix24\SDK\Lib\Tests\EntityManagerFactory; use Bitrix24\SDK\Tests\Application\Contracts\Bitrix24Accounts\Repository\Bitrix24AccountRepositoryInterfaceTest; use Carbon\CarbonImmutable; @@ -63,6 +64,8 @@ protected function createBitrix24AccountImplementation( #[Override] protected function createBitrix24AccountRepositoryImplementation(): Bitrix24AccountRepositoryInterface { - return new Bitrix24AccountRepository(EntityManagerFactory::get()); + $entityManager = EntityManagerFactory::get(); + $flusher = new Flusher($entityManager); + return new Bitrix24AccountRepository($entityManager,$flusher); } } \ No newline at end of file diff --git a/tests/Functional/Bitrix24Accounts/UseCase/RenewAuthToken/HandlerTest.php b/tests/Functional/Bitrix24Accounts/UseCase/RenewAuthToken/HandlerTest.php index d40a581..898e953 100644 --- a/tests/Functional/Bitrix24Accounts/UseCase/RenewAuthToken/HandlerTest.php +++ b/tests/Functional/Bitrix24Accounts/UseCase/RenewAuthToken/HandlerTest.php @@ -16,15 +16,20 @@ use Bitrix24\SDK\Application\ApplicationStatus; use Bitrix24\SDK\Application\Contracts\Bitrix24Accounts\Entity\Bitrix24AccountStatus; use Bitrix24\SDK\Application\Contracts\Bitrix24Accounts\Repository\Bitrix24AccountRepositoryInterface; +use Bitrix24\SDK\Core\Exceptions\WrongConfigurationException; use Bitrix24\SDK\Core\Response\DTO\RenewedAuthToken; use Bitrix24\SDK\Lib\Bitrix24Accounts\Entity\Bitrix24Account; use Bitrix24\SDK\Core\Credentials\AuthToken; use Bitrix24\SDK\Core\Credentials\Scope; use Bitrix24\SDK\Lib\Bitrix24Accounts\Infrastructure\Doctrine\Bitrix24AccountRepository; +use Bitrix24\SDK\Lib\Bitrix24Accounts\UseCase\Command\Flusher; use Bitrix24\SDK\Lib\Bitrix24Accounts\UseCase\RenewAuthToken\Command; use Bitrix24\SDK\Lib\Bitrix24Accounts\UseCase\RenewAuthToken\Handler; use Bitrix24\SDK\Lib\Tests\EntityManagerFactory; use Carbon\CarbonImmutable; +use Doctrine\DBAL\Exception; +use Doctrine\ORM\Exception\ORMException; +use Doctrine\ORM\OptimisticLockException; use Override; use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\Attributes\Test; @@ -77,10 +82,13 @@ public function testRenewAuthTokenWithoutBitrix24UserId(): void $this->assertEquals($newAuthToken->refreshToken, $updated->getAuthToken()->refreshToken); } + #[Override] protected function setUp(): void { - $this->repository = new Bitrix24AccountRepository(EntityManagerFactory::get()); + $entityManager = EntityManagerFactory::get(); + $flusher = new Flusher($entityManager); + $this->repository = new Bitrix24AccountRepository($entityManager,$flusher); $this->handler = new Handler( new EventDispatcher(), $this->repository, From 22baa6e646996f6a0c94aca9bf7356d43f5efad2 Mon Sep 17 00:00:00 2001 From: KarlsonComplete Date: Thu, 17 Oct 2024 00:36:21 +0300 Subject: [PATCH 3/4] =?UTF-8?q?-=20=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=B8?= =?UTF-8?q?=D0=BB=20=D0=BE=D1=82=D0=BE=D0=B1=D1=80=D0=B0=D0=B6=D0=B5=D0=BD?= =?UTF-8?q?=D0=B8=D1=8F=20=D1=81=D1=82=D1=80=D1=83=D0=BA=D1=82=D1=83=D1=80?= =?UTF-8?q?=D1=8B=20=D0=B1=D0=B4=20(=D0=B3=D0=B4=D0=B5=20=D1=8D=D1=82?= =?UTF-8?q?=D0=BE=20=D0=BE=D1=82=D0=BE=D0=B1=D1=80=D0=B0=D0=B6=D0=B0=D0=B5?= =?UTF-8?q?=D1=82=D1=81=D1=8F=3F)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/tests-functional.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/tests-functional.yml b/.github/workflows/tests-functional.yml index d34fb9d..47e1a0d 100644 --- a/.github/workflows/tests-functional.yml +++ b/.github/workflows/tests-functional.yml @@ -69,6 +69,7 @@ jobs: run: | php bin/doctrine orm:schema-tool:drop --force php bin/doctrine orm:schema-tool:create + php bin/doctrine orm:schema-tool:update --dump-sql php vendor/bin/phpunit --testsuite=functional_tests --display-warnings --testdox - name: "is functional tests succeeded" From a29c2e6a660b65cf4edae06a7652fe1c497282d1 Mon Sep 17 00:00:00 2001 From: KarlsonComplete Date: Sun, 20 Oct 2024 13:20:06 +0300 Subject: [PATCH 4/4] =?UTF-8?q?-=20=D0=A1=D0=BE=D0=B7=D0=B4=D0=B0=D0=BB=20?= =?UTF-8?q?xml=20=D1=84=D0=B0=D0=B9=D0=BB=20=D0=B4=D0=BB=D1=8F=20=D0=BC?= =?UTF-8?q?=D0=B0=D0=BF=D0=BF=D0=B8=D0=BD=D0=B3=D0=B0.=20-=20=D0=92=20Enti?= =?UTF-8?q?tyManagerFactory.php=20=D0=BF=D0=BE=D0=BC=D0=B5=D0=BD=D1=8F?= =?UTF-8?q?=D0=BB=20=D0=BD=D0=B0=20=D1=81=D0=BE=D0=B7=D0=B4=D0=B0=D0=BD?= =?UTF-8?q?=D0=B8=D0=B5=20=D1=87=D0=B5=D1=80=D0=B5=D0=B7=20xml=20-=20?= =?UTF-8?q?=D0=92=20Makefile=20=D0=B4=D0=BE=D0=B1=D0=B0=D0=B2=D0=B8=D0=BB?= =?UTF-8?q?=20=D0=BE=D1=82=D0=B4=D0=B5=D0=BB=D1=8C=D0=BD=D0=BE=D0=B5=20?= =?UTF-8?q?=D1=81=D0=BE=D0=B7=D0=B4=D0=B0=D0=BD=D0=B8=D0=B5=20=D0=B8=20?= =?UTF-8?q?=D1=83=D0=B4=D0=B0=D0=BB=D0=B5=D0=BD=D0=B8=D0=B5=20=D0=B1=D0=B4?= =?UTF-8?q?.=20-=20=D0=94=D0=BB=D1=8F=20=D1=82=D0=B5=D1=81=D1=82=D0=B8?= =?UTF-8?q?=D1=80=D0=BE=D0=B2=D0=B0=D0=BD=D0=B8=D1=8F=20=D0=B4=D0=BE=D0=B1?= =?UTF-8?q?=D0=B0=D0=B2=D0=B8=D0=BB=20=D1=82=D0=B5=D1=81=D1=82=D0=BE=D0=B2?= =?UTF-8?q?=D1=83=D1=8E=20=D1=81=D1=83=D1=89=D0=BD=D0=BE=D1=81=D1=82=D1=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Makefile | 8 +++- config/doctrine/xml/Bitrix24Account.dcm.xml | 42 ++++++++++++++++++ config/doctrine/xml/TestUser.dcm.xml | 13 ++++++ .../Entity/Bitrix24Account.php | 1 - src/Bitrix24Accounts/Entity/TestUser.php | 43 +++++++++++++++++++ tests/EntityManagerFactory.php | 8 +++- 6 files changed, 111 insertions(+), 4 deletions(-) create mode 100644 config/doctrine/xml/Bitrix24Account.dcm.xml create mode 100644 config/doctrine/xml/TestUser.dcm.xml create mode 100644 src/Bitrix24Accounts/Entity/TestUser.php diff --git a/Makefile b/Makefile index b794559..057164e 100644 --- a/Makefile +++ b/Makefile @@ -78,4 +78,10 @@ test-run-unit: test-run-functional: docker-compose run --rm php-cli php bin/doctrine orm:schema-tool:drop --force docker-compose run --rm php-cli php bin/doctrine orm:schema-tool:create - docker-compose run --rm php-cli php vendor/bin/phpunit --testsuite=functional_tests --display-warnings --testdox \ No newline at end of file + docker-compose run --rm php-cli php vendor/bin/phpunit --testsuite=functional_tests --display-warnings --testdox + +schema-drop: + docker-compose run --rm php-cli php bin/doctrine orm:schema-tool:drop --force + +schema-create: + docker-compose run --rm php-cli php bin/doctrine orm:schema-tool:create \ No newline at end of file diff --git a/config/doctrine/xml/Bitrix24Account.dcm.xml b/config/doctrine/xml/Bitrix24Account.dcm.xml new file mode 100644 index 0000000..41028c2 --- /dev/null +++ b/config/doctrine/xml/Bitrix24Account.dcm.xml @@ -0,0 +1,42 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/config/doctrine/xml/TestUser.dcm.xml b/config/doctrine/xml/TestUser.dcm.xml new file mode 100644 index 0000000..6e330dc --- /dev/null +++ b/config/doctrine/xml/TestUser.dcm.xml @@ -0,0 +1,13 @@ + + + + + + + + + + \ No newline at end of file diff --git a/src/Bitrix24Accounts/Entity/Bitrix24Account.php b/src/Bitrix24Accounts/Entity/Bitrix24Account.php index 772955c..31b9d24 100644 --- a/src/Bitrix24Accounts/Entity/Bitrix24Account.php +++ b/src/Bitrix24Accounts/Entity/Bitrix24Account.php @@ -74,7 +74,6 @@ public function __construct( private string $domainUrl, #[ORM\Column(name: 'account_status', type: 'string', nullable: false, enumType: Bitrix24AccountStatus::class)] private Bitrix24AccountStatus $accountStatus, - #[ORM\Embedded(class: AuthToken::class)] AuthToken $authToken, #[ORM\Column(name: 'created_at_utc', type: 'carbon_immutable', precision: 3, nullable: false)] #[Ignore] diff --git a/src/Bitrix24Accounts/Entity/TestUser.php b/src/Bitrix24Accounts/Entity/TestUser.php new file mode 100644 index 0000000..51a1543 --- /dev/null +++ b/src/Bitrix24Accounts/Entity/TestUser.php @@ -0,0 +1,43 @@ +login; + } + + public function setLogin(string $login): void + { + $this->login = $login; + } + + public function getPassword(): string + { + return $this->password; + } + + public function setPassword(string $password): void + { + $this->password = $password; + } + public function getId(): int + { + return $this->id; + } + + public function setId(int $id): void + { + $this->id = $id; + } + +} \ No newline at end of file diff --git a/tests/EntityManagerFactory.php b/tests/EntityManagerFactory.php index a04e483..e0de768 100644 --- a/tests/EntityManagerFactory.php +++ b/tests/EntityManagerFactory.php @@ -27,8 +27,11 @@ class EntityManagerFactory */ public static function get(): EntityManagerInterface { - $paths = [ + /*$paths = [ dirname(__DIR__) . '/src/Bitrix24Accounts/Entity' + ];*/ + $paths = [ + dirname(__DIR__) . '/config/doctrine/xml' ]; $isDevMode = true; @@ -63,7 +66,8 @@ public static function get(): EntityManagerInterface Type::addType('carbon_immutable', CarbonImmutableType::class); } - $configuration = ORMSetup::createAttributeMetadataConfiguration($paths, $isDevMode); + // $configuration = ORMSetup::createAttributeMetadataConfiguration($paths, $isDevMode); + $configuration = ORMSetup::createXMLMetadataConfiguration($paths, $isDevMode); $connection = DriverManager::getConnection($connectionParams, $configuration); $entityManager = new EntityManager($connection, $configuration); // todo разобраться, почему так, без этого объекты оставались в кеше и при find мы получали старые значения