diff --git a/CHANGELOG.md b/CHANGELOG.md index 69152211..cc3a3236 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ - Enh #315: Raise minimum PHP version to `^8.1` with minor refactoring (@Tigrov) - Enh #314: Implement `ColumnFactory` class (@Tigrov) - Enh #317: Separate column type constants (@Tigrov) +- Enh #318: Realize `ColumnBuilder` class (@Tigrov) ## 1.2.0 March 21, 2024 diff --git a/src/Column/ColumnBuilder.php b/src/Column/ColumnBuilder.php index 11dbfc34..b0476207 100644 --- a/src/Column/ColumnBuilder.php +++ b/src/Column/ColumnBuilder.php @@ -4,12 +4,6 @@ namespace Yiisoft\Db\Sqlite\Column; -use Yiisoft\Db\Schema\Column\ColumnFactoryInterface; - final class ColumnBuilder extends \Yiisoft\Db\Schema\Column\ColumnBuilder { - public static function columnFactory(): ColumnFactoryInterface - { - return new ColumnFactory(); - } } diff --git a/src/Connection.php b/src/Connection.php index 888fa498..c1308d87 100644 --- a/src/Connection.php +++ b/src/Connection.php @@ -7,10 +7,11 @@ use Yiisoft\Db\Driver\Pdo\AbstractPdoConnection; use Yiisoft\Db\Driver\Pdo\PdoCommandInterface; use Yiisoft\Db\QueryBuilder\QueryBuilderInterface; +use Yiisoft\Db\Schema\Column\ColumnFactoryInterface; use Yiisoft\Db\Schema\Quoter; use Yiisoft\Db\Schema\QuoterInterface; use Yiisoft\Db\Schema\SchemaInterface; -use Yiisoft\Db\Sqlite\Column\ColumnBuilder; +use Yiisoft\Db\Sqlite\Column\ColumnFactory; use Yiisoft\Db\Transaction\TransactionInterface; use function str_starts_with; @@ -71,9 +72,9 @@ public function getQueryBuilder(): QueryBuilderInterface return $this->queryBuilder; } - public function getColumnBuilderClass(): string + public function getColumnFactory(): ColumnFactoryInterface { - return ColumnBuilder::class; + return new ColumnFactory(); } public function getQuoter(): QuoterInterface diff --git a/src/Schema.php b/src/Schema.php index 9766b39f..67752a2a 100644 --- a/src/Schema.php +++ b/src/Schema.php @@ -438,7 +438,7 @@ public function getSchemaDefaultValues(string $schema = '', bool $refresh = fals */ private function loadColumnSchema(array $info): ColumnSchemaInterface { - $columnFactory = $this->db->getColumnBuilderClass()::columnFactory(); + $columnFactory = $this->db->getColumnFactory(); $dbType = strtolower($info['type']); $column = $columnFactory->fromDefinition($dbType, ['name' => $info['name']]); diff --git a/tests/ColumnBuilderTest.php b/tests/ColumnBuilderTest.php index 6ded372b..61f45283 100644 --- a/tests/ColumnBuilderTest.php +++ b/tests/ColumnBuilderTest.php @@ -2,7 +2,9 @@ declare(strict_types=1); -use Yiisoft\Db\Sqlite\Column\ColumnFactory; +namespace Yiisoft\Db\Sqlite\Tests; + +use Yiisoft\Db\Sqlite\Column\ColumnBuilder; use Yiisoft\Db\Sqlite\Tests\Support\TestTrait; use Yiisoft\Db\Tests\AbstractColumnBuilderTest; @@ -13,11 +15,8 @@ class ColumnBuilderTest extends AbstractColumnBuilderTest { use TestTrait; - public function testColumnFactory(): void + public function getColumnBuilderClass(): string { - $db = $this->getConnection(); - $columnBuilderClass = $db->getColumnBuilderClass(); - - $this->assertInstanceOf(ColumnFactory::class, $columnBuilderClass::columnFactory()); + return ColumnBuilder::class; } } diff --git a/tests/ConnectionTest.php b/tests/ConnectionTest.php index 2695f8c3..83371fc2 100644 --- a/tests/ConnectionTest.php +++ b/tests/ConnectionTest.php @@ -14,7 +14,7 @@ use Yiisoft\Db\Exception\InvalidConfigException; use Yiisoft\Db\Exception\NotSupportedException; use Yiisoft\Db\Profiler\ProfilerInterface; -use Yiisoft\Db\Sqlite\Column\ColumnBuilder; +use Yiisoft\Db\Sqlite\Column\ColumnFactory; use Yiisoft\Db\Sqlite\Tests\Support\TestTrait; use Yiisoft\Db\Tests\Common\CommonConnectionTest; use Yiisoft\Db\Transaction\TransactionInterface; @@ -182,11 +182,11 @@ private function runExceptionTest(ConnectionInterface $db): void $this->assertTrue($thrown, 'An exception should have been thrown by the command.'); } - public function testGetColumnBuilderClass(): void + public function testGetColumnFactory(): void { $db = $this->getConnection(); - $this->assertSame(ColumnBuilder::class, $db->getColumnBuilderClass()); + $this->assertInstanceOf(ColumnFactory::class, $db->getColumnFactory()); } private function createProfiler(): ProfilerInterface