Skip to content

Commit

Permalink
Improve
Browse files Browse the repository at this point in the history
  • Loading branch information
Tigrov committed Oct 7, 2024
1 parent c8910c6 commit 3bc2831
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/Schema/Column/AbstractColumnFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,8 @@ protected function isType(string $type): bool
ColumnType::TIMESTAMP,
ColumnType::DATE,
ColumnType::TIME,
ColumnType::ARRAY,
ColumnType::STRUCTURED,
ColumnType::JSON => true,
default => false,
};
Expand Down
3 changes: 3 additions & 0 deletions src/Schema/Column/ColumnSchemaInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,13 @@
* @psalm-type ColumnInfo = array{
* auto_increment?: bool|string,
* check?: string|null,
* column?: ColumnSchemaInterface|null,
* columns?: array<string, ColumnSchemaInterface>,
* comment?: string|null,
* computed?: bool|string,
* db_type?: string|null,
* default_value?: mixed,
* dimension?: int|string,
* enum_values?: array|null,
* extra?: string|null,
* primary_key?: bool|string,
Expand Down
10 changes: 10 additions & 0 deletions tests/AbstractColumnFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ public function testFromDbType(string $dbType, string $expectedType, string $exp
$this->assertInstanceOf($expectedInstanceOf, $column);
$this->assertSame($expectedType, $column->getType());
$this->assertSame($dbType, $column->getDbType());

$db->close();
}

/**
Expand Down Expand Up @@ -51,6 +53,8 @@ public function testFromDefinition(
foreach ($columnMethodResults as $method => $result) {
$this->assertSame($result, $column->$method());
}

$db->close();
}

/** @dataProvider \Yiisoft\Db\Tests\Provider\ColumnFactoryProvider::pseudoTypes */
Expand All @@ -76,6 +80,8 @@ public function testFromPseudoType(
foreach ($columnMethodResults as $method => $result) {
$this->assertEquals($result, $column->$method());
}

$db->close();
}

/** @dataProvider \Yiisoft\Db\Tests\Provider\ColumnFactoryProvider::types */
Expand All @@ -88,6 +94,8 @@ public function testFromType(string $type, string $expectedType, string $expecte

$this->assertInstanceOf($expectedInstanceOf, $column);
$this->assertSame($expectedType, $column->getType());

$db->close();
}

public function testFromDefinitionWithExtra(): void
Expand All @@ -101,5 +109,7 @@ public function testFromDefinitionWithExtra(): void
$this->assertSame('char', $column->getType());
$this->assertSame(1, $column->getSize());
$this->assertSame('NOT NULL UNIQUE', $column->getExtra());

$db->close();
}
}
2 changes: 2 additions & 0 deletions tests/Provider/ColumnFactoryProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
use Yiisoft\Db\Schema\Column\IntegerColumnSchema;
use Yiisoft\Db\Schema\Column\JsonColumnSchema;
use Yiisoft\Db\Schema\Column\StringColumnSchema;
use Yiisoft\Db\Schema\Column\StructuredColumnSchema;

class ColumnFactoryProvider
{
Expand Down Expand Up @@ -64,6 +65,7 @@ public static function types(): array
'timestamp' => [ColumnType::TIMESTAMP, ColumnType::TIMESTAMP, StringColumnSchema::class],
'time' => [ColumnType::TIME, ColumnType::TIME, StringColumnSchema::class],
'date' => [ColumnType::DATE, ColumnType::DATE, StringColumnSchema::class],
'structured' => [ColumnType::STRUCTURED, ColumnType::STRUCTURED, StructuredColumnSchema::class],
'json' => [ColumnType::JSON, ColumnType::JSON, JsonColumnSchema::class],
];
}
Expand Down

0 comments on commit 3bc2831

Please sign in to comment.