Skip to content

Commit 8e74a80

Browse files
committed
Fix deprecated API usage for TableSchema.
1 parent b17448a commit 8e74a80

File tree

7 files changed

+52
-34
lines changed

7 files changed

+52
-34
lines changed

tests/TestCase/Database/Schema/MysqlSchemaTest.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -378,7 +378,7 @@ public function testDescribeTable()
378378
foreach ($expected as $field => $definition) {
379379
$this->assertEquals(
380380
$definition,
381-
$result->column($field),
381+
$result->getColumn($field),
382382
'Field definition does not match for ' . $field
383383
);
384384
}
@@ -468,11 +468,11 @@ public function testDescribeNonPrimaryAutoIncrement()
468468
$table = $schema->describe('odd_primary_key');
469469
$connection->execute('DROP TABLE odd_primary_key');
470470

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

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

@@ -1057,7 +1057,7 @@ public function testCreateSql()
10571057
'type' => 'primary',
10581058
'columns' => ['id']
10591059
])
1060-
->options([
1060+
->setOptions([
10611061
'engine' => 'InnoDB',
10621062
'charset' => 'utf8',
10631063
'collate' => 'utf8_general_ci',
@@ -1110,7 +1110,7 @@ public function testCreateSqlJson()
11101110
'type' => 'primary',
11111111
'columns' => ['id']
11121112
])
1113-
->options([
1113+
->setOptions([
11141114
'engine' => 'InnoDB',
11151115
'charset' => 'utf8',
11161116
'collate' => 'utf8_general_ci',

tests/TestCase/Database/Schema/SqliteSchemaTest.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -371,7 +371,7 @@ public function testDescribeTable()
371371
$this->assertInstanceOf('Cake\Database\Schema\Table', $result);
372372
$this->assertEquals(['id'], $result->primaryKey());
373373
foreach ($expected as $field => $definition) {
374-
$this->assertEquals($definition, $result->column($field));
374+
$this->assertEquals($definition, $result->getColumn($field));
375375
}
376376
}
377377

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

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

398398
/**
@@ -429,14 +429,14 @@ public function testDescribeTableIndexes()
429429
]
430430
];
431431
$this->assertCount(3, $result->constraints());
432-
$this->assertEquals($expected['primary'], $result->constraint('primary'));
432+
$this->assertEquals($expected['primary'], $result->getConstraint('primary'));
433433
$this->assertEquals(
434434
$expected['sqlite_autoindex_schema_articles_1'],
435-
$result->constraint('sqlite_autoindex_schema_articles_1')
435+
$result->getConstraint('sqlite_autoindex_schema_articles_1')
436436
);
437437
$this->assertEquals(
438438
$expected['author_id_fk'],
439-
$result->constraint('author_id_fk')
439+
$result->getConstraint('author_id_fk')
440440
);
441441

442442
$this->assertCount(1, $result->indexes());
@@ -445,7 +445,7 @@ public function testDescribeTableIndexes()
445445
'columns' => ['created'],
446446
'length' => []
447447
];
448-
$this->assertEquals($expected, $result->index('created_idx'));
448+
$this->assertEquals($expected, $result->getIndex('created_idx'));
449449
}
450450

451451
/**

tests/TestCase/Database/Schema/TableTest.php

Lines changed: 33 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ public function testRemoveColumn()
136136

137137
$this->assertSame($table, $result);
138138
$this->assertEquals([], $table->columns());
139-
$this->assertNull($table->column('title'));
139+
$this->assertNull($table->getColumn('title'));
140140
$this->assertSame([], $table->typeMap());
141141
}
142142

@@ -175,26 +175,26 @@ public function testColumnType()
175175
'length' => 25,
176176
'null' => false
177177
]);
178-
$this->assertEquals('string', $table->columnType('title'));
179-
$this->assertNull($table->columnType('not there'));
178+
$this->assertEquals('string', $table->getColumnType('title'));
179+
$this->assertNull($table->getColumnType('not there'));
180180
}
181181

182182
/**
183-
* Test columnType setter method
183+
* Test setColumnType setter method
184184
*
185185
* @return void
186186
*/
187-
public function testColumnTypeSet()
187+
public function testSetColumnType()
188188
{
189189
$table = new Table('articles');
190190
$table->addColumn('title', [
191191
'type' => 'string',
192192
'length' => 25,
193193
'null' => false
194194
]);
195-
$this->assertEquals('string', $table->columnType('title'));
196-
$table->columnType('title', 'json');
197-
$this->assertEquals('json', $table->columnType('title'));
195+
$this->assertEquals('string', $table->getColumnType('title'));
196+
$table->setColumnType('title', 'json');
197+
$this->assertEquals('json', $table->getColumnType('title'));
198198
}
199199

200200
/**
@@ -211,7 +211,7 @@ public function testBaseColumnType()
211211
'length' => 25,
212212
'null' => false
213213
]);
214-
$this->assertEquals('json', $table->columnType('title'));
214+
$this->assertEquals('json', $table->getColumnType('title'));
215215
$this->assertEquals('text', $table->baseColumnType('title'));
216216
}
217217

@@ -228,7 +228,7 @@ public function testBaseColumnTypeInherited()
228228
'type' => 'foo',
229229
'null' => false
230230
]);
231-
$this->assertEquals('foo', $table->columnType('thing'));
231+
$this->assertEquals('foo', $table->getColumnType('thing'));
232232
$this->assertEquals('integer', $table->baseColumnType('thing'));
233233
}
234234

@@ -243,7 +243,7 @@ public function testAddColumnFiltersAttributes()
243243
$table->addColumn('title', [
244244
'type' => 'string'
245245
]);
246-
$result = $table->column('title');
246+
$result = $table->getColumn('title');
247247
$expected = [
248248
'type' => 'string',
249249
'length' => null,
@@ -259,7 +259,7 @@ public function testAddColumnFiltersAttributes()
259259
$table->addColumn('author_id', [
260260
'type' => 'integer'
261261
]);
262-
$result = $table->column('author_id');
262+
$result = $table->getColumn('author_id');
263263
$expected = [
264264
'type' => 'integer',
265265
'length' => null,
@@ -275,7 +275,7 @@ public function testAddColumnFiltersAttributes()
275275
$table->addColumn('amount', [
276276
'type' => 'decimal'
277277
]);
278-
$result = $table->column('amount');
278+
$result = $table->getColumn('amount');
279279
$expected = [
280280
'type' => 'decimal',
281281
'length' => null,
@@ -520,6 +520,24 @@ public function testPrimaryKey()
520520
* @return void
521521
*/
522522
public function testOptions()
523+
{
524+
$table = new Table('articles');
525+
$options = [
526+
'engine' => 'InnoDB'
527+
];
528+
$return = $table->setOptions($options);
529+
$this->assertInstanceOf('Cake\Database\Schema\Table', $return);
530+
$this->assertEquals($options, $table->getOptions());
531+
}
532+
533+
534+
/**
535+
* Test the options method.
536+
*
537+
* @group deprecated
538+
* @return void
539+
*/
540+
public function testOptionsDeprecated()
523541
{
524542
$table = new Table('articles');
525543
$options = [
@@ -557,7 +575,7 @@ public function testAddConstraintForeignKey()
557575
public function testConstraintForeignKey()
558576
{
559577
$table = TableRegistry::get('ArticlesTags');
560-
$compositeConstraint = $table->schema()->constraint('tag_id_fk');
578+
$compositeConstraint = $table->schema()->getConstraint('tag_id_fk');
561579
$expected = [
562580
'type' => 'foreign',
563581
'columns' => ['tag_id'],
@@ -581,7 +599,7 @@ public function testConstraintForeignKey()
581599
public function testConstraintForeignKeyTwoColumns()
582600
{
583601
$table = TableRegistry::get('Orders');
584-
$compositeConstraint = $table->schema()->constraint('product_category_fk');
602+
$compositeConstraint = $table->schema()->getConstraint('product_category_fk');
585603
$expected = [
586604
'type' => 'foreign',
587605
'columns' => [

tests/TestCase/ORM/Locator/TableLocatorTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -412,7 +412,7 @@ public function testConfigAndBuild()
412412
$this->assertEquals('users', $table->alias());
413413
$this->assertSame($connection, $table->connection());
414414
$this->assertEquals(array_keys($schema), $table->schema()->columns());
415-
$this->assertEquals($schema['id']['type'], $table->schema()->column('id')['type']);
415+
$this->assertEquals($schema['id']['type'], $table->schema()->getColumnType('id'));
416416

417417
$this->_locator->clear();
418418
$this->assertEmpty($this->_locator->config());
@@ -424,7 +424,7 @@ public function testConfigAndBuild()
424424
$this->assertEquals('users', $table->alias());
425425
$this->assertSame($connection, $table->connection());
426426
$this->assertEquals(array_keys($schema), $table->schema()->columns());
427-
$this->assertEquals($schema['id']['type'], $table->schema()->column('id')['type']);
427+
$this->assertEquals($schema['id']['type'], $table->schema()->getColumnType('id'));
428428
}
429429

430430
/**

tests/TestCase/ORM/TableTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -346,12 +346,12 @@ public function testSchemaInitialize()
346346
->method('_initializeSchema')
347347
->with($schema)
348348
->will($this->returnCallback(function ($schema) {
349-
$schema->columnType('username', 'integer');
349+
$schema->setColumnType('username', 'integer');
350350

351351
return $schema;
352352
}));
353353
$result = $table->schema();
354-
$schema->columnType('username', 'integer');
354+
$schema->setColumnType('username', 'integer');
355355
$this->assertEquals($schema, $result);
356356
$this->assertEquals($schema, $table->schema(), '_initializeSchema should be called once');
357357
}

tests/TestCase/View/Form/EntityContextTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -689,7 +689,7 @@ public function testValAssociatedCustomIds()
689689
public function testValSchemaDefault()
690690
{
691691
$table = TableRegistry::get('Articles');
692-
$column = $table->schema()->column('title');
692+
$column = $table->schema()->getColumn('title');
693693
$table->schema()->addColumn('title', ['default' => 'default title'] + $column);
694694
$row = $table->newEntity();
695695

tests/TestCase/View/Helper/FormHelperTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4379,7 +4379,7 @@ public function testTextDefaultValue()
43794379
$this->assertHtml($expected, $result);
43804380

43814381
$Articles = TableRegistry::get('Articles');
4382-
$title = $Articles->schema()->column('title');
4382+
$title = $Articles->schema()->getColumn('title');
43834383
$Articles->schema()->addColumn(
43844384
'title',
43854385
['default' => 'default title'] + $title
@@ -4714,7 +4714,7 @@ public function testRadioComplexDisabled()
47144714
public function testRadioDefaultValue()
47154715
{
47164716
$Articles = TableRegistry::get('Articles');
4717-
$title = $Articles->schema()->column('title');
4717+
$title = $Articles->schema()->getColumn('title');
47184718
$Articles->schema()->addColumn(
47194719
'title',
47204720
['default' => '1'] + $title

0 commit comments

Comments
 (0)