Browse Source

Test TableSchema instead of a deprecated Table class.

Robert Pustułka 8 years ago
parent
commit
275e24fbc5

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

@@ -312,7 +312,7 @@ SQL;
 
         $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',
@@ -400,7 +400,7 @@ SQL;
 
         $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 = [
@@ -1296,7 +1296,7 @@ SQL;
 
         $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,

+ 2 - 2
tests/TestCase/Database/Schema/PostgresSchemaTest.php

@@ -513,7 +513,7 @@ SQL;
 
         $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',
@@ -543,7 +543,7 @@ SQL;
 
         $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',

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

@@ -372,7 +372,7 @@ SQL;
                 '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));
@@ -411,7 +411,7 @@ SQL;
 
         $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',

+ 2 - 2
tests/TestCase/Database/Schema/SqlserverSchemaTest.php

@@ -274,7 +274,7 @@ SQL;
         $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);
@@ -472,7 +472,7 @@ SQL;
 
         $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' => [

+ 38 - 38
tests/TestCase/Database/Schema/TableTest.php

@@ -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());

+ 2 - 2
tests/TestCase/TestSuite/FixtureManagerTest.php

@@ -16,7 +16,7 @@ namespace Cake\Test\TestSuite;
 
 use Cake\Core\Exception\Exception as CakeException;
 use Cake\Core\Plugin;
-use Cake\Database\Schema\Table;
+use Cake\Database\Schema\TableSchema;
 use Cake\Datasource\ConnectionManager;
 use Cake\Log\Log;
 use Cake\TestSuite\Fixture\FixtureManager;
@@ -113,7 +113,7 @@ class FixtureManagerTest extends TestCase
             'stream' => $buffer
         ]);
 
-        $table = new Table('articles', [
+        $table = new TableSchema('articles', [
             'id' => ['type' => 'integer', 'unsigned' => true],
             'title' => ['type' => 'string', 'length' => 255],
         ]);

+ 7 - 7
tests/TestCase/TestSuite/TestFixtureTest.php

@@ -14,7 +14,7 @@
  */
 namespace Cake\Test\TestCase\TestSuite;
 
-use Cake\Database\Schema\Table;
+use Cake\Database\Schema\TableSchema;
 use Cake\Datasource\ConnectionManager;
 use Cake\Log\Log;
 use Cake\TestSuite\Fixture\TestFixture;
@@ -190,7 +190,7 @@ class TestFixtureTest extends TestCase
         $this->assertEquals('articles', $Fixture->table);
 
         $schema = $Fixture->getTableSchema();
-        $this->assertInstanceOf('Cake\Database\Schema\Table', $schema);
+        $this->assertInstanceOf('Cake\Database\Schema\TableSchema', $schema);
 
         $fields = $Fixture->fields;
         unset($fields['_constraints'], $fields['_indexes']);
@@ -275,7 +275,7 @@ class TestFixtureTest extends TestCase
     public function testInitNoImportNoFields()
     {
         $db = ConnectionManager::get('test');
-        $table = new Table('letters', [
+        $table = new TableSchema('letters', [
             'id' => ['type' => 'integer'],
             'letter' => ['type' => 'string', 'length' => 1]
         ]);
@@ -317,7 +317,7 @@ class TestFixtureTest extends TestCase
         $db = $this->getMockBuilder('Cake\Database\Connection')
             ->disableOriginalConstructor()
             ->getMock();
-        $table = $this->getMockBuilder('Cake\Database\Schema\Table')
+        $table = $this->getMockBuilder('Cake\Database\Schema\TableSchema')
             ->setConstructorArgs(['articles'])
             ->getMock();
         $table->expects($this->once())
@@ -349,7 +349,7 @@ class TestFixtureTest extends TestCase
         $db = $this->getMockBuilder('Cake\Database\Connection')
             ->disableOriginalConstructor()
             ->getMock();
-        $table = $this->getMockBuilder('Cake\Database\Schema\Table')
+        $table = $this->getMockBuilder('Cake\Database\Schema\TableSchema')
             ->setConstructorArgs(['articles'])
             ->getMock();
         $table->expects($this->once())
@@ -545,7 +545,7 @@ class TestFixtureTest extends TestCase
             ->with('sql')
             ->will($this->returnValue($statement));
 
-        $table = $this->getMockBuilder('Cake\Database\Schema\Table')
+        $table = $this->getMockBuilder('Cake\Database\Schema\TableSchema')
             ->setConstructorArgs(['articles'])
             ->getMock();
         $table->expects($this->once())
@@ -577,7 +577,7 @@ class TestFixtureTest extends TestCase
             ->with('sql')
             ->will($this->returnValue($statement));
 
-        $table = $this->getMockBuilder('Cake\Database\Schema\Table')
+        $table = $this->getMockBuilder('Cake\Database\Schema\TableSchema')
             ->setConstructorArgs(['articles'])
             ->getMock();
         $table->expects($this->once())