Skip to content

Commit

Permalink
minor #187 Add missing ODM extensions test + XSD types (ogizanagi)
Browse files Browse the repository at this point in the history
This PR was merged into the 2.x-dev branch.

Discussion
----------

Add missing ODM extensions test + XSD types

Commits
-------

11f0a04 Add missing ODM extensions test + XSD types
  • Loading branch information
ogizanagi committed May 3, 2022
2 parents d6edf71 + 11f0a04 commit e6735d6
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 0 deletions.
20 changes: 20 additions & 0 deletions src/Bridge/Symfony/Bundle/config/schema/elao_enum.xsd
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
<xsd:complexType name="config">
<xsd:choice maxOccurs="unbounded">
<xsd:element name="doctrine" type="doctrine" minOccurs="0" maxOccurs="1"/>
<xsd:element name="doctrine_mongodb" type="doctrine_mongodb" minOccurs="0" maxOccurs="1"/>
</xsd:choice>
</xsd:complexType>

Expand All @@ -34,4 +35,23 @@
</xsd:simpleType>
</xsd:attribute>
</xsd:complexType>

<xsd:complexType name="doctrine_mongodb">
<xsd:sequence>
<xsd:element name="type" type="doctrine_mongodb_type" minOccurs="0" maxOccurs="unbounded"/>
</xsd:sequence>
</xsd:complexType>

<xsd:complexType name="doctrine_mongodb_type">
<xsd:attribute name="class" type="xsd:string" use="required"/>
<xsd:attribute name="type">
<xsd:simpleType>
<xsd:restriction base="xsd:string">
<xsd:enumeration value="single"/>
<xsd:enumeration value="collection"/>
</xsd:restriction>
</xsd:simpleType>
</xsd:attribute>
<xsd:attribute name="name" type="xsd:string" use="required"/>
</xsd:complexType>
</xsd:schema>
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?xml version="1.0" ?>

<container xmlns="http://symfony.com/schema/dic/services"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:elao-enum="http://elao.com/schema/dic/elao_enum"
xsi:schemaLocation="http://elao.com/schema/dic/elao_enum http://elao.com/schema/dic/elao_enum/elao_enum.xsd">

<elao-enum:config>
<elao-enum:doctrine_mongodb>
<elao-enum:type class="Elao\Enum\Tests\Fixtures\Enum\Suit" name="suit" />
<elao-enum:type class="Elao\Enum\Tests\Fixtures\Enum\RequestStatus" name="request_status" type="single" />
<elao-enum:type class="Elao\Enum\Tests\Fixtures\Enum\Permissions" name="permissions" type="collection" />
</elao-enum:doctrine_mongodb>
</elao-enum:config>
</container>
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
elao_enum:
doctrine_mongodb:
types:
suit: Elao\Enum\Tests\Fixtures\Enum\Suit
request_status: { class: Elao\Enum\Tests\Fixtures\Enum\RequestStatus, type: single }
permissions: { class: Elao\Enum\Tests\Fixtures\Enum\Permissions, type: collection }
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
namespace Elao\Enum\Tests\Unit\Bridge\Symfony\Bundle\DependencyInjection;

use Doctrine\Bundle\DoctrineBundle\DoctrineBundle;
use Doctrine\Bundle\MongoDBBundle\DoctrineMongoDBBundle;
use Elao\Enum\Bridge\Symfony\Bundle\DependencyInjection\ElaoEnumExtension;
use Elao\Enum\Tests\Fixtures\Enum\Permissions;
use Elao\Enum\Tests\Fixtures\Enum\RequestStatus;
Expand Down Expand Up @@ -78,6 +79,24 @@ public function testDoctrineTypesArePrepended(): void
], $container->getExtensionConfig('doctrine'));
}

public function testDoctrineOdmTypesArePrepended(): void
{
$container = $this->createContainerFromFile('doctrine_mongodb_types', false);
/** @var ElaoEnumExtension $ext */
$ext = $container->getExtension('elao_enum');
$ext->prepend($container);

self::assertEquals([
[
'types' => [
'suit' => 'ELAO_ENUM_DT_ODM\\Elao\\Enum\\Tests\\Fixtures\\Enum\\SuitType',
'request_status' => 'ELAO_ENUM_DT_ODM\\Elao\\Enum\\Tests\\Fixtures\\Enum\\RequestStatusType',
'permissions' => 'ELAO_ENUM_DT_ODM\\Elao\\Enum\\Tests\\Fixtures\\Enum\\PermissionsCollectionType',
],
],
], $container->getExtensionConfig('doctrine_mongodb'));
}

protected function createContainerFromFile(string $file, bool $compile = true): ContainerBuilder
{
$container = $this->createContainer();
Expand All @@ -102,6 +121,7 @@ protected function createContainer(): ContainerBuilder
return new ContainerBuilder(new EnvPlaceholderParameterBag([
'kernel.bundles' => [
'DoctrineBundle' => DoctrineBundle::class,
'DoctrineMongoDBBundle' => DoctrineMongoDBBundle::class,
],
'kernel.cache_dir' => self::FIXTURES_PATH . '/cache_dir',
]));
Expand Down

0 comments on commit e6735d6

Please sign in to comment.