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"
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/src/Bitrix24Accounts/Infrastructure/Doctrine/Bitrix24AccountRepository.php b/src/Bitrix24Accounts/Infrastructure/Doctrine/Bitrix24AccountRepository.php
index fe5f33e..08f7978 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;
@@ -18,11 +19,14 @@
class Bitrix24AccountRepository extends EntityRepository implements Bitrix24AccountRepositoryInterface
{
+ private Flusher $flusher;
public function __construct(
- EntityManagerInterface $entityManager
+ EntityManagerInterface $entityManager,
+ Flusher $flusher
)
{
parent::__construct($entityManager, $entityManager->getClassMetadata(Bitrix24Account::class));
+ $this->flusher = $flusher;
}
/**
@@ -48,7 +52,8 @@ 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
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 мы получали старые значения
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,