Skip to content

Commit

Permalink
Test TableSchema instead of a deprecated Table class.
Browse files Browse the repository at this point in the history
  • Loading branch information
robertpustulka committed Feb 15, 2018
1 parent 42eb337 commit 275e24f
Show file tree
Hide file tree
Showing 7 changed files with 56 additions and 56 deletions.
6 changes: 3 additions & 3 deletions tests/TestCase/Database/Schema/MysqlSchemaTest.php
Expand Up @@ -312,7 +312,7 @@ public function testDescribeTable()

$schema = new SchemaCollection($connection);
$result = $schema->describe('schema_articles');
$this->assertInstanceOf('Cake\Database\Schema\Table', $result);
$this->assertInstanceOf('Cake\Database\Schema\TableSchema', $result);
$expected = [
'id' => [
'type' => 'biginteger',
Expand Down Expand Up @@ -400,7 +400,7 @@ public function testDescribeTableIndexes()

$schema = new SchemaCollection($connection);
$result = $schema->describe('schema_articles');
$this->assertInstanceOf('Cake\Database\Schema\Table', $result);
$this->assertInstanceOf('Cake\Database\Schema\TableSchema', $result);

$this->assertCount(3, $result->constraints());
$expected = [
Expand Down Expand Up @@ -1296,7 +1296,7 @@ public function testDescribeJson()

$schema = new SchemaCollection($connection);
$result = $schema->describe('schema_json');
$this->assertInstanceOf('Cake\Database\Schema\Table', $result);
$this->assertInstanceOf('Cake\Database\Schema\TableSchema', $result);
$expected = [
'type' => 'json',
'null' => false,
Expand Down
4 changes: 2 additions & 2 deletions tests/TestCase/Database/Schema/PostgresSchemaTest.php
Expand Up @@ -513,7 +513,7 @@ public function testDescribeTableConstraintsWithKeywords()

$schema = new SchemaCollection($connection);
$result = $schema->describe('schema_authors');
$this->assertInstanceOf('Cake\Database\Schema\Table', $result);
$this->assertInstanceOf('Cake\Database\Schema\TableSchema', $result);
$expected = [
'primary' => [
'type' => 'primary',
Expand Down Expand Up @@ -543,7 +543,7 @@ public function testDescribeTableIndexes()

$schema = new SchemaCollection($connection);
$result = $schema->describe('schema_articles');
$this->assertInstanceOf('Cake\Database\Schema\Table', $result);
$this->assertInstanceOf('Cake\Database\Schema\TableSchema', $result);
$expected = [
'primary' => [
'type' => 'primary',
Expand Down
4 changes: 2 additions & 2 deletions tests/TestCase/Database/Schema/SqliteSchemaTest.php
Expand Up @@ -372,7 +372,7 @@ public function testDescribeTable()
'collate' => null,
],
];
$this->assertInstanceOf('Cake\Database\Schema\Table', $result);
$this->assertInstanceOf('Cake\Database\Schema\TableSchema', $result);
$this->assertEquals(['id'], $result->primaryKey());
foreach ($expected as $field => $definition) {
$this->assertEquals($definition, $result->getColumn($field));
Expand Down Expand Up @@ -411,7 +411,7 @@ public function testDescribeTableIndexes()

$schema = new SchemaCollection($connection);
$result = $schema->describe('schema_articles');
$this->assertInstanceOf('Cake\Database\Schema\Table', $result);
$this->assertInstanceOf('Cake\Database\Schema\TableSchema', $result);
$expected = [
'primary' => [
'type' => 'primary',
Expand Down
4 changes: 2 additions & 2 deletions tests/TestCase/Database/Schema/SqlserverSchemaTest.php
Expand Up @@ -274,7 +274,7 @@ public function testConvertColumn($type, $length, $precision, $scale, $expected)
$driver = $this->getMockBuilder('Cake\Database\Driver\Sqlserver')->getMock();
$dialect = new SqlserverSchema($driver);

$table = $this->getMockBuilder('Cake\Database\Schema\Table')
$table = $this->getMockBuilder('Cake\Database\Schema\TableSchema')
->setConstructorArgs(['table'])
->getMock();
$table->expects($this->at(0))->method('addColumn')->with('field', $expected);
Expand Down Expand Up @@ -472,7 +472,7 @@ public function testDescribeTableIndexes()

$schema = new SchemaCollection($connection);
$result = $schema->describe('schema_articles');
$this->assertInstanceOf('Cake\Database\Schema\Table', $result);
$this->assertInstanceOf('Cake\Database\Schema\TableSchema', $result);
$this->assertCount(3, $result->constraints());
$expected = [
'primary' => [
Expand Down
Expand Up @@ -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;
Expand Down Expand Up @@ -78,7 +78,7 @@ public function testConstructWithColumns()
'length' => 255
]
];
$table = new Table('articles', $columns);
$table = new TableSchema('articles', $columns);
$this->assertEquals(['id', 'title'], $table->columns());
}

Expand All @@ -89,7 +89,7 @@ public function testConstructWithColumns()
*/
public function testAddColumn()
{
$table = new Table('articles');
$table = new TableSchema('articles');
$result = $table->addColumn('title', [
'type' => 'string',
'length' => 25,
Expand All @@ -110,7 +110,7 @@ public function testAddColumn()
*/
public function testHasColumn()
{
$schema = new Table('articles', [
$schema = new TableSchema('articles', [
'title' => 'string'
]);

Expand All @@ -125,7 +125,7 @@ public function testHasColumn()
*/
public function testRemoveColumn()
{
$table = new Table('articles');
$table = new TableSchema('articles');
$result = $table->addColumn('title', [
'type' => 'string',
'length' => 25,
Expand All @@ -146,7 +146,7 @@ public function testRemoveColumn()
*/
public function testIsNullable()
{
$table = new Table('articles');
$table = new TableSchema('articles');
$table->addColumn('title', [
'type' => 'string',
'length' => 25,
Expand All @@ -168,7 +168,7 @@ public function testIsNullable()
*/
public function testColumnType()
{
$table = new Table('articles');
$table = new TableSchema('articles');
$table->addColumn('title', [
'type' => 'string',
'length' => 25,
Expand All @@ -185,7 +185,7 @@ public function testColumnType()
*/
public function testSetColumnType()
{
$table = new Table('articles');
$table = new TableSchema('articles');
$table->addColumn('title', [
'type' => 'string',
'length' => 25,
Expand All @@ -203,7 +203,7 @@ public function testSetColumnType()
*/
public function testBaseColumnType()
{
$table = new Table('articles');
$table = new TableSchema('articles');
$table->addColumn('title', [
'type' => 'json',
'baseType' => 'text',
Expand All @@ -222,7 +222,7 @@ public function testBaseColumnType()
public function testBaseColumnTypeInherited()
{
Type::map('foo', __NAMESPACE__ . '\FooType');
$table = new Table('articles');
$table = new TableSchema('articles');
$table->addColumn('thing', [
'type' => 'foo',
'null' => false
Expand All @@ -238,7 +238,7 @@ public function testBaseColumnTypeInherited()
*/
public function testAddColumnFiltersAttributes()
{
$table = new Table('articles');
$table = new TableSchema('articles');
$table->addColumn('title', [
'type' => 'string'
]);
Expand Down Expand Up @@ -294,7 +294,7 @@ public function testAddColumnFiltersAttributes()
*/
public function testDefaultValues()
{
$table = new Table('articles');
$table = new TableSchema('articles');
$table->addColumn('id', [
'type' => 'integer',
'default' => 0
Expand Down Expand Up @@ -326,7 +326,7 @@ public function testDefaultValues()
*/
public function testAddConstraint()
{
$table = new Table('articles');
$table = new TableSchema('articles');
$table->addColumn('id', [
'type' => 'integer'
]);
Expand All @@ -345,7 +345,7 @@ public function testAddConstraint()
*/
public function testAddConstraintOverwriteUniqueIndex()
{
$table = new Table('articles');
$table = new TableSchema('articles');
$table->addColumn('project_id', [
'type' => 'integer',
'default' => null,
Expand Down Expand Up @@ -382,10 +382,10 @@ public static function addConstraintErrorProvider()
// 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']],
];
Expand All @@ -401,7 +401,7 @@ public static function addConstraintErrorProvider()
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);
}
Expand All @@ -413,7 +413,7 @@ public function testAddConstraintError($props)
*/
public function testAddIndex()
{
$table = new Table('articles');
$table = new TableSchema('articles');
$table->addColumn('title', [
'type' => 'string'
]);
Expand All @@ -438,10 +438,10 @@ public static function addIndexErrorProvider()
// 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]],
];
}

Expand All @@ -455,7 +455,7 @@ public static function addIndexErrorProvider()
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);
}
Expand All @@ -467,7 +467,7 @@ public function testAddIndexError($props)
*/
public function testAddIndexTypes()
{
$table = new Table('articles');
$table = new TableSchema('articles');
$table->addColumn('id', 'integer')
->addColumn('title', 'string')
->addColumn('author_id', 'integer');
Expand All @@ -493,7 +493,7 @@ public function testAddIndexTypes()
*/
public function testPrimaryKey()
{
$table = new Table('articles');
$table = new TableSchema('articles');
$table->addColumn('id', 'integer')
->addColumn('title', 'string')
->addColumn('author_id', 'integer')
Expand All @@ -506,7 +506,7 @@ public function testPrimaryKey()
]);
$this->assertEquals(['id'], $table->primaryKey());

$table = new Table('articles');
$table = new TableSchema('articles');
$table->addColumn('id', 'integer')
->addColumn('title', 'string')
->addColumn('author_id', 'integer');
Expand All @@ -520,12 +520,12 @@ public function testPrimaryKey()
*/
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());
}

Expand All @@ -537,13 +537,13 @@ public function testOptions()
*/
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());
});
}
Expand All @@ -555,10 +555,10 @@ public function testOptionsDeprecated()
*/
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',
Expand Down Expand Up @@ -631,19 +631,19 @@ public static function badForeignKeyProvider()
{
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',
Expand All @@ -660,7 +660,7 @@ public static function badForeignKeyProvider()
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);
}
Expand All @@ -673,7 +673,7 @@ public function testAddConstraintForeignKeyBadData($data)
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());
Expand All @@ -689,7 +689,7 @@ public function testTemporary()
*/
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());
Expand Down

0 comments on commit 275e24f

Please sign in to comment.