diff --git a/framework/db/cubrid/Schema.php b/framework/db/cubrid/Schema.php index 3ab34099bdb..e0f2a223bbc 100644 --- a/framework/db/cubrid/Schema.php +++ b/framework/db/cubrid/Schema.php @@ -7,6 +7,7 @@ namespace yii\db\cubrid; +use yii\base\NotSupportedException; use yii\db\Constraint; use yii\db\ConstraintFinderTrait; use yii\db\Expression; @@ -210,18 +211,20 @@ protected function loadTableUniques($tableName) /** * @inheritDoc + * @throws NotSupportedException if this method is called. */ protected function loadTableChecks($tableName) { - return []; + throw new NotSupportedException('CUBRID does not support check constraints.'); } /** * @inheritDoc + * @throws NotSupportedException if this method is called. */ protected function loadTableDefaultValues($tableName) { - return []; + throw new NotSupportedException('CUBRID does not support default value constraints.'); } /** diff --git a/framework/db/mysql/Schema.php b/framework/db/mysql/Schema.php index 6327c175353..0f26dd9e6b6 100644 --- a/framework/db/mysql/Schema.php +++ b/framework/db/mysql/Schema.php @@ -8,6 +8,7 @@ namespace yii\db\mysql; use yii\base\InvalidConfigException; +use yii\base\NotSupportedException; use yii\db\ColumnSchema; use yii\db\Constraint; use yii\db\ConstraintFinderTrait; @@ -177,18 +178,20 @@ protected function loadTableUniques($tableName) /** * @inheritDoc + * @throws NotSupportedException if this method is called. */ protected function loadTableChecks($tableName) { - return []; + throw new NotSupportedException('MySQL does not support check constraints.'); } /** * @inheritDoc + * @throws NotSupportedException if this method is called. */ protected function loadTableDefaultValues($tableName) { - return []; + throw new NotSupportedException('MySQL does not support default value constraints.'); } /** diff --git a/framework/db/oci/Schema.php b/framework/db/oci/Schema.php index 6676fcb1466..2c94dc4be2e 100644 --- a/framework/db/oci/Schema.php +++ b/framework/db/oci/Schema.php @@ -8,6 +8,7 @@ namespace yii\db\oci; use yii\base\InvalidCallException; +use yii\base\NotSupportedException; use yii\db\CheckConstraint; use yii\db\ColumnSchema; use yii\db\Connection; @@ -220,10 +221,11 @@ protected function loadTableChecks($tableName) /** * @inheritDoc + * @throws NotSupportedException if this method is called. */ protected function loadTableDefaultValues($tableName) { - return []; + throw new NotSupportedException('Oracle does not support default value constraints.'); } /** diff --git a/framework/db/pgsql/Schema.php b/framework/db/pgsql/Schema.php index 4f07260ed15..1eba40a1b80 100644 --- a/framework/db/pgsql/Schema.php +++ b/framework/db/pgsql/Schema.php @@ -7,6 +7,7 @@ namespace yii\db\pgsql; +use yii\base\NotSupportedException; use yii\db\CheckConstraint; use yii\db\Constraint; use yii\db\ConstraintFinderTrait; @@ -260,10 +261,11 @@ protected function loadTableChecks($tableName) /** * @inheritDoc + * @throws NotSupportedException if this method is called. */ protected function loadTableDefaultValues($tableName) { - return []; + throw new NotSupportedException('PostgreSQL does not support default value constraints.'); } /** diff --git a/framework/db/sqlite/Schema.php b/framework/db/sqlite/Schema.php index c5e4d609a7e..028200cb0f6 100644 --- a/framework/db/sqlite/Schema.php +++ b/framework/db/sqlite/Schema.php @@ -174,10 +174,11 @@ protected function loadTableChecks($tableName) /** * @inheritDoc + * @throws NotSupportedException if this method is called. */ protected function loadTableDefaultValues($tableName) { - return []; + throw new NotSupportedException('SQLite does not support default value constraints.'); } /** @@ -362,7 +363,7 @@ protected function loadColumnSchema($info) * Sets the isolation level of the current transaction. * @param string $level The transaction isolation level to use for this transaction. * This can be either [[Transaction::READ_UNCOMMITTED]] or [[Transaction::SERIALIZABLE]]. - * @throws \yii\base\NotSupportedException when unsupported isolation levels are used. + * @throws NotSupportedException when unsupported isolation levels are used. * SQLite only supports SERIALIZABLE and READ UNCOMMITTED. * @see http://www.sqlite.org/pragma.html#pragma_read_uncommitted */ diff --git a/tests/framework/db/SchemaTest.php b/tests/framework/db/SchemaTest.php index bd4000dfc2d..fc8eab1c4c5 100644 --- a/tests/framework/db/SchemaTest.php +++ b/tests/framework/db/SchemaTest.php @@ -485,7 +485,7 @@ public function constraintsProvider() 'isUnique' => true, ]), ]], - '1: default' => ['T_constraints_1', 'defaultValues', []], + '1: default' => ['T_constraints_1', 'defaultValues', false], '2: primary key' => ['T_constraints_2', 'primaryKey', new Constraint([ 'name' => 'CN_pk', @@ -518,7 +518,7 @@ public function constraintsProvider() ]), ]], '2: check' => ['T_constraints_2', 'checks', []], - '2: default' => ['T_constraints_2', 'defaultValues', []], + '2: default' => ['T_constraints_2', 'defaultValues', false], '3: primary key' => ['T_constraints_3', 'primaryKey', null], '3: foreign key' => ['T_constraints_3', 'foreignKeys', [ @@ -541,7 +541,7 @@ public function constraintsProvider() ]), ]], '3: check' => ['T_constraints_3', 'checks', []], - '3: default' => ['T_constraints_3', 'defaultValues', []], + '3: default' => ['T_constraints_3', 'defaultValues', false], '4: primary key' => ['T_constraints_4', 'primaryKey', new Constraint([ 'name' => AnyValue::getInstance(), @@ -554,7 +554,7 @@ public function constraintsProvider() ]), ]], '4: check' => ['T_constraints_4', 'checks', []], - '4: default' => ['T_constraints_4', 'defaultValues', []], + '4: default' => ['T_constraints_4', 'defaultValues', false], ]; } @@ -573,6 +573,10 @@ public function uppercaseConstraintsProvider() */ public function testTableSchemaConstraints($tableName, $type, $expected) { + if ($expected === false) { + $this->expectException('yii\base\NotSupportedException'); + } + $constraints = $this->getConnection(false)->getSchema()->{'getTable' . ucfirst($type)}($tableName); $this->assertMetadataEquals($expected, $constraints); } @@ -582,6 +586,10 @@ public function testTableSchemaConstraints($tableName, $type, $expected) */ public function testTableSchemaConstraintsWithPdoUppercase($tableName, $type, $expected) { + if ($expected === false) { + $this->expectException('yii\base\NotSupportedException'); + } + $connection = $this->getConnection(false); $connection->getSlavePdo()->setAttribute(PDO::ATTR_CASE, PDO::CASE_UPPER); $constraints = $connection->getSchema()->{'getTable' . ucfirst($type)}($tableName, true); @@ -593,6 +601,10 @@ public function testTableSchemaConstraintsWithPdoUppercase($tableName, $type, $e */ public function testTableSchemaConstraintsWithPdoLowercase($tableName, $type, $expected) { + if ($expected === false) { + $this->expectException('yii\base\NotSupportedException'); + } + $connection = $this->getConnection(false); $connection->getSlavePdo()->setAttribute(PDO::ATTR_CASE, PDO::CASE_LOWER); $constraints = $connection->getSchema()->{'getTable' . ucfirst($type)}($tableName, true); diff --git a/tests/framework/db/cubrid/SchemaTest.php b/tests/framework/db/cubrid/SchemaTest.php index c7d273fc177..82e33b5be84 100644 --- a/tests/framework/db/cubrid/SchemaTest.php +++ b/tests/framework/db/cubrid/SchemaTest.php @@ -82,14 +82,18 @@ public function constraintsProvider() foreach ($result as $name => $constraints) { $result[$name][2] = $this->convertPropertiesToAnycase($constraints[2]); } - $result['1: check'][2] = []; + $result['1: check'][2] = false; unset($result['1: index'][2][0]); + $result['2: check'][2] = false; unset($result['2: index'][2][0]); $result['3: foreign key'][2][0]->onDelete = 'RESTRICT'; $result['3: foreign key'][2][0]->onUpdate = 'RESTRICT'; $result['3: index'][2] = []; + $result['3: check'][2] = false; + + $result['4: check'][2] = false; return $result; } diff --git a/tests/framework/db/mssql/SchemaTest.php b/tests/framework/db/mssql/SchemaTest.php index 6ad1723a344..c84d2b28229 100644 --- a/tests/framework/db/mssql/SchemaTest.php +++ b/tests/framework/db/mssql/SchemaTest.php @@ -22,14 +22,20 @@ public function constraintsProvider() { $result = parent::constraintsProvider(); $result['1: check'][2][0]->expression = '([C_check]<>\'\')'; + $result['1: default'][2] = []; $result['1: default'][2][] = new DefaultValueConstraint([ 'name' => AnyValue::getInstance(), 'columnNames' => ['C_default'], 'value' => '((0))', ]); + $result['2: default'][2] = []; + $result['3: foreign key'][2][0]->foreignSchemaName = 'dbo'; $result['3: index'][2] = []; + $result['3: default'][2] = []; + + $result['4: default'][2] = []; return $result; } } diff --git a/tests/framework/db/mysql/SchemaTest.php b/tests/framework/db/mysql/SchemaTest.php index cb7024ce8c7..ee06c1fdaf3 100644 --- a/tests/framework/db/mysql/SchemaTest.php +++ b/tests/framework/db/mysql/SchemaTest.php @@ -20,12 +20,16 @@ class SchemaTest extends \yiiunit\framework\db\SchemaTest public function constraintsProvider() { $result = parent::constraintsProvider(); - $result['1: check'][2] = []; + $result['1: check'][2] = false; $result['2: primary key'][2]->name = null; + $result['2: check'][2] = false; // Work aroung bug in MySQL 5.1 - it creates only this table in lowercase. O_o $result['3: foreign key'][2][0]->foreignTableName = new AnyCaseValue('T_constraints_2'); + $result['3: check'][2] = false; + + $result['4: check'][2] = false; return $result; } }