Skip to content

Commit

Permalink
Added more tests for the object mapper + renamed functions
Browse files Browse the repository at this point in the history
  • Loading branch information
sebprt committed Jan 12, 2024
1 parent 77123b3 commit 563ae0b
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 2 deletions.
4 changes: 2 additions & 2 deletions tests/functional/Builder/ArrayMapperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ final class ArrayMapperTest extends BuilderTestCase
{
use TransformerBuilderAssertTrait;

public function testWithOneConditionThatMatch()
public function testWithASingleCopyField()
{
$builder = new \Kiboko\Plugin\FastMap\Builder\ArrayMapper(
$mapper = new ArrayBuilder()
Expand All @@ -42,7 +42,7 @@ public function testWithOneConditionThatMatch()
);
}

public function testWithSeveralConditionsThatMatch()
public function testWithSameNumberOfOutputFields()
{
$builder = new \Kiboko\Plugin\FastMap\Builder\ArrayMapper(
$mapper = new ArrayBuilder()
Expand Down
14 changes: 14 additions & 0 deletions tests/functional/Builder/DTO/Product.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

declare(strict_types=1);

namespace functional\Kiboko\Plugin\FastMap\Builder\DTO;

class Product
{
public function __construct(
public int $id,
public ?bool $enabled = false,
) {
}
}
46 changes: 46 additions & 0 deletions tests/functional/Builder/ObjectMapperTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?php

declare(strict_types=1);

namespace functional\Kiboko\Plugin\FastMap\Builder;

use functional\Kiboko\Plugin\FastMap\Builder\DTO\Product;
use Kiboko\Component\FastMapConfig\ObjectBuilder;
use Kiboko\Component\PHPUnitExtension\Assert\TransformerBuilderAssertTrait;
use Kiboko\Plugin\FastMap\Builder\Transformer;

final class ObjectMapperTest extends BuilderTestCase
{
use TransformerBuilderAssertTrait;

public function testObjectMapper()
{
$builder = new \Kiboko\Plugin\FastMap\Builder\ObjectMapper(
$mapper = new ObjectBuilder(Product::class)
);

$mapper->arguments('input.id', 'input.enabled');

$builder = new Transformer($builder);

$this->assertBuildsTransformerTransformsLike(
[
new Product(1)
],
[
new Product(1)
],
$builder,
);

$this->assertBuildsTransformerTransformsLike(
[
new Product(1, true)
],
[
new Product(1, true)
],
$builder,
);
}
}

0 comments on commit 563ae0b

Please sign in to comment.