|
|
@@ -14,7 +14,7 @@
|
|
|
*/
|
|
|
namespace Cake\Test\TestCase\Database\Schema;
|
|
|
|
|
|
-use Cake\Database\Schema\Table;
|
|
|
+use Cake\Database\Schema\TableSchema;
|
|
|
use Cake\Database\Type;
|
|
|
use Cake\Datasource\ConnectionManager;
|
|
|
use Cake\TestSuite\TestCase;
|
|
|
@@ -78,7 +78,7 @@ class TableTest extends TestCase
|
|
|
'length' => 255
|
|
|
]
|
|
|
];
|
|
|
- $table = new Table('articles', $columns);
|
|
|
+ $table = new TableSchema('articles', $columns);
|
|
|
$this->assertEquals(['id', 'title'], $table->columns());
|
|
|
}
|
|
|
|
|
|
@@ -89,7 +89,7 @@ class TableTest extends TestCase
|
|
|
*/
|
|
|
public function testAddColumn()
|
|
|
{
|
|
|
- $table = new Table('articles');
|
|
|
+ $table = new TableSchema('articles');
|
|
|
$result = $table->addColumn('title', [
|
|
|
'type' => 'string',
|
|
|
'length' => 25,
|
|
|
@@ -110,7 +110,7 @@ class TableTest extends TestCase
|
|
|
*/
|
|
|
public function testHasColumn()
|
|
|
{
|
|
|
- $schema = new Table('articles', [
|
|
|
+ $schema = new TableSchema('articles', [
|
|
|
'title' => 'string'
|
|
|
]);
|
|
|
|
|
|
@@ -125,7 +125,7 @@ class TableTest extends TestCase
|
|
|
*/
|
|
|
public function testRemoveColumn()
|
|
|
{
|
|
|
- $table = new Table('articles');
|
|
|
+ $table = new TableSchema('articles');
|
|
|
$result = $table->addColumn('title', [
|
|
|
'type' => 'string',
|
|
|
'length' => 25,
|
|
|
@@ -146,7 +146,7 @@ class TableTest extends TestCase
|
|
|
*/
|
|
|
public function testIsNullable()
|
|
|
{
|
|
|
- $table = new Table('articles');
|
|
|
+ $table = new TableSchema('articles');
|
|
|
$table->addColumn('title', [
|
|
|
'type' => 'string',
|
|
|
'length' => 25,
|
|
|
@@ -168,7 +168,7 @@ class TableTest extends TestCase
|
|
|
*/
|
|
|
public function testColumnType()
|
|
|
{
|
|
|
- $table = new Table('articles');
|
|
|
+ $table = new TableSchema('articles');
|
|
|
$table->addColumn('title', [
|
|
|
'type' => 'string',
|
|
|
'length' => 25,
|
|
|
@@ -185,7 +185,7 @@ class TableTest extends TestCase
|
|
|
*/
|
|
|
public function testSetColumnType()
|
|
|
{
|
|
|
- $table = new Table('articles');
|
|
|
+ $table = new TableSchema('articles');
|
|
|
$table->addColumn('title', [
|
|
|
'type' => 'string',
|
|
|
'length' => 25,
|
|
|
@@ -203,7 +203,7 @@ class TableTest extends TestCase
|
|
|
*/
|
|
|
public function testBaseColumnType()
|
|
|
{
|
|
|
- $table = new Table('articles');
|
|
|
+ $table = new TableSchema('articles');
|
|
|
$table->addColumn('title', [
|
|
|
'type' => 'json',
|
|
|
'baseType' => 'text',
|
|
|
@@ -222,7 +222,7 @@ class TableTest extends TestCase
|
|
|
public function testBaseColumnTypeInherited()
|
|
|
{
|
|
|
Type::map('foo', __NAMESPACE__ . '\FooType');
|
|
|
- $table = new Table('articles');
|
|
|
+ $table = new TableSchema('articles');
|
|
|
$table->addColumn('thing', [
|
|
|
'type' => 'foo',
|
|
|
'null' => false
|
|
|
@@ -238,7 +238,7 @@ class TableTest extends TestCase
|
|
|
*/
|
|
|
public function testAddColumnFiltersAttributes()
|
|
|
{
|
|
|
- $table = new Table('articles');
|
|
|
+ $table = new TableSchema('articles');
|
|
|
$table->addColumn('title', [
|
|
|
'type' => 'string'
|
|
|
]);
|
|
|
@@ -294,7 +294,7 @@ class TableTest extends TestCase
|
|
|
*/
|
|
|
public function testDefaultValues()
|
|
|
{
|
|
|
- $table = new Table('articles');
|
|
|
+ $table = new TableSchema('articles');
|
|
|
$table->addColumn('id', [
|
|
|
'type' => 'integer',
|
|
|
'default' => 0
|
|
|
@@ -326,7 +326,7 @@ class TableTest extends TestCase
|
|
|
*/
|
|
|
public function testAddConstraint()
|
|
|
{
|
|
|
- $table = new Table('articles');
|
|
|
+ $table = new TableSchema('articles');
|
|
|
$table->addColumn('id', [
|
|
|
'type' => 'integer'
|
|
|
]);
|
|
|
@@ -345,7 +345,7 @@ class TableTest extends TestCase
|
|
|
*/
|
|
|
public function testAddConstraintOverwriteUniqueIndex()
|
|
|
{
|
|
|
- $table = new Table('articles');
|
|
|
+ $table = new TableSchema('articles');
|
|
|
$table->addColumn('project_id', [
|
|
|
'type' => 'integer',
|
|
|
'default' => null,
|
|
|
@@ -382,10 +382,10 @@ class TableTest extends TestCase
|
|
|
// No properties
|
|
|
[[]],
|
|
|
// Empty columns
|
|
|
- [['columns' => '', 'type' => Table::CONSTRAINT_UNIQUE]],
|
|
|
- [['columns' => [], 'type' => Table::CONSTRAINT_UNIQUE]],
|
|
|
+ [['columns' => '', 'type' => TableSchema::CONSTRAINT_UNIQUE]],
|
|
|
+ [['columns' => [], 'type' => TableSchema::CONSTRAINT_UNIQUE]],
|
|
|
// Missing column
|
|
|
- [['columns' => ['derp'], 'type' => Table::CONSTRAINT_UNIQUE]],
|
|
|
+ [['columns' => ['derp'], 'type' => TableSchema::CONSTRAINT_UNIQUE]],
|
|
|
// Invalid type
|
|
|
[['columns' => 'author_id', 'type' => 'derp']],
|
|
|
];
|
|
|
@@ -401,7 +401,7 @@ class TableTest extends TestCase
|
|
|
public function testAddConstraintError($props)
|
|
|
{
|
|
|
$this->expectException(\Cake\Database\Exception::class);
|
|
|
- $table = new Table('articles');
|
|
|
+ $table = new TableSchema('articles');
|
|
|
$table->addColumn('author_id', 'integer');
|
|
|
$table->addConstraint('author_idx', $props);
|
|
|
}
|
|
|
@@ -413,7 +413,7 @@ class TableTest extends TestCase
|
|
|
*/
|
|
|
public function testAddIndex()
|
|
|
{
|
|
|
- $table = new Table('articles');
|
|
|
+ $table = new TableSchema('articles');
|
|
|
$table->addColumn('title', [
|
|
|
'type' => 'string'
|
|
|
]);
|
|
|
@@ -438,10 +438,10 @@ class TableTest extends TestCase
|
|
|
// Invalid type
|
|
|
[['columns' => 'author_id', 'type' => 'derp']],
|
|
|
// No columns
|
|
|
- [['columns' => ''], 'type' => Table::INDEX_INDEX],
|
|
|
- [['columns' => [], 'type' => Table::INDEX_INDEX]],
|
|
|
+ [['columns' => ''], 'type' => TableSchema::INDEX_INDEX],
|
|
|
+ [['columns' => [], 'type' => TableSchema::INDEX_INDEX]],
|
|
|
// Missing column
|
|
|
- [['columns' => ['not_there'], 'type' => Table::INDEX_INDEX]],
|
|
|
+ [['columns' => ['not_there'], 'type' => TableSchema::INDEX_INDEX]],
|
|
|
];
|
|
|
}
|
|
|
|
|
|
@@ -455,7 +455,7 @@ class TableTest extends TestCase
|
|
|
public function testAddIndexError($props)
|
|
|
{
|
|
|
$this->expectException(\Cake\Database\Exception::class);
|
|
|
- $table = new Table('articles');
|
|
|
+ $table = new TableSchema('articles');
|
|
|
$table->addColumn('author_id', 'integer');
|
|
|
$table->addIndex('author_idx', $props);
|
|
|
}
|
|
|
@@ -467,7 +467,7 @@ class TableTest extends TestCase
|
|
|
*/
|
|
|
public function testAddIndexTypes()
|
|
|
{
|
|
|
- $table = new Table('articles');
|
|
|
+ $table = new TableSchema('articles');
|
|
|
$table->addColumn('id', 'integer')
|
|
|
->addColumn('title', 'string')
|
|
|
->addColumn('author_id', 'integer');
|
|
|
@@ -493,7 +493,7 @@ class TableTest extends TestCase
|
|
|
*/
|
|
|
public function testPrimaryKey()
|
|
|
{
|
|
|
- $table = new Table('articles');
|
|
|
+ $table = new TableSchema('articles');
|
|
|
$table->addColumn('id', 'integer')
|
|
|
->addColumn('title', 'string')
|
|
|
->addColumn('author_id', 'integer')
|
|
|
@@ -506,7 +506,7 @@ class TableTest extends TestCase
|
|
|
]);
|
|
|
$this->assertEquals(['id'], $table->primaryKey());
|
|
|
|
|
|
- $table = new Table('articles');
|
|
|
+ $table = new TableSchema('articles');
|
|
|
$table->addColumn('id', 'integer')
|
|
|
->addColumn('title', 'string')
|
|
|
->addColumn('author_id', 'integer');
|
|
|
@@ -520,12 +520,12 @@ class TableTest extends TestCase
|
|
|
*/
|
|
|
public function testOptions()
|
|
|
{
|
|
|
- $table = new Table('articles');
|
|
|
+ $table = new TableSchema('articles');
|
|
|
$options = [
|
|
|
'engine' => 'InnoDB'
|
|
|
];
|
|
|
$return = $table->setOptions($options);
|
|
|
- $this->assertInstanceOf('Cake\Database\Schema\Table', $return);
|
|
|
+ $this->assertInstanceOf('Cake\Database\Schema\TableSchema', $return);
|
|
|
$this->assertEquals($options, $table->getOptions());
|
|
|
}
|
|
|
|
|
|
@@ -537,13 +537,13 @@ class TableTest extends TestCase
|
|
|
*/
|
|
|
public function testOptionsDeprecated()
|
|
|
{
|
|
|
- $table = new Table('articles');
|
|
|
+ $table = new TableSchema('articles');
|
|
|
$options = [
|
|
|
'engine' => 'InnoDB'
|
|
|
];
|
|
|
$this->deprecated(function () use ($table, $options) {
|
|
|
$return = $table->options($options);
|
|
|
- $this->assertInstanceOf('Cake\Database\Schema\Table', $return);
|
|
|
+ $this->assertInstanceOf('Cake\Database\Schema\TableSchema', $return);
|
|
|
$this->assertEquals($options, $table->options());
|
|
|
});
|
|
|
}
|
|
|
@@ -555,10 +555,10 @@ class TableTest extends TestCase
|
|
|
*/
|
|
|
public function testAddConstraintForeignKey()
|
|
|
{
|
|
|
- $table = new Table('articles');
|
|
|
+ $table = new TableSchema('articles');
|
|
|
$table->addColumn('author_id', 'integer')
|
|
|
->addConstraint('author_id_idx', [
|
|
|
- 'type' => Table::CONSTRAINT_FOREIGN,
|
|
|
+ 'type' => TableSchema::CONSTRAINT_FOREIGN,
|
|
|
'columns' => ['author_id'],
|
|
|
'references' => ['authors', 'id'],
|
|
|
'update' => 'cascade',
|
|
|
@@ -631,19 +631,19 @@ class TableTest extends TestCase
|
|
|
{
|
|
|
return [
|
|
|
'references is bad' => [[
|
|
|
- 'type' => Table::CONSTRAINT_FOREIGN,
|
|
|
+ 'type' => TableSchema::CONSTRAINT_FOREIGN,
|
|
|
'columns' => ['author_id'],
|
|
|
'references' => ['authors'],
|
|
|
'delete' => 'derp',
|
|
|
]],
|
|
|
'bad update value' => [[
|
|
|
- 'type' => Table::CONSTRAINT_FOREIGN,
|
|
|
+ 'type' => TableSchema::CONSTRAINT_FOREIGN,
|
|
|
'columns' => ['author_id'],
|
|
|
'references' => ['authors', 'id'],
|
|
|
'update' => 'derp',
|
|
|
]],
|
|
|
'bad delete value' => [[
|
|
|
- 'type' => Table::CONSTRAINT_FOREIGN,
|
|
|
+ 'type' => TableSchema::CONSTRAINT_FOREIGN,
|
|
|
'columns' => ['author_id'],
|
|
|
'references' => ['authors', 'id'],
|
|
|
'delete' => 'derp',
|
|
|
@@ -660,7 +660,7 @@ class TableTest extends TestCase
|
|
|
public function testAddConstraintForeignKeyBadData($data)
|
|
|
{
|
|
|
$this->expectException(\Cake\Database\Exception::class);
|
|
|
- $table = new Table('articles');
|
|
|
+ $table = new TableSchema('articles');
|
|
|
$table->addColumn('author_id', 'integer')
|
|
|
->addConstraint('author_id_idx', $data);
|
|
|
}
|
|
|
@@ -673,7 +673,7 @@ class TableTest extends TestCase
|
|
|
public function testTemporary()
|
|
|
{
|
|
|
$this->deprecated(function () {
|
|
|
- $table = new Table('articles');
|
|
|
+ $table = new TableSchema('articles');
|
|
|
$this->assertFalse($table->temporary());
|
|
|
$this->assertSame($table, $table->temporary(true));
|
|
|
$this->assertTrue($table->temporary());
|
|
|
@@ -689,7 +689,7 @@ class TableTest extends TestCase
|
|
|
*/
|
|
|
public function testSetTemporary()
|
|
|
{
|
|
|
- $table = new Table('articles');
|
|
|
+ $table = new TableSchema('articles');
|
|
|
$this->assertFalse($table->isTemporary());
|
|
|
$this->assertSame($table, $table->setTemporary(true));
|
|
|
$this->assertTrue($table->isTemporary());
|