Skip to content

Commit

Permalink
Fix deprecated API usage for TableSchema.
Browse files Browse the repository at this point in the history
  • Loading branch information
markstory committed Sep 12, 2017
1 parent b17448a commit 8e74a80
Show file tree
Hide file tree
Showing 7 changed files with 52 additions and 34 deletions.
10 changes: 5 additions & 5 deletions tests/TestCase/Database/Schema/MysqlSchemaTest.php
Expand Up @@ -378,7 +378,7 @@ public function testDescribeTable()
foreach ($expected as $field => $definition) {
$this->assertEquals(
$definition,
$result->column($field),
$result->getColumn($field),
'Field definition does not match for ' . $field
);
}
Expand Down Expand Up @@ -468,11 +468,11 @@ public function testDescribeNonPrimaryAutoIncrement()
$table = $schema->describe('odd_primary_key');
$connection->execute('DROP TABLE odd_primary_key');

$column = $table->column('id');
$column = $table->getColumn('id');
$this->assertNull($column['autoIncrement'], 'should not autoincrement');
$this->assertTrue($column['unsigned'], 'should be unsigned');

$column = $table->column('other_field');
$column = $table->getColumn('other_field');
$this->assertTrue($column['autoIncrement'], 'should not autoincrement');
$this->assertFalse($column['unsigned'], 'should not be unsigned');

