diff --git a/framework/db/mysql/ColumnSchema.php b/framework/db/mysql/ColumnSchema.php new file mode 100644 index 0000000000..554308d565 --- /dev/null +++ b/framework/db/mysql/ColumnSchema.php @@ -0,0 +1,52 @@ + + * @since 2.0.14.1 + */ +class ColumnSchema extends \yii\db\ColumnSchema +{ + /** + * {@inheritdoc} + */ + public function dbTypecast($value) + { + if ($value instanceof ExpressionInterface) { + return $value; + } + + if ($this->dbType === Schema::TYPE_JSON) { + return new JsonExpression($value, $this->type); + } + + return $this->typecast($value); + } + + /** + * {@inheritdoc} + */ + public function phpTypecast($value) + { + if ($value === null) { + return null; + } + + if ($this->type === Schema::TYPE_JSON) { + return json_decode($value, true); + } + + return parent::phpTypecast($value); + } +} diff --git a/tests/data/ar/Document.php b/tests/data/ar/Document.php index e129953a17..1d599baeb6 100644 --- a/tests/data/ar/Document.php +++ b/tests/data/ar/Document.php @@ -12,6 +12,7 @@ namespace yiiunit\data\ar; * @property string $title * @property string $content * @property int $version + * @property array $document */ class Document extends ActiveRecord { diff --git a/tests/data/mysql.sql b/tests/data/mysql.sql index 212aa49353..99d40fd64e 100644 --- a/tests/data/mysql.sql +++ b/tests/data/mysql.sql @@ -169,6 +169,7 @@ CREATE TABLE `document` ( `title` VARCHAR(255) NOT NULL, `content` TEXT, `version` INT(11) NOT NULL DEFAULT 0, + `properties` JSON, PRIMARY KEY (id) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; diff --git a/tests/data/postgres.sql b/tests/data/postgres.sql index 36bac6f382..e9b1cd08b0 100644 --- a/tests/data/postgres.sql +++ b/tests/data/postgres.sql @@ -178,7 +178,8 @@ CREATE TABLE "document" ( id serial primary key, title varchar(255) not null, content text not null, - version integer not null default 0 + version integer not null default 0, + properties json ); CREATE TABLE "comment" ( diff --git a/tests/framework/ChangeLogTest.php b/tests/framework/ChangeLogTest.php index bb3b0bdb58..a8e2fac3a3 100644 --- a/tests/framework/ChangeLogTest.php +++ b/tests/framework/ChangeLogTest.php @@ -54,6 +54,6 @@ class ChangeLogTest extends TestCase * - Description ends without a "." * - Line ends with contributor name between "(" and ")". */ - $this->assertRegExp('/- (Bug|Enh|Chg|New)( #\d+(, #\d+)*)?(\s\(CVE-[\d-]+\))?: .*[^.] \(.*\)$', $line); + $this->assertRegExp('/- (Bug|Enh|Chg|New)( #\d+(, #\d+)*)?(\s\(CVE-[\d-]+\))?: .*[^.] \(.*\)$/', $line); } }