From 8163dbed8eb9b186e93869c6bf191c6ec1d25e48 Mon Sep 17 00:00:00 2001 From: Robert Perry Date: Thu, 31 Aug 2023 15:04:15 -0400 Subject: [PATCH] Modify getColumns to only read numeric_precision for columns of type PHINX_TYPE_DECIMAL Added testAddStringWithLimit to PostgresAdapterTest to assure that limits are being properly set. Updated ManagerTest->testMigrationWithCustomColumnTypes to no longer expect pgsql to return null for limit of custom columns. --- src/Phinx/Db/Adapter/PostgresAdapter.php | 8 +------- .../Phinx/Db/Adapter/PostgresAdapterTest.php | 19 +++++++++++++++++++ tests/Phinx/Migration/ManagerTest.php | 14 ++------------ 3 files changed, 22 insertions(+), 19 deletions(-) diff --git a/src/Phinx/Db/Adapter/PostgresAdapter.php b/src/Phinx/Db/Adapter/PostgresAdapter.php index 4cea33842..75757deaf 100644 --- a/src/Phinx/Db/Adapter/PostgresAdapter.php +++ b/src/Phinx/Db/Adapter/PostgresAdapter.php @@ -474,13 +474,7 @@ public function getColumns(string $tableName): array if (in_array($columnType, [static::PHINX_TYPE_TIME, static::PHINX_TYPE_DATETIME], true)) { $column->setPrecision($columnInfo['datetime_precision']); - } elseif ( - !in_array($columnType, [ - self::PHINX_TYPE_SMALL_INTEGER, - self::PHINX_TYPE_INTEGER, - self::PHINX_TYPE_BIG_INTEGER, - ], true) - ) { + } elseif ($columnType === self::PHINX_TYPE_DECIMAL) { $column->setPrecision($columnInfo['numeric_precision']); } $columns[] = $column; diff --git a/tests/Phinx/Db/Adapter/PostgresAdapterTest.php b/tests/Phinx/Db/Adapter/PostgresAdapterTest.php index 6599d4e98..3dd977fd2 100644 --- a/tests/Phinx/Db/Adapter/PostgresAdapterTest.php +++ b/tests/Phinx/Db/Adapter/PostgresAdapterTest.php @@ -758,6 +758,25 @@ public function testAddColumnWithComment() ); } + public function testAddStringWithLimit() + { + $table = new \Phinx\Db\Table('table1', [], $this->adapter); + $table->save(); + $table->addColumn('string1', 'string', ['limit' => 10]) + ->addColumn('char1', 'char', ['limit' => 20]) + ->save(); + $columns = $this->adapter->getColumns('table1'); + foreach ($columns as $column) { + if ($column->getName() === 'string1') { + $this->assertEquals('10', $column->getLimit()); + } + + if ($column->getName() === 'char1') { + $this->assertEquals('20', $column->getLimit()); + } + } + } + public function testAddDecimalWithPrecisionAndScale() { $table = new \Phinx\Db\Table('table1', [], $this->adapter); diff --git a/tests/Phinx/Migration/ManagerTest.php b/tests/Phinx/Migration/ManagerTest.php index 1464369fd..f5b280d6b 100644 --- a/tests/Phinx/Migration/ManagerTest.php +++ b/tests/Phinx/Migration/ManagerTest.php @@ -6147,26 +6147,16 @@ public function testMigrationWithCustomColumnTypes() $this->assertArrayHasKey(3, $columns); $this->assertArrayHasKey(4, $columns); - $limit = 15; - if ($adapter->getAdapterType() === 'pgsql') { - $limit = null; - } - $column = $columns[3]; $this->assertSame('phone_number', $column->getName()); $this->assertSame('string', $column->getType()); - $this->assertSame($limit, $column->getLimit()); + $this->assertSame(15, $column->getLimit()); $this->assertTrue($column->getNull()); - $limit = 30; - if ($adapter->getAdapterType() === 'pgsql') { - $limit = null; - } - $column = $columns[4]; $this->assertSame('phone_number_ext', $column->getName()); $this->assertSame('string', $column->getType()); - $this->assertSame($limit, $column->getLimit()); + $this->assertSame(30, $column->getLimit()); $this->assertFalse($column->getNull()); } }