From 792aea8ccd1dc591e9d99242e80fdecd40cd6914 Mon Sep 17 00:00:00 2001 From: Jose Lorenzo Rodriguez Date: Sat, 19 Mar 2016 21:37:19 +0100 Subject: [PATCH] Added test for create table SQL in mysql including JSON column --- .../Database/Schema/MysqlSchemaTest.php | 56 +++++++++++++++++++ 1 file changed, 56 insertions(+) diff --git a/tests/TestCase/Database/Schema/MysqlSchemaTest.php b/tests/TestCase/Database/Schema/MysqlSchemaTest.php index 610023e9a32..eabbfeea4c3 100644 --- a/tests/TestCase/Database/Schema/MysqlSchemaTest.php +++ b/tests/TestCase/Database/Schema/MysqlSchemaTest.php @@ -872,6 +872,11 @@ public function testCreateSql() $connection->expects($this->any())->method('driver') ->will($this->returnValue($driver)); + $driver->connection() + ->expects($this->any()) + ->method('getAttribute') + ->will($this->returnValue('5.6.0')); + $table = (new Table('posts'))->addColumn('id', [ 'type' => 'integer', 'null' => false @@ -885,6 +890,9 @@ public function testCreateSql() 'type' => 'text', 'comment' => '' ]) + ->addColumn('data', [ + 'type' => 'json' + ]) ->addColumn('created', 'datetime') ->addConstraint('primary', [ 'type' => 'primary', @@ -901,6 +909,7 @@ public function testCreateSql() `id` INTEGER NOT NULL AUTO_INCREMENT, `title` VARCHAR(255) NOT NULL COMMENT 'The title', `body` TEXT, +`data` LONGTEXT, `created` DATETIME, PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci @@ -910,6 +919,53 @@ public function testCreateSql() $this->assertTextEquals($expected, $result[0]); } + /** + * Integration test for converting a Schema\Table with native JSON + * + * @return void + */ + public function testCreateSqlJson() + { + $driver = $this->_getMockedDriver(); + $connection = $this->getMock('Cake\Database\Connection', [], [], '', false); + $connection->expects($this->any()) + ->method('driver') + ->will($this->returnValue($driver)); + + $driver->connection() + ->expects($this->any()) + ->method('getAttribute') + ->will($this->returnValue('5.7.0')); + + $table = (new Table('posts'))->addColumn('id', [ + 'type' => 'integer', + 'null' => false + ]) + ->addColumn('data', [ + 'type' => 'json' + ]) + ->addConstraint('primary', [ + 'type' => 'primary', + 'columns' => ['id'] + ]) + ->options([ + 'engine' => 'InnoDB', + 'charset' => 'utf8', + 'collate' => 'utf8_general_ci', + ]); + + $expected = <<createSql($connection); + $this->assertCount(1, $result); + $this->assertTextEquals($expected, $result[0]); + } + /** * Tests creating temporary tables *