Skip to content

Commit 563ae0b

Browse files
committed
Added more tests for the object mapper + renamed functions
1 parent 77123b3 commit 563ae0b

File tree

3 files changed

+62
-2
lines changed

3 files changed

+62
-2
lines changed

tests/functional/Builder/ArrayMapperTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ final class ArrayMapperTest extends BuilderTestCase
1616
{
1717
use TransformerBuilderAssertTrait;
1818

19-
public function testWithOneConditionThatMatch()
19+
public function testWithASingleCopyField()
2020
{
2121
$builder = new \Kiboko\Plugin\FastMap\Builder\ArrayMapper(
2222
$mapper = new ArrayBuilder()
@@ -42,7 +42,7 @@ public function testWithOneConditionThatMatch()
4242
);
4343
}
4444

45-
public function testWithSeveralConditionsThatMatch()
45+
public function testWithSameNumberOfOutputFields()
4646
{
4747
$builder = new \Kiboko\Plugin\FastMap\Builder\ArrayMapper(
4848
$mapper = new ArrayBuilder()
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace functional\Kiboko\Plugin\FastMap\Builder\DTO;
6+
7+
class Product
8+
{
9+
public function __construct(
10+
public int $id,
11+
public ?bool $enabled = false,
12+
) {
13+
}
14+
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace functional\Kiboko\Plugin\FastMap\Builder;
6+
7+
use functional\Kiboko\Plugin\FastMap\Builder\DTO\Product;
8+
use Kiboko\Component\FastMapConfig\ObjectBuilder;
9+
use Kiboko\Component\PHPUnitExtension\Assert\TransformerBuilderAssertTrait;
10+
use Kiboko\Plugin\FastMap\Builder\Transformer;
11+
12+
final class ObjectMapperTest extends BuilderTestCase
13+
{
14+
use TransformerBuilderAssertTrait;
15+
16+
public function testObjectMapper()
17+
{
18+
$builder = new \Kiboko\Plugin\FastMap\Builder\ObjectMapper(
19+
$mapper = new ObjectBuilder(Product::class)
20+
);
21+
22+
$mapper->arguments('input.id', 'input.enabled');
23+
24+
$builder = new Transformer($builder);
25+
26+
$this->assertBuildsTransformerTransformsLike(
27+
[
28+
new Product(1)
29+
],
30+
[
31+
new Product(1)
32+
],
33+
$builder,
34+
);
35+
36+
$this->assertBuildsTransformerTransformsLike(
37+
[
38+
new Product(1, true)
39+
],
40+
[
41+
new Product(1, true)
42+
],
43+
$builder,
44+
);
45+
}
46+
}

0 commit comments

Comments
 (0)