Skip to content

Commit

Permalink
test: Mapping test first version.
Browse files Browse the repository at this point in the history
  • Loading branch information
priyadi committed Jan 15, 2024
1 parent 07797cd commit f149625
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
3 changes: 3 additions & 0 deletions tests/Common/AbstractIntegrationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
{
Expand All @@ -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();
}

/**
Expand Down
6 changes: 6 additions & 0 deletions tests/Common/MapperTestFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -39,4 +40,9 @@ public function getMappingFactory(): MappingFactoryInterface
{
return parent::getMappingFactory();
}

public function getTransformerRegistry(): TransformerRegistryInterface
{
return parent::getTransformerRegistry();
}
}
38 changes: 38 additions & 0 deletions tests/IntegrationTest/MappingTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php

declare(strict_types=1);

/*
* This file is part of rekalogika/mapper package.
*
* (c) Priyadi Iman Nurcahyo <https://rekalogika.dev>
*
* 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()
);
}
}

0 comments on commit f149625

Please sign in to comment.