2021-11-28 17:43:02 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
2021-12-29 00:09:34 +01:00
|
|
|
namespace CuyZ\Valinor\Tests\Integration\Mapping\Object;
|
2021-11-28 17:43:02 +01:00
|
|
|
|
|
|
|
use CuyZ\Valinor\Mapper\MappingError;
|
|
|
|
use CuyZ\Valinor\Tests\Integration\IntegrationTest;
|
|
|
|
use CuyZ\Valinor\Tests\Integration\Mapping\Fixture\SimpleObject;
|
|
|
|
|
|
|
|
final class ObjectValuesMappingTest extends IntegrationTest
|
|
|
|
{
|
|
|
|
public function test_values_are_mapped_properly(): void
|
|
|
|
{
|
|
|
|
$source = [
|
|
|
|
'object' => [
|
|
|
|
'value' => 'foo',
|
|
|
|
],
|
|
|
|
];
|
|
|
|
|
|
|
|
foreach ([ObjectValues::class, ObjectValuesWithConstructor::class] as $class) {
|
|
|
|
try {
|
|
|
|
$result = $this->mapperBuilder->mapper()->map($class, $source);
|
|
|
|
} catch (MappingError $error) {
|
|
|
|
$this->mappingFail($error);
|
|
|
|
}
|
|
|
|
|
|
|
|
self::assertSame('foo', $result->object->value);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class ObjectValues
|
|
|
|
{
|
|
|
|
public SimpleObject $object;
|
|
|
|
}
|
|
|
|
|
|
|
|
class ObjectValuesWithConstructor extends ObjectValues
|
|
|
|
{
|
|
|
|
public function __construct(SimpleObject $object)
|
|
|
|
{
|
|
|
|
$this->object = $object;
|
|
|
|
}
|
|
|
|
}
|