diff --git a/src/Helpers/ColumnAssertions.php b/src/Helpers/ColumnAssertions.php index 7c68a01..e586d19 100644 --- a/src/Helpers/ColumnAssertions.php +++ b/src/Helpers/ColumnAssertions.php @@ -35,11 +35,16 @@ protected function assertDefaultOnColumn(string $table, string $column, ?string $this->assertSame($expected, $defaultValue); } - protected function assertTypeColumn(string $table, string $column, string $expected): void + protected function assertLaravelTypeColumn(string $table, string $column, string $expected): void { $this->assertSame($expected, Schema::getColumnType($table, $column)); } + protected function assertPostgresTypeColumn(string $table, string $column, string $expected): void + { + $this->assertSame($expected, $this->getTypeListing($table, $column)); + } + private function getCommentListing(string $table, string $column) { $definition = DB::selectOne( @@ -57,6 +62,20 @@ private function getCommentListing(string $table, string $column) return $definition ? $definition->description : null; } + private function getTypeListing(string $table, string $column): ?string + { + $definition = DB::selectOne( + ' + SELECT data_type + FROM information_schema.columns + WHERE table_name = ? AND column_name = ? + ', + [$table, $column] + ); + + return $definition ? $definition->data_type : null; + } + private function getDefaultListing(string $table, string $column) { $definition = DB::selectOne( diff --git a/tests/Functional/Schema/CreateTableTest.php b/tests/Functional/Schema/CreateTableTest.php index a02fa0c..af97d69 100644 --- a/tests/Functional/Schema/CreateTableTest.php +++ b/tests/Functional/Schema/CreateTableTest.php @@ -40,8 +40,9 @@ public function columnAssertions(): void $this->assertSameTable(['id', 'name', 'field_comment', 'field_default'], 'test_table'); - $this->assertTypeColumn('test_table', 'id', 'integer'); - $this->assertTypeColumn('test_table', 'name', 'string'); + $this->assertPostgresTypeColumn('test_table', 'id', 'integer'); + $this->assertLaravelTypeColumn('test_table', 'name', 'string'); + $this->assertPostgresTypeColumn('test_table', 'name', 'character varying'); $this->assertDefaultOnColumn('test_table', 'field_default', '123'); $this->assertCommentOnColumn('test_table', 'field_comment', 'test');