Skip to content
Permalink
Browse files

Added test for create table SQL in mysql including JSON column

  • Loading branch information...
lorenzo committed Mar 19, 2016
1 parent 5ac1f7d commit 792aea8ccd1dc591e9d99242e80fdecd40cd6914
Showing with 56 additions and 0 deletions.
  1. +56 −0 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 = <<<SQL
CREATE TABLE `posts` (
`id` INTEGER NOT NULL AUTO_INCREMENT,
`data` JSON,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci
SQL;
$result = $table->createSql($connection);
$this->assertCount(1, $result);
$this->assertTextEquals($expected, $result[0]);
}
/**
* Tests creating temporary tables
*

0 comments on commit 792aea8

Please sign in to comment.
You can’t perform that action at this time.