Browse Source

Add test for default function value in postgres

Ensure that default values using functions don't have corrupted default
value expressions.
Mark Story 7 years ago
parent
commit
ba1ddb3f36
1 changed files with 34 additions and 0 deletions
  1. 34 0
      tests/TestCase/Database/Schema/PostgresSchemaTest.php

+ 34 - 0
tests/TestCase/Database/Schema/PostgresSchemaTest.php

@@ -638,6 +638,40 @@ SQL;
     }
 
     /**
+     * Test describing a table with postgres function defaults
+     *
+     * @return void
+     */
+    public function testDescribeTableFunctionDefaultValue()
+    {
+        $this->_needsConnection();
+        $connection = ConnectionManager::get('test');
+        $sql = <<<SQL
+CREATE TABLE schema_function_defaults (
+    "id" SERIAL,
+    year INT DEFAULT DATE_PART('year'::text, NOW()),
+    PRIMARY KEY("id")
+);
+SQL;
+        $connection->execute($sql);
+        $schema = new SchemaCollection($connection);
+        $result = $schema->describe('schema_function_defaults');
+        $connection->execute('DROP TABLE schema_function_defaults');
+
+        $expected = [
+            'type' => 'integer',
+            'default' => "date_part('year'::text, now())",
+            'null' => true,
+            'precision' => null,
+            'length' => 10,
+            'comment' => null,
+            'unsigned' => null,
+            'autoIncrement' => null,
+        ];
+        $this->assertEquals($expected, $result->getColumn('year'));
+    }
+
+    /**
      * Column provider for creating column sql
      *
      * @return array