Skip to content

Commit

Permalink
Merge pull request #21 from rekalogika:test/array-cast-to-object
Browse files Browse the repository at this point in the history
test: test array cast to object mapping
  • Loading branch information
priyadi committed Feb 20, 2024
2 parents 483abd6 + 7d137a8 commit 60b8f35
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
* fix: Typo in `RemoveOptionalDefinitionPass`
* feat: Supports dynamic properties (including `stdClass`) on the target side.
* fix(`Mapper`): Fix typehint.
* test: test array cast to object mapping

## 1.0.0

Expand Down
18 changes: 18 additions & 0 deletions tests/IntegrationTest/DynamicPropertyTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,24 @@ public function testObjectExtendingStdClassToObject(): void
$this->assertSame(1.1, $target->d);
}

public function testArrayCastToObjectToObject(): void
{
$source = [
'a' => 1,
'b' => 'string',
'c' => true,
'd' => 1.1,
];

$target = $this->mapper->map((object) $source, ObjectWithScalarPropertiesDto::class);

$this->assertInstanceOf(ObjectWithScalarPropertiesDto::class, $target);
$this->assertSame(1, $target->a);
$this->assertSame('string', $target->b);
$this->assertTrue($target->c);
$this->assertSame(1.1, $target->d);
}

public function testStdClassWithoutPropertiesToObject(): void
{
$source = new \stdClass();
Expand Down

0 comments on commit 60b8f35

Please sign in to comment.