Skip to content

Commit

Permalink
- Создал xml файл для маппинга.
Browse files Browse the repository at this point in the history
- В EntityManagerFactory.php поменял на создание через xml
- В Makefile добавил отдельное создание и удаление бд.
- Для тестирования добавил тестовую сущность
  • Loading branch information
KarlsonComplete committed Oct 20, 2024
1 parent 22baa6e commit a29c2e6
Show file tree
Hide file tree
Showing 6 changed files with 111 additions and 4 deletions.
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;
}

}
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

0 comments on commit a29c2e6

Please sign in to comment.