Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/tests-functional.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
8 changes: 7 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
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
42 changes: 42 additions & 0 deletions config/doctrine/xml/Bitrix24Account.dcm.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<doctrine-mapping xmlns="http://doctrine-project.org/schemas/orm/doctrine-mapping"
xmlns:xsi="https://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://doctrine-project.org/schemas/orm/doctrine-mapping
https://www.doctrine-project.org/schemas/orm/doctrine-mapping.xsd">
<entity name="Bitrix24\SDK\Lib\Bitrix24Accounts\Entity\Bitrix24Account" table="bitrix24account">
<id name="id" type="uuid" column="id">
<generator strategy="UUID"/>
</id>

<field name="bitrix24UserId" type="integer" column="b24_user_id" nullable="false"/>
<field name="isBitrix24UserAdmin" type="boolean" column="is_b24_user_admin" nullable="false"/>

<field name="memberId" type="string" column="member_id" nullable="false"/>

<field name="domainUrl" type="string" column="domain_url" nullable="false"/>

<field name="accountStatus" type="string" column="account_status" nullable="false" enumType="Bitrix24\SDK\Application\Contracts\Bitrix24Accounts\Entity\Bitrix24AccountStatus"/>

<embedded name="authToken" class="Bitrix24\SDK\Core\Credentials\AuthToken"/>

<field name="createdAt" type="datetime_immutable" column="created_at_utc" precision="3" nullable="false"/>

<field name="updatedAt" type="datetime_immutable" column="update_at_utc" precision="3" nullable="false"/>

<field name="applicationVersion" type="integer" column="application_version" nullable="false"/>

<!-- Вложенный объект Scope -->
<embedded name="applicationScope" class="Bitrix24\SDK\Core\Credentials\Scope"/>
</entity>

<embeddable name="Bitrix24\SDK\Core\Credentials\AuthToken">
<field name="accessToken" type="string" column="access_token"/>
<field name="refreshToken" type="string" column="refresh_token"/>
<field name="expires" type="integer" column="expires"/>
<field name="expiresIn" type="integer" column="expires_in"/>
</embeddable>

<embeddable name="Bitrix24\SDK\Core\Credentials\Scope">
<field name="availableScope" type="array" column="available_scope"/>
<field name="currentScope" type="array" column="current_scope"/>
</embeddable>
</doctrine-mapping>
13 changes: 13 additions & 0 deletions config/doctrine/xml/TestUser.dcm.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<doctrine-mapping xmlns="http://doctrine-project.org/schemas/orm/doctrine-mapping"
xmlns:xsi="https://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://doctrine-project.org/schemas/orm/doctrine-mapping
https://www.doctrine-project.org/schemas/orm/doctrine-mapping.xsd">
<entity name="Bitrix24\SDK\Lib\Bitrix24Accounts\Entity\TestUser" table="test_user">
<id name="id" type="id" column="id">
<generator strategy="AUTO"/>
</id>

<field name="login" type="string" nullable="false"/>
<field name="password" type="string" nullable="false"/>
</entity>
</doctrine-mapping>
1 change: 0 additions & 1 deletion src/Bitrix24Accounts/Entity/Bitrix24Account.php
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
43 changes: 43 additions & 0 deletions src/Bitrix24Accounts/Entity/TestUser.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php
declare(strict_types=1);

namespace Bitrix24\SDK\Lib\Bitrix24Accounts\Entity;

class TestUser
{
private int $id;

private string $login;

private string $password;

public function getLogin(): string
{
return $this->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;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,22 @@
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;
use Symfony\Component\Uid\Uuid;

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;
}

/**
Expand All @@ -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();
}

/**
Expand Down
17 changes: 17 additions & 0 deletions src/Bitrix24Accounts/UseCase/Command/Flusher.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

declare(strict_types=1);

namespace Bitrix24\SDK\Lib\Bitrix24Accounts\UseCase\Command;

use Doctrine\ORM\EntityManagerInterface;

final readonly class Flusher
{
public function __construct(private EntityManagerInterface $em) {}

public function flush(): void
{
$this->em->flush();
}
}
8 changes: 6 additions & 2 deletions tests/EntityManagerFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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 мы получали старые значения
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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,
Expand Down
Loading