Browse Source

Fix deprecated API usage for TableSchema.

Mark Story 8 years ago
parent
commit
8e74a80d13

+ 5 - 5
tests/TestCase/Database/Schema/MysqlSchemaTest.php

@@ -378,7 +378,7 @@ SQL;
         foreach ($expected as $field => $definition) {
             $this->assertEquals(
                 $definition,
-                $result->column($field),
+                $result->getColumn($field),
                 'Field definition does not match for ' . $field
             );
         }
@@ -468,11 +468,11 @@ SQL;
         $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');
 
@@ -1057,7 +1057,7 @@ SQL;
                 'type' => 'primary',
                 'columns' => ['id']
             ])
-            ->options([
+            ->setOptions([
                 'engine' => 'InnoDB',
                 'charset' => 'utf8',
                 'collate' => 'utf8_general_ci',
@@ -1110,7 +1110,7 @@ SQL;
                 'type' => 'primary',
                 'columns' => ['id']
             ])
-            ->options([
+            ->setOptions([
                 'engine' => 'InnoDB',
                 'charset' => 'utf8',
                 'collate' => 'utf8_general_ci',

+ 7 - 7
tests/TestCase/Database/Schema/SqliteSchemaTest.php

@@ -371,7 +371,7 @@ SQL;
         $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));
         }
     }
 
@@ -391,8 +391,8 @@ SQL;
         $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');
     }
 
     /**
@@ -429,14 +429,14 @@ SQL;
             ]
         ];
         $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());
@@ -445,7 +445,7 @@ SQL;
             'columns' => ['created'],
             'length' => []
         ];
-        $this->assertEquals($expected, $result->index('created_idx'));
+        $this->assertEquals($expected, $result->getIndex('created_idx'));
     }
 
     /**

+ 33 - 15
tests/TestCase/Database/Schema/TableTest.php

@@ -136,7 +136,7 @@ class TableTest extends TestCase
 
         $this->assertSame($table, $result);
         $this->assertEquals([], $table->columns());
-        $this->assertNull($table->column('title'));
+        $this->assertNull($table->getColumn('title'));
         $this->assertSame([], $table->typeMap());
     }
 
@@ -175,16 +175,16 @@ class TableTest extends TestCase
             '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', [
@@ -192,9 +192,9 @@ class TableTest extends TestCase
             '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'));
     }
 
     /**
@@ -211,7 +211,7 @@ class TableTest extends TestCase
             'length' => 25,
             'null' => false
         ]);
-        $this->assertEquals('json', $table->columnType('title'));
+        $this->assertEquals('json', $table->getColumnType('title'));
         $this->assertEquals('text', $table->baseColumnType('title'));
     }
 
@@ -228,7 +228,7 @@ class TableTest extends TestCase
             'type' => 'foo',
             'null' => false
         ]);
-        $this->assertEquals('foo', $table->columnType('thing'));
+        $this->assertEquals('foo', $table->getColumnType('thing'));
         $this->assertEquals('integer', $table->baseColumnType('thing'));
     }
 
@@ -243,7 +243,7 @@ class TableTest extends TestCase
         $table->addColumn('title', [
             'type' => 'string'
         ]);
-        $result = $table->column('title');
+        $result = $table->getColumn('title');
         $expected = [
             'type' => 'string',
             'length' => null,
@@ -259,7 +259,7 @@ class TableTest extends TestCase
         $table->addColumn('author_id', [
             'type' => 'integer'
         ]);
-        $result = $table->column('author_id');
+        $result = $table->getColumn('author_id');
         $expected = [
             'type' => 'integer',
             'length' => null,
@@ -275,7 +275,7 @@ class TableTest extends TestCase
         $table->addColumn('amount', [
             'type' => 'decimal'
         ]);
-        $result = $table->column('amount');
+        $result = $table->getColumn('amount');
         $expected = [
             'type' => 'decimal',
             'length' => null,
@@ -525,6 +525,24 @@ class TableTest extends TestCase
         $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 = [
+            'engine' => 'InnoDB'
+        ];
         $return = $table->options($options);
         $this->assertInstanceOf('Cake\Database\Schema\Table', $return);
         $this->assertEquals($options, $table->options());
@@ -557,7 +575,7 @@ class TableTest extends TestCase
     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'],
@@ -581,7 +599,7 @@ class TableTest extends TestCase
     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' => [

+ 2 - 2
tests/TestCase/ORM/Locator/TableLocatorTest.php

@@ -412,7 +412,7 @@ class TableLocatorTest extends TestCase
         $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());
@@ -424,7 +424,7 @@ class TableLocatorTest extends TestCase
         $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'));
     }
 
     /**

+ 2 - 2
tests/TestCase/ORM/TableTest.php

@@ -346,12 +346,12 @@ class TableTest extends TestCase
             ->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');
     }

+ 1 - 1
tests/TestCase/View/Form/EntityContextTest.php

@@ -689,7 +689,7 @@ class EntityContextTest extends TestCase
     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();
 

+ 2 - 2
tests/TestCase/View/Helper/FormHelperTest.php

@@ -4379,7 +4379,7 @@ class FormHelperTest extends TestCase
         $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
@@ -4714,7 +4714,7 @@ class FormHelperTest extends TestCase
     public function testRadioDefaultValue()
     {
         $Articles = TableRegistry::get('Articles');
-        $title = $Articles->schema()->column('title');
+        $title = $Articles->schema()->getColumn('title');
         $Articles->schema()->addColumn(
             'title',
             ['default' => '1'] + $title