Skip to content

Commit

Permalink
Added test for create table SQL in mysql including JSON column
Browse files Browse the repository at this point in the history
  • Loading branch information
lorenzo committed Mar 19, 2016
1 parent 5ac1f7d commit 792aea8
Showing 1 changed file with 56 additions and 0 deletions.
56 changes: 56 additions & 0 deletions tests/TestCase/Database/Schema/MysqlSchemaTest.php
Expand Up @@ -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
Expand All @@ -885,6 +890,9 @@ public function testCreateSql()
'type' => 'text',
'comment' => ''
])
->addColumn('data', [
'type' => 'json'
])
->addColumn('created', 'datetime')
->addConstraint('primary', [
'type' => 'primary',
Expand All @@ -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
Expand All @@ -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
*
Expand Down

0 comments on commit 792aea8

Please sign in to comment.