diff --git a/src/Column/ColumnBuilder.php b/src/Column/ColumnBuilder.php new file mode 100644 index 00000000..d974744d --- /dev/null +++ b/src/Column/ColumnBuilder.php @@ -0,0 +1,15 @@ +queryBuilder === null) { diff --git a/src/Schema.php b/src/Schema.php index 836f43e6..618843c1 100644 --- a/src/Schema.php +++ b/src/Schema.php @@ -15,9 +15,7 @@ use Yiisoft\Db\Exception\NotSupportedException; use Yiisoft\Db\Expression\Expression; use Yiisoft\Db\Helper\DbArrayHelper; -use Yiisoft\Db\Mysql\Column\ColumnFactory; use Yiisoft\Db\Schema\Builder\ColumnInterface; -use Yiisoft\Db\Schema\Column\ColumnFactoryInterface; use Yiisoft\Db\Schema\Column\ColumnSchemaInterface; use Yiisoft\Db\Schema\TableSchemaInterface; @@ -83,11 +81,6 @@ public function createColumn(string $type, array|int|string $length = null): Col return new Column($type, $length); } - public function getColumnFactory(): ColumnFactoryInterface - { - return new ColumnFactory(); - } - /** * Returns all unique indexes for the given table. * @@ -418,9 +411,11 @@ protected function getCreateTableSql(TableSchemaInterface $table): string */ private function loadColumnSchema(array $info): ColumnSchemaInterface { + $columnFactory = $this->db->getColumnBuilderClass()::columnFactory(); + $dbType = $info['type']; /** @psalm-var ColumnInfoArray $info */ - $column = $this->getColumnFactory()->fromDefinition($dbType); + $column = $columnFactory->fromDefinition($dbType); $column->name($info['field']); $column->allowNull($info['null'] === 'YES'); $column->primaryKey(str_contains($info['key'], 'PRI')); diff --git a/tests/ColumnBuilderTest.php b/tests/ColumnBuilderTest.php new file mode 100644 index 00000000..23aa3b80 --- /dev/null +++ b/tests/ColumnBuilderTest.php @@ -0,0 +1,23 @@ +getConnection(); + $columnBuilderClass = $db->getColumnBuilderClass(); + + $this->assertInstanceOf(ColumnFactory::class, $columnBuilderClass::columnFactory()); + } +} diff --git a/tests/ColumnFactoryTest.php b/tests/ColumnFactoryTest.php index bfe58602..195346aa 100644 --- a/tests/ColumnFactoryTest.php +++ b/tests/ColumnFactoryTest.php @@ -21,9 +21,23 @@ public function testFromDbType(string $dbType, string $expectedType, string $exp } /** @dataProvider \Yiisoft\Db\Mysql\Tests\Provider\ColumnFactoryProvider::definitions */ - public function testFromDefinition(string $definition, string $expectedType, string $expectedInstanceOf, array $expectedInfo = []): void - { - parent::testFromDefinition($definition, $expectedType, $expectedInstanceOf, $expectedInfo); + public function testFromDefinition( + string $definition, + string $expectedType, + string $expectedInstanceOf, + array $expectedMethodResults = [] + ): void { + parent::testFromDefinition($definition, $expectedType, $expectedInstanceOf, $expectedMethodResults); + } + + /** @dataProvider \Yiisoft\Db\Mysql\Tests\Provider\ColumnFactoryProvider::pseudoTypes */ + public function testFromPseudoType( + string $pseudoType, + string $expectedType, + string $expectedInstanceOf, + array $expectedMethodResults = [] + ): void { + parent::testFromPseudoType($pseudoType, $expectedType, $expectedInstanceOf, $expectedMethodResults); } /** @dataProvider \Yiisoft\Db\Mysql\Tests\Provider\ColumnFactoryProvider::types */ diff --git a/tests/ConnectionTest.php b/tests/ConnectionTest.php index e8baa4ac..cc6ad10e 100644 --- a/tests/ConnectionTest.php +++ b/tests/ConnectionTest.php @@ -11,6 +11,7 @@ use Yiisoft\Db\Exception\IntegrityException; use Yiisoft\Db\Exception\InvalidConfigException; use Yiisoft\Db\Exception\NotSupportedException; +use Yiisoft\Db\Mysql\Column\ColumnBuilder; use Yiisoft\Db\Mysql\Tests\Support\TestTrait; use Yiisoft\Db\Tests\Common\CommonConnectionTest; use Yiisoft\Db\Transaction\TransactionInterface; @@ -156,4 +157,11 @@ public function testNotRestartConnectionOnTimeoutInTransaction(): void $db->createCommand('SELECT 1')->queryScalar(); } + + public function testGetColumnBuilderClass(): void + { + $db = $this->getConnection(); + + $this->assertSame(ColumnBuilder::class, $db->getColumnBuilderClass()); + } } diff --git a/tests/Provider/ColumnFactoryProvider.php b/tests/Provider/ColumnFactoryProvider.php index e76d2136..fe2b1bfa 100644 --- a/tests/Provider/ColumnFactoryProvider.php +++ b/tests/Provider/ColumnFactoryProvider.php @@ -55,7 +55,7 @@ public static function definitions(): array { $definitions = parent::definitions(); - $definitions[] = ['bit(1)', ColumnType::BOOLEAN, BooleanColumnSchema::class, ['getSize' => 1]]; + $definitions[] = ['bit(1)', ColumnType::BOOLEAN, BooleanColumnSchema::class, ['getDbType' => 'bit', 'getSize' => 1]]; return $definitions; } diff --git a/tests/SchemaTest.php b/tests/SchemaTest.php index d459ba46..7757d109 100644 --- a/tests/SchemaTest.php +++ b/tests/SchemaTest.php @@ -17,7 +17,6 @@ use Yiisoft\Db\Exception\NotSupportedException; use Yiisoft\Db\Expression\Expression; use Yiisoft\Db\Mysql\Column; -use Yiisoft\Db\Mysql\Column\ColumnFactory; use Yiisoft\Db\Mysql\Schema; use Yiisoft\Db\Mysql\Tests\Support\TestTrait; use Yiisoft\Db\Query\Query; @@ -566,12 +565,4 @@ public function testInsertDefaultValues() 'numeric_col' => '-33.22', ], $row); } - - public function testGetColumnFactory(): void - { - $db = $this->getConnection(); - $factory = $db->getSchema()->getColumnFactory(); - - $this->assertInstanceOf(ColumnFactory::class, $factory); - } }