Skip to content

Commit a18f422

Browse files
authored
chore(mapper): add test for nested value objects (#935)
1 parent d72dd17 commit a18f422

File tree

3 files changed

+36
-2
lines changed

3 files changed

+36
-2
lines changed
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?php
2+
3+
namespace Tests\Tempest\Integration\Mapper\Fixtures;
4+
5+
final readonly class Name
6+
{
7+
public function __construct(
8+
public string $first,
9+
public string $last,
10+
) {}
11+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?php
2+
3+
namespace Tests\Tempest\Integration\Mapper\Fixtures;
4+
5+
final readonly class Person
6+
{
7+
public function __construct(
8+
public Name $name,
9+
) {}
10+
}

tests/Integration/Mapper/MapperTest.php

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
namespace Tests\Tempest\Integration\Mapper;
66

77
use Tempest\Mapper\Exceptions\MissingValuesException;
8-
use Tempest\Mapper\MapTo;
98
use Tempest\Validation\Exceptions\ValidationException;
109
use Tests\Tempest\Fixtures\Modules\Books\Models\Author;
1110
use Tests\Tempest\Fixtures\Modules\Books\Models\Book;
@@ -16,12 +15,12 @@
1615
use Tests\Tempest\Integration\Mapper\Fixtures\ObjectWithFloatProp;
1716
use Tests\Tempest\Integration\Mapper\Fixtures\ObjectWithIntProp;
1817
use Tests\Tempest\Integration\Mapper\Fixtures\ObjectWithMapFromAttribute;
19-
use Tests\Tempest\Integration\Mapper\Fixtures\ObjectWithMappedVariousPropertyScope;
2018
use Tests\Tempest\Integration\Mapper\Fixtures\ObjectWithMapToAttribute;
2119
use Tests\Tempest\Integration\Mapper\Fixtures\ObjectWithMapToCollisions;
2220
use Tests\Tempest\Integration\Mapper\Fixtures\ObjectWithMapToCollisionsJsonSerializable;
2321
use Tests\Tempest\Integration\Mapper\Fixtures\ObjectWithStrictOnClass;
2422
use Tests\Tempest\Integration\Mapper\Fixtures\ObjectWithStrictProperty;
23+
use Tests\Tempest\Integration\Mapper\Fixtures\Person;
2524
use function Tempest\make;
2625
use function Tempest\map;
2726

@@ -225,4 +224,18 @@ public function test_map_to_handle_name_collisions_with_json_serializable(): voi
225224
'full_name' => 'my name',
226225
], $array);
227226
}
227+
public function test_nested_value_object_mapping(): void
228+
{
229+
$data = [
230+
'name' => [
231+
'first' => 'Brent',
232+
'last' => 'Roose',
233+
]
234+
];
235+
236+
$person = map($data)->to(Person::class);
237+
238+
$this->assertSame('Brent', $person->name->first);
239+
$this->assertSame('Roose', $person->name->last);
240+
}
228241
}

0 commit comments

Comments
 (0)