Expand Down Expand Up @@ -1057,7 +1057,7 @@ public function testCreateSql()
'type' => 'primary',
'columns' => ['id']
])
->options([
->setOptions([
'engine' => 'InnoDB',
'charset' => 'utf8',
'collate' => 'utf8_general_ci',
Expand Down Expand Up @@ -1110,7 +1110,7 @@ public function testCreateSqlJson()
'type' => 'primary',
'columns' => ['id']
])
->options([
->setOptions([
'engine' => 'InnoDB',
'charset' => 'utf8',
'collate' => 'utf8_general_ci',
Expand Down
14 changes: 7 additions & 7 deletions tests/TestCase/Database/Schema/SqliteSchemaTest.php
Expand Up @@ -371,7 +371,7 @@ public function testDescribeTable()
$this->assertInstanceOf('Cake\Database\Schema\Table', $result);
$this->assertEquals(['id'], $result->primaryKey());
foreach ($expected as $field => $definition) {
$this->assertEquals($definition, $result->column($field));
$this->assertEquals($definition, $result->getColumn($field));
}
}

Expand All @@ -391,8 +391,8 @@ public function testDescribeTableCompositeKey()
$result = $schema->describe('schema_composite');

$this->assertEquals(['id', 'site_id'], $result->primaryKey());
$this->assertNull($result->column('site_id')['autoIncrement'], 'site_id should not be autoincrement');
$this->assertNull($result->column('id')['autoIncrement'], 'id should not be autoincrement');
$this->assertNull($result->getColumn('site_id')['autoIncrement'], 'site_id should not be autoincrement');
$this->assertNull($result->getColumn('id')['autoIncrement'], 'id should not be autoincrement');
}

/**
Expand Down Expand Up @@ -429,14 +429,14 @@ public function testDescribeTableIndexes()
]
];
$this->assertCount(3, $result->constraints());
$this->assertEquals($expected['primary'], $result->constraint('primary'));
$this->assertEquals($expected['primary'], $result->getConstraint('primary'));
$this->assertEquals(
$expected['sqlite_autoindex_schema_articles_1'],
$result->constraint('sqlite_autoindex_schema_articles_1')
$result->getConstraint('sqlite_autoindex_schema_articles_1')
);
$this->assertEquals(
$expected['author_id_fk'],
$result->constraint('author_id_fk')
$result->getConstraint('author_id_fk')
);

$this->assertCount(1, $result->indexes());
Expand All @@ -445,7 +445,7 @@ public function testDescribeTableIndexes()
'columns' => ['created'],
'length' => []
];
$this->assertEquals($expected, $result->index('created_idx'));
$this->assertEquals($expected, $result->getIndex('created_idx'));
}

/**
Expand Down
48 changes: 33 additions & 15 deletions tests/TestCase/Database/Schema/TableTest.php
Expand Up @@ -136,7 +136,7 @@ public function testRemoveColumn()

$this->assertSame($table, $result);
$this->assertEquals([], $table->columns());
$this->assertNull($table->column('title'));
$this->assertNull($table->getColumn('title'));
$this->assertSame([], $table->typeMap());
}

Expand Down Expand Up @@ -175,26 +175,26 @@ public function testColumnType()
'length' => 25,
'null' => false
]);
$this->assertEquals('string', $table->columnType('title'));
$this->assertNull($table->columnType('not there'));
$this->assertEquals('string', $table->getColumnType('title'));
$this->assertNull($table->getColumnType('not there'));
}

/**
* Test columnType setter method
* Test setColumnType setter method
*
* @return void
*/
public function testColumnTypeSet()
public function testSetColumnType()
{
$table = new Table('articles');
$table->addColumn('title', [
'type' => 'string',
'length' => 25,
'null' => false
]);
$this->assertEquals('string', $table->columnType('title'));
$table->columnType('title', 'json');
$this->assertEquals('json', $table->columnType('title'));
$this->assertEquals('string', $table->getColumnType('title'));
$table->setColumnType('title', 'json');
$this->assertEquals('json', $table->getColumnType('title'));
}

/**
Expand All @@ -211,7 +211,7 @@ public function testBaseColumnType()
'length' => 25,
'null' => false
]);
$this->assertEquals('json', $table->columnType('title'));
$this->assertEquals('json', $table->getColumnType('title'));
$this->assertEquals('text', $table->baseColumnType('title'));
}

Expand All @@ -228,7 +228,7 @@ public function testBaseColumnTypeInherited()
'type' => 'foo',
'null' => false
]);
$this->assertEquals('foo', $table->columnType('thing'));
$this->assertEquals('foo', $table->getColumnType('thing'));
$this->assertEquals('integer', $table->baseColumnType('thing'));
}

Expand All @@ -243,7 +243,7 @@ public function testAddColumnFiltersAttributes()
$table->addColumn('title', [
'type' => 'string'
]);
$result = $table->column('title');
$result = $table->getColumn('title');
$expected = [
'type' => 'string',
'length' => null,
Expand All @@ -259,7 +259,7 @@ public function testAddColumnFiltersAttributes()
$table->addColumn('author_id', [
'type' => 'integer'
]);
$result = $table->column('author_id');
$result = $table->getColumn('author_id');
$expected = [
'type' => 'integer',
'length' => null,
Expand All @@ -275,7 +275,7 @@ public function testAddColumnFiltersAttributes()
$table->addColumn('amount', [
'type' => 'decimal'
]);
$result = $table->column('amount');
$result = $table->getColumn('amount');
$expected = [
'type' => 'decimal',
'length' => null,
Expand Down Expand Up @@ -520,6 +520,24 @@ public function testPrimaryKey()
* @return void
*/
public function testOptions()
{
$table = new Table('articles');
$options = [
'engine' => 'InnoDB'
];
$return = $table->setOptions($options);
$this->assertInstanceOf('Cake\Database\Schema\Table', $return);
$this->assertEquals($options, $table->getOptions());
}


/**
* Test the options method.
*
* @group deprecated
* @return void
*/
public function testOptionsDeprecated()
{
$table = new Table('articles');
$options = [
Expand Down Expand Up @@ -557,7 +575,7 @@ public function testAddConstraintForeignKey()
public function testConstraintForeignKey()
{
$table = TableRegistry::get('ArticlesTags');
$compositeConstraint = $table->schema()->constraint('tag_id_fk');
$compositeConstraint = $table->schema()->getConstraint('tag_id_fk');
$expected = [
'type' => 'foreign',
'columns' => ['tag_id'],
Expand All @@ -581,7 +599,7 @@ public function testConstraintForeignKey()
public function testConstraintForeignKeyTwoColumns()
{
$table = TableRegistry::get('Orders');
$compositeConstraint = $table->schema()->constraint('product_category_fk');
$compositeConstraint = $table->schema()->getConstraint('product_category_fk');
$expected = [
'type' => 'foreign',
'columns' => [
Expand Down
4 changes: 2 additions & 2 deletions tests/TestCase/ORM/Locator/TableLocatorTest.php
Expand Up @@ -412,7 +412,7 @@ public function testConfigAndBuild()
$this->assertEquals('users', $table->alias());
$this->assertSame($connection, $table->connection());
$this->assertEquals(array_keys($schema), $table->schema()->columns());
$this->assertEquals($schema['id']['type'], $table->schema()->column('id')['type']);
$this->assertEquals($schema['id']['type'], $table->schema()->getColumnType('id'));

$this->_locator->clear();
$this->assertEmpty($this->_locator->config());
Expand All @@ -424,7 +424,7 @@ public function testConfigAndBuild()
$this->assertEquals('users', $table->alias());
$this->assertSame($connection, $table->connection());
$this->assertEquals(array_keys($schema), $table->schema()->columns());
$this->assertEquals($schema['id']['type'], $table->schema()->column('id')['type']);
$this->assertEquals($schema['id']['type'], $table->schema()->getColumnType('id'));
}

/**
Expand Down
4 changes: 2 additions & 2 deletions tests/TestCase/ORM/TableTest.php
Expand Up @@ -346,12 +346,12 @@ public function testSchemaInitialize()
->method('_initializeSchema')
->with($schema)
->will($this->returnCallback(function ($schema) {
$schema->columnType('username', 'integer');
$schema->setColumnType('username', 'integer');

return $schema;
}));
$result = $table->schema();
$schema->columnType('username', 'integer');
$schema->setColumnType('username', 'integer');
$this->assertEquals($schema, $result);
$this->assertEquals($schema, $table->schema(), '_initializeSchema should be called once');
}
Expand Down
2 changes: 1 addition & 1 deletion tests/TestCase/View/Form/EntityContextTest.php
Expand Up @@ -689,7 +689,7 @@ public function testValAssociatedCustomIds()
public function testValSchemaDefault()
{
$table = TableRegistry::get('Articles');
$column = $table->schema()->column('title');
$column = $table->schema()->getColumn('title');
$table->schema()->addColumn('title', ['default' => 'default title'] + $column);
$row = $table->newEntity();

Expand Down
4 changes: 2 additions & 2 deletions tests/TestCase/View/Helper/FormHelperTest.php
Expand Up @@ -4379,7 +4379,7 @@ public function testTextDefaultValue()
$this->assertHtml($expected, $result);

$Articles = TableRegistry::get('Articles');
$title = $Articles->schema()->column('title');
$title = $Articles->schema()->getColumn('title');
$Articles->schema()->addColumn(
'title',
['default' => 'default title'] + $title
Expand Down Expand Up @@ -4714,7 +4714,7 @@ public function testRadioComplexDisabled()
public function testRadioDefaultValue()
{
$Articles = TableRegistry::get('Articles');
$title = $Articles->schema()->column('title');
$title = $Articles->schema()->getColumn('title');
$Articles->schema()->addColumn(
'title',
['default' => '1'] + $title
Expand Down

0 comments on commit 8e74a80

Please sign in to comment.