Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/DBD/Entity/Columns/CustomColumn.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ public function __construct(
string $primitiveType,
string $originType,
int $length = null,
int $precision = null,
bool $nullable = false,
bool $primary = false,
?string $defaultValue = null,
Expand All @@ -50,6 +51,7 @@ public function __construct(
Column::PRIMITIVE_TYPE => $primitiveType,
Column::ORIGIN_TYPE => $originType,
Column::MAXLENGTH => $length,
Column::PRECISION => $precision,
Column::NULLABLE => $nullable,
Column::KEY => $primary,
Column::DEFAULT => $defaultValue,
Expand Down
2 changes: 1 addition & 1 deletion src/DBD/Entity/Columns/JsonColumn.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ class JsonColumn extends Column
{
public function __construct(
string $name,
?string $annotation = null,
bool $nullable = true,
?string $annotation = null,
)
{
parent::__construct([
Expand Down
2 changes: 1 addition & 1 deletion src/DBD/Entity/Columns/JsonbColumn.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ class JsonbColumn extends Column
{
public function __construct(
string $name,
?string $annotation = null,
bool $nullable = true,
?string $annotation = null,
)
{
parent::__construct([
Expand Down
16 changes: 7 additions & 9 deletions src/DBD/Entity/Columns/NumericColumn.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,22 +36,20 @@ class NumericColumn extends Column
{
public function __construct(
string $name,
int $length,
int $precision,
?string $annotation = null,
int $length = null,
int $precision = null,
bool $nullable = true,
float $defaultValue = null,
bool $auto = false,
bool $primary = false
bool $primary = false,
string $defaultValue = null,
string $annotation = null
)
{
parent::__construct([
Column::NAME => $name,
Column::MAXLENGTH => $length,
Column::PRECISION => $precision,
Column::PRIMITIVE_TYPE => NumericPrimitives::Decimal,
Column::ORIGIN_TYPE => 'numeric',
Column::IS_AUTO => $auto,
Column::MAXLENGTH => $length,
Column::PRECISION => $precision,
Column::NULLABLE => $nullable,
Column::KEY => $primary,
Column::DEFAULT => $defaultValue,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
* @package DBD\Entity\Columns
*/
#[Attribute(Attribute::TARGET_PROPERTY)]
class TimeColumnTZ extends Column
class TimeTZColumn extends Column
{
public function __construct(
string $name,
Expand Down
4 changes: 2 additions & 2 deletions src/DBD/Entity/EntityTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/********************************************************************************
* Apache License, Version 2.0 *
* *
* Copyright [2024] [Nick Ispandiarov <[email protected]>] *
* Copyright [2024] [Nick Ispandiarov <[email protected]>] *
* *
* Licensed under the Apache License, Version 2.0 (the "License"); *
* you may not use this file except in compliance with the License. *
Expand Down Expand Up @@ -35,7 +35,7 @@ final class EntityTable
public function __construct(
public string $scheme,
public string $name,
public string $annotation
public string $annotation = ''
)
{
}
Expand Down
2 changes: 1 addition & 1 deletion src/DBD/Entity/Interfaces/EntityMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/********************************************************************************
* Apache License, Version 2.0 *
* *
* Copyright [2024] [Nick Ispandiarov <[email protected]>] *
* Copyright [2024] [Nick Ispandiarov <[email protected]>] *
* *
* Licensed under the Apache License, Version 2.0 (the "License"); *
* you may not use this file except in compliance with the License. *
Expand Down
4 changes: 3 additions & 1 deletion src/DBD/Entity/MapperAttributed.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/********************************************************************************
* Apache License, Version 2.0 *
* *
* Copyright [2024] [Nick Ispandiarov <[email protected]>] *
* Copyright [2024] [Nick Ispandiarov <[email protected]>] *
* *
* Licensed under the Apache License, Version 2.0 (the "License"); *
* you may not use this file except in compliance with the License. *
Expand All @@ -22,6 +22,7 @@

namespace DBD\Entity;

use AllowDynamicProperties;
use DBD\Entity\Common\EntityException;
use DBD\Entity\Interfaces\EntityMapper;
use ReflectionClass;
Expand All @@ -32,6 +33,7 @@
*
* @package DBD\Entity
*/
#[AllowDynamicProperties]
class MapperAttributed implements EntityMapper
{
use MapperTrait;
Expand Down
2 changes: 1 addition & 1 deletion src/DBD/Entity/Primitives/StringPrimitives.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ interface StringPrimitives
public const Stream = "Stream";

/** @var string 16-byte (128-bit) unique identifier */
public const Guid = "Guid";
public const Guid = "Guid";

/** @var string Binary data */
public const Binary = "Binary";
Expand Down
5 changes: 3 additions & 2 deletions tests/DBD/Entity/Tests/AttributedTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/********************************************************************************
* Apache License, Version 2.0 *
* *
* Copyright [2024] [Nick Ispandiarov <[email protected]>] *
* Copyright [2024] [Nick Ispandiarov <[email protected]>] *
* *
* Licensed under the Apache License, Version 2.0 (the "License"); *
* you may not use this file except in compliance with the License. *
Expand Down Expand Up @@ -55,7 +55,7 @@ public function testAttribute(): void

foreach ($columns as $column) {
self::assertInstanceOf(Column::class, $column);
self::assertSame($column->name, $column->annotation);
// self::assertSame($column->name, $column->annotation);
}

$table = $map->getTable();
Expand Down Expand Up @@ -83,6 +83,7 @@ public function testEmbedded(): void
$map->TimeColumn->name => date('Y-m-d H:i:s'),
$map->TimeStampColumn->name => ''.time(),
$map->TimeStampTZColumn->name => ''.time(),
$map->numericColumn->name => '0.00',
'two' => [
TwoEmbedded::map()->id->name => 2,
'three' => [
Expand Down
58 changes: 58 additions & 0 deletions tests/DBD/Entity/Tests/Columns/BigIntColumnTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<?php
/********************************************************************************
* Apache License, Version 2.0 *
* *
* Copyright [2024] [Nick Ispandiarov <[email protected]>] *
* *
* Licensed under the Apache License, Version 2.0 (the "License"); *
* you may not use this file except in compliance with the License. *
* You may obtain a copy of the License at *
* *
* http://www.apache.org/licenses/LICENSE-2.0 *
* *
* Unless required by applicable law or agreed to in writing, software *
* distributed under the License is distributed on an "AS IS" BASIS, *
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. *
* See the License for the specific language governing permissions and *
* limitations under the License. *
* *
********************************************************************************/

declare(strict_types=1);

namespace DBD\Entity\Tests\Columns;

use DBD\Entity\Columns\BigIntColumn;
use DBD\Entity\Entity;
use DBD\Entity\EntityTable;
use DBD\Entity\Interfaces\FullEntity;
use PHPUnit\Framework\TestCase;

class BigIntColumnTest extends TestCase
{
/**
* @return void
*/
public function testInEntity(): void
{
$data = [
'test_id' => 1000000
];

$entity = new #[EntityTable('public', 'test')] class($data) extends Entity implements FullEntity {
const SCHEME = 'public';
const TABLE = 'test';

#[BigIntColumn(
name: 'test_id',
auto: true,
nullable: false,
primary: true,
annotation: 'Test id'
)]
public int $id;
};

self::assertSame($data['test_id'], $entity->id);
}
}
56 changes: 56 additions & 0 deletions tests/DBD/Entity/Tests/Columns/BooleanColumnTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<?php
/********************************************************************************
* Apache License, Version 2.0 *
* *
* Copyright [2024] [Nick Ispandiarov <[email protected]>] *
* *
* Licensed under the Apache License, Version 2.0 (the "License"); *
* you may not use this file except in compliance with the License. *
* You may obtain a copy of the License at *
* *
* http://www.apache.org/licenses/LICENSE-2.0 *
* *
* Unless required by applicable law or agreed to in writing, software *
* distributed under the License is distributed on an "AS IS" BASIS, *
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. *
* See the License for the specific language governing permissions and *
* limitations under the License. *
* *
********************************************************************************/

declare(strict_types=1);

namespace DBD\Entity\Tests\Columns;

use DBD\Entity\Columns\BooleanColumn;
use DBD\Entity\Entity;
use DBD\Entity\EntityTable;
use DBD\Entity\Interfaces\FullEntity;
use PHPUnit\Framework\TestCase;

class BooleanColumnTest extends TestCase
{
/**
* @return void
*/
public function testInEntity(): void
{
$data = [
'test_value' => true
];

$entity = new #[EntityTable('public', 'test')] class($data) extends Entity implements FullEntity {
const SCHEME = 'public';
const TABLE = 'test';

#[BooleanColumn(
name: 'test_value',
nullable: true,
annotation: 'Test numeric'
)]
public ?bool $value;
};

self::assertSame($data['test_value'], $entity->value);
}
}
60 changes: 60 additions & 0 deletions tests/DBD/Entity/Tests/Columns/CustomColumnTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<?php
/********************************************************************************
* Apache License, Version 2.0 *
* *
* Copyright [2024] [Nick Ispandiarov <[email protected]>] *
* *
* Licensed under the Apache License, Version 2.0 (the "License"); *
* you may not use this file except in compliance with the License. *
* You may obtain a copy of the License at *
* *
* http://www.apache.org/licenses/LICENSE-2.0 *
* *
* Unless required by applicable law or agreed to in writing, software *
* distributed under the License is distributed on an "AS IS" BASIS, *
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. *
* See the License for the specific language governing permissions and *
* limitations under the License. *
* *
********************************************************************************/

declare(strict_types=1);

namespace DBD\Entity\Tests\Columns;

use DBD\Entity\Columns\CustomColumn;
use DBD\Entity\Entity;
use DBD\Entity\EntityTable;
use DBD\Entity\Interfaces\FullEntity;
use DBD\Entity\Primitive;
use PHPUnit\Framework\TestCase;

class CustomColumnTest extends TestCase
{
/**
* @return void
*/
public function testInEntity(): void
{
$data = [
'test_value' => 12.101
];

$entity = new #[EntityTable('public', 'test')] class($data) extends Entity implements FullEntity {
const SCHEME = 'public';
const TABLE = 'test';

#[CustomColumn(
name: 'test_value',
primitiveType: Primitive::Single,
originType: 'float4',
length: 10,
precision: 2,
annotation: 'Test id'
)]
public ?float $value;
};

self::assertSame($data['test_value'], $entity->value);
}
}
56 changes: 56 additions & 0 deletions tests/DBD/Entity/Tests/Columns/DateColumnTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<?php
/********************************************************************************
* Apache License, Version 2.0 *
* *
* Copyright [2024] [Nick Ispandiarov <[email protected]>] *
* *
* Licensed under the Apache License, Version 2.0 (the "License"); *
* you may not use this file except in compliance with the License. *
* You may obtain a copy of the License at *
* *
* http://www.apache.org/licenses/LICENSE-2.0 *
* *
* Unless required by applicable law or agreed to in writing, software *
* distributed under the License is distributed on an "AS IS" BASIS, *
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. *
* See the License for the specific language governing permissions and *
* limitations under the License. *
* *
********************************************************************************/

declare(strict_types=1);

namespace DBD\Entity\Tests\Columns;

use DBD\Entity\Columns\DateColumn;
use DBD\Entity\Entity;
use DBD\Entity\EntityTable;
use DBD\Entity\Interfaces\FullEntity;
use PHPUnit\Framework\TestCase;

class DateColumnTest extends TestCase
{
/**
* @return void
*/
public function testInEntity(): void
{
$data = [
'test_value' => '1999-12-31'
];

$entity = new #[EntityTable('public', 'test')] class($data) extends Entity implements FullEntity {
const SCHEME = 'public';
const TABLE = 'test';

#[DateColumn(
name: 'test_value',
nullable: true,
annotation: 'Test date'
)]
public ?string $value;
};

self::assertSame($data['test_value'], $entity->value);
}
}
Loading