From f149625873f0ae90c7265cd5b6992c561fcf1017 Mon Sep 17 00:00:00 2001 From: Priyadi Iman Nurcahyo <1102197+priyadi@users.noreply.github.com> Date: Mon, 15 Jan 2024 11:34:57 +0700 Subject: [PATCH] test: Mapping test first version. --- CHANGELOG.md | 1 + tests/Common/AbstractIntegrationTest.php | 3 ++ tests/Common/MapperTestFactory.php | 6 ++++ tests/IntegrationTest/MappingTest.php | 38 ++++++++++++++++++++++++ 4 files changed, 48 insertions(+) create mode 100644 tests/IntegrationTest/MappingTest.php diff --git a/CHANGELOG.md b/CHANGELOG.md index ed74fb0d..2a11bd82 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ * dx(`SearchResult`): Now an `ArrayAccess`. * feat(`TryPropertyCommand`): Improve output. * dx(`TypeCheck`): Now accept `MixedType` as an argument. +* test: Mapping test first version. ## 0.5.10 diff --git a/tests/Common/AbstractIntegrationTest.php b/tests/Common/AbstractIntegrationTest.php index 7dd0868b..c6747b18 100644 --- a/tests/Common/AbstractIntegrationTest.php +++ b/tests/Common/AbstractIntegrationTest.php @@ -17,6 +17,7 @@ use Rekalogika\Mapper\MainTransformer\MainTransformerInterface; use Rekalogika\Mapper\MapperInterface; use Rekalogika\Mapper\Transformer\Contracts\TransformerInterface; +use Rekalogika\Mapper\TransformerRegistry\TransformerRegistryInterface; use Rekalogika\Mapper\TypeResolver\TypeResolverInterface; abstract class AbstractIntegrationTest extends TestCase @@ -25,6 +26,7 @@ abstract class AbstractIntegrationTest extends TestCase protected MapperInterface $mapper; protected MainTransformerInterface $mainTransformer; protected TypeResolverInterface $typeResolver; + protected TransformerRegistryInterface $transformerRegistry; public function setUp(): void { @@ -34,6 +36,7 @@ public function setUp(): void $this->mapper = $this->factory->getMapper(); $this->mainTransformer = $this->factory->getMainTransformer(); $this->typeResolver = $this->factory->getTypeResolver(); + $this->transformerRegistry = $this->factory->getTransformerRegistry(); } /** diff --git a/tests/Common/MapperTestFactory.php b/tests/Common/MapperTestFactory.php index d409e446..017c604a 100644 --- a/tests/Common/MapperTestFactory.php +++ b/tests/Common/MapperTestFactory.php @@ -16,6 +16,7 @@ use Rekalogika\Mapper\MainTransformer\MainTransformer; use Rekalogika\Mapper\MapperFactory\MapperFactory; use Rekalogika\Mapper\Mapping\MappingFactoryInterface; +use Rekalogika\Mapper\TransformerRegistry\TransformerRegistryInterface; use Rekalogika\Mapper\TypeResolver\TypeResolverInterface; class MapperTestFactory extends MapperFactory @@ -39,4 +40,9 @@ public function getMappingFactory(): MappingFactoryInterface { return parent::getMappingFactory(); } + + public function getTransformerRegistry(): TransformerRegistryInterface + { + return parent::getTransformerRegistry(); + } } diff --git a/tests/IntegrationTest/MappingTest.php b/tests/IntegrationTest/MappingTest.php new file mode 100644 index 00000000..c09ee667 --- /dev/null +++ b/tests/IntegrationTest/MappingTest.php @@ -0,0 +1,38 @@ + + * + * For the full copyright and license information, please view the LICENSE file + * that was distributed with this source code. + */ + +namespace Rekalogika\Mapper\Tests\IntegrationTest; + +use Rekalogika\Mapper\Tests\Common\AbstractIntegrationTest; +use Rekalogika\Mapper\Transformer\ScalarToScalarTransformer; +use Rekalogika\Mapper\Util\TypeFactory; + +class MappingTest extends AbstractIntegrationTest +{ + public function testScalar(): void + { + $searchResult = $this->transformerRegistry->findBySourceAndTargetTypes( + sourceTypes: [ + TypeFactory::int(), + ], + targetTypes: [ + TypeFactory::int(), + ], + ); + + $this->assertInstanceOf( + ScalarToScalarTransformer::class, + $searchResult[0]?->getTransformer() + ); + } +}