Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
chriskapp committed Oct 17, 2023
1 parent e59d5b5 commit 7711abf
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 18 deletions.
2 changes: 1 addition & 1 deletion src/Attribute/TableName.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class TableName
{
public function __construct(
public string $tableName,
public string $primaryColumn,
public ?string $primaryColumn = null,
) {
if (strlen($tableName) > 30) {
throw new \InvalidArgumentException('The table name must not be larger then 30 characters');
Expand Down
2 changes: 1 addition & 1 deletion src/Attribute/TablePrimary.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ class TablePrimary extends TableColumn
{
public function __construct(string $columnName)
{
parent::__construct($columnName, DataType::STR_TYPE_CHAR20);
parent::__construct($columnName, DataType::CHAR20);
}
}
16 changes: 8 additions & 8 deletions src/Converter.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,23 +16,23 @@ public function register(string $type, TypeConverterInterface $converter): void
$this->converters[$type] = $converter;
}

public function toPHPType(mixed $value, string $type): mixed
public function toPHPType(mixed $value, string|DataType $type): mixed
{
return match ($type) {
'string', DataType::STR_TYPE_CHAR10, DataType::STR_TYPE_CHAR20, DataType::STR_TYPE_CHAR100, DataType::STR_TYPE_CHAR254, DataType::STR_TYPE_CHAR500, DataType::STR_TYPE_TEXT, DataType::STR_TYPE_LONGTEXT, DataType::STR_TYPE_BIGINT => (string) $value,
DataType::STR_TYPE_INT => (int) $value,
'float', DataType::STR_TYPE_FLOAT => (float) $value,
'string', DataType::CHAR10, DataType::CHAR20, DataType::CHAR100, DataType::CHAR254, DataType::CHAR500, DataType::TEXT, DataType::LONGTEXT, DataType::BIGINT => (string) $value,
'int', DataType::INT => (int) $value,
'float', DataType::FLOAT => (float) $value,
'bool' => (bool) $value,
default => isset($this->converters[$type]) ? $this->converters[$type]->toPHPType($value) : null,
};
}

public function toDatabaseType(mixed $value, string $type): mixed
public function toDatabaseType(mixed $value, string|DataType $type): mixed
{
return match ($type) {
'string', DataType::STR_TYPE_CHAR10, DataType::STR_TYPE_CHAR20, DataType::STR_TYPE_CHAR100, DataType::STR_TYPE_CHAR254, DataType::STR_TYPE_CHAR500, DataType::STR_TYPE_TEXT, DataType::STR_TYPE_LONGTEXT, DataType::STR_TYPE_BIGINT => (string) $value,
DataType::STR_TYPE_INT => (int) $value,
'float', DataType::STR_TYPE_FLOAT => (float) $value,
'string', DataType::CHAR10, DataType::CHAR20, DataType::CHAR100, DataType::CHAR254, DataType::CHAR500, DataType::TEXT, DataType::LONGTEXT, DataType::BIGINT => (string) $value,
'int', DataType::INT => (int) $value,
'float', DataType::FLOAT => (float) $value,
'bool' => $value ? 1 : 0,
default => isset($this->converters[$type]) ? $this->converters[$type]->toDatabaseType($value) : null,
};
Expand Down
3 changes: 2 additions & 1 deletion src/EntityMeta.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Artemeon\Orm;

use Artemeon\Database\Schema\DataType;
use Artemeon\Orm\Attribute\OneToMany;
use Artemeon\Orm\Attribute\TableColumn;
use Artemeon\Orm\Attribute\TableName;
Expand Down Expand Up @@ -180,7 +181,7 @@ private function findOneToManyAttribute(\ReflectionProperty $property): ?OneToMa
return null;
}

private function getTypeForProperty(\ReflectionProperty $property, string $dataType): string
private function getTypeForProperty(\ReflectionProperty $property, DataType $dataType): string|DataType
{
$type = $this->getTypeHintForProperty($property);
if ($type !== null) {
Expand Down
4 changes: 2 additions & 2 deletions src/SchemaManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ private function getFieldsForEntity(string $entityClass, array &$keys, array &$r
[$type, $class, $setter, $getter, $relationTable, $sourceColumn, $targetColumn, $types] = $config;

$relationColumns = [
$sourceColumn => [DataType::STR_TYPE_CHAR20, false],
$targetColumn => [DataType::STR_TYPE_CHAR20, false],
$sourceColumn => [DataType::CHAR20, false],
$targetColumn => [DataType::CHAR20, false],
];

$primaryKeys = [$sourceColumn, $targetColumn];
Expand Down
8 changes: 4 additions & 4 deletions tests/FieldMapper/TestModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,16 @@ class TestModel extends TestParent
#[TablePrimary('contract_id')]
private string $contractId;

#[TableColumn('servicerid', DataType::STR_TYPE_CHAR20)]
#[TableColumn('servicerid', DataType::CHAR20)]
private $strServicerId;

#[TableColumn('inhouseservice', DataType::STR_TYPE_INT)]
#[TableColumn('inhouseservice', DataType::INT)]
private $intInhouseService;

#[TableColumn('outsourcing_i', DataType::STR_TYPE_CHAR20)]
#[TableColumn('outsourcing_i', DataType::CHAR20)]
private ?string $outsourcingInstitution = null;

#[TableColumn('purchasing_relevance', DataType::STR_TYPE_INT)]
#[TableColumn('purchasing_relevance', DataType::INT)]
private ?int $purchasingRelevance = 0;

#[OneToMany('agp_contracts_con2foo', 'contract_id', 'system_id', [TestParent::class])]
Expand Down
2 changes: 1 addition & 1 deletion tests/FieldMapper/TestParent.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class TestParent implements EntityInterface
#[TablePrimary('system_id')]
private ?string $systemId = null;

#[TableColumn('owner', DataType::STR_TYPE_CHAR20)]
#[TableColumn('owner', DataType::CHAR20)]
private ?string $owner = null;

public function getSystemId(): ?string
Expand Down

0 comments on commit 7711abf

Please sign in to comment.