You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
74 lines
2.3 KiB
PHP
74 lines
2.3 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Kartierung\Sql;
|
|
|
|
use Kartierung\Analyze\EntityField;
|
|
use Kartierung\Analyze\EntityResult;
|
|
use Kartierung\Analyze\FieldAccess;
|
|
use PHPUnit\Framework\TestCase;
|
|
|
|
class DateToEntityMapperTest extends TestCase
|
|
{
|
|
public function testMapsSetter(): void
|
|
{
|
|
// Given
|
|
$mapper = new DataToEntityMapper(
|
|
entityResult: new EntityResult(
|
|
classFqcn: EntityWithThreeAccessMethods::class,
|
|
tableName: '',
|
|
fields: [
|
|
new EntityField(
|
|
name: 'witherVal',
|
|
fqcn: 'int',
|
|
columnName: 'witherVal',
|
|
isIdField: false,
|
|
writeAccess: FieldAccess::WITHER,
|
|
readAccess: FieldAccess::WITHER
|
|
),
|
|
new EntityField(
|
|
name: 'publicVal',
|
|
fqcn: 'int',
|
|
columnName: 'publicVal',
|
|
isIdField: false,
|
|
writeAccess: FieldAccess::PUBLIC,
|
|
readAccess: FieldAccess::PUBLIC
|
|
),
|
|
new EntityField(
|
|
name: 'setterVal',
|
|
fqcn: 'int',
|
|
columnName: 'setterVal',
|
|
isIdField: false,
|
|
writeAccess: FieldAccess::GETSET,
|
|
readAccess: FieldAccess::GETSET
|
|
)
|
|
],
|
|
idField: new EntityField(
|
|
name: '',
|
|
fqcn: '',
|
|
columnName: '',
|
|
isIdField: false,
|
|
writeAccess: FieldAccess::GETSET,
|
|
readAccess: FieldAccess::GETSET
|
|
)
|
|
)
|
|
);
|
|
|
|
$row = [
|
|
'witherVal' => 1,
|
|
'publicVal' => 2,
|
|
'setterVal' => 3
|
|
];
|
|
|
|
// When
|
|
$entity = $mapper->toEntity($row);
|
|
|
|
// Then
|
|
$this->assertInstanceOf(EntityWithThreeAccessMethods::class, $entity);
|
|
$this->assertEquals(1, $entity->getWitherVal());
|
|
$this->assertEquals(2, $entity->publicVal);
|
|
$this->assertEquals(3, $entity->getSetterVal());
|
|
}
|
|
}
|