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.
62 lines
1.8 KiB
PHP
62 lines
1.8 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Kartierung\Sql;
|
|
|
|
use Kartierung\Analyze\Result\EntityField;
|
|
use Kartierung\Analyze\Result\EntityResult;
|
|
use Kartierung\Analyze\Result\FieldAccess;
|
|
use Kartierung\Analyze\Result\Type\PrimitiveType;
|
|
use PHPUnit\Framework\TestCase;
|
|
|
|
class DataToEntityMapperTest extends TestCase
|
|
{
|
|
public function testMapsWithDifferentMethods(): void
|
|
{
|
|
// Given
|
|
$mapper = new DataToEntityMapper(
|
|
entityResult: new EntityResult(
|
|
classFqcn: EntityWithAllReadMechanics::class,
|
|
tableName: '',
|
|
fields: [
|
|
new EntityField(
|
|
name: 'publicVal',
|
|
type: PrimitiveType::INTEGER,
|
|
columnName: 'public_val',
|
|
isIdField: false,
|
|
readAccess: FieldAccess::PUBLIC
|
|
),
|
|
new EntityField(
|
|
name: 'setterVal',
|
|
type: PrimitiveType::INTEGER,
|
|
columnName: 'setter_val',
|
|
isIdField: false,
|
|
readAccess: FieldAccess::GETTER
|
|
)
|
|
],
|
|
idField: new EntityField(
|
|
name: '',
|
|
type: PrimitiveType::INTEGER,
|
|
columnName: '',
|
|
isIdField: false,
|
|
readAccess: FieldAccess::GETTER
|
|
)
|
|
)
|
|
);
|
|
|
|
$row = [
|
|
'public_val' => 2,
|
|
'setter_val' => 3
|
|
];
|
|
|
|
// When
|
|
$entity = $mapper->toEntity($row);
|
|
|
|
// Then
|
|
$this->assertInstanceOf(EntityWithAllReadMechanics::class, $entity);
|
|
$this->assertEquals(2, $entity->publicVal);
|
|
$this->assertEquals(3, $entity->getSetterVal());
|
|
}
|
|
}
|