Code Duplication    Length = 34-35 lines in 3 locations

tests/Database/DatabaseTest.php 1 location

@@ 20-54 (lines=35) @@
17
     * @covers Database::hasTable
18
     * @covers Database::removeTable
19
     */
20
    public function testTables()
21
    {
22
        $database = new TestDatabase();
23
        $this->assertCount(0, $database->getTables());
24
25
        $table = new FirstTestTable();
26
27
        for ($i = 0; $i < 2; $i++) {
28
            try {
29
                $database->createTable($table);
30
            } catch (InvalidArgumentException $e) {
31
                $this->assertGreaterThan(0, $i);
32
            }
33
34
            $this->assertCount(1, $database->getTables());
35
            $this->assertEquals($table, $database->getTables()[FirstTestTable::getName()]);
36
            $this->assertEquals($table, $database->getTable(FirstTestTable::getName()));
37
            $this->assertTrue($database->hasTable(FirstTestTable::getName()));
38
        }
39
40
        for ($i = 0; $i < 2; $i++) {
41
            try {
42
                $database->removeTable($table);
43
            } catch (InvalidArgumentException $e) {
44
                $this->assertGreaterThan(0, $i);
45
            }
46
            $this->assertCount(0, $database->getTables());
47
        }
48
49
        for ($i = 0; $i < 2; $i++) {
50
            $database->createTableIfNotExists($table);
51
            $this->assertCount(1, $database->getTables());
52
            $this->assertEquals($table, $database->getTable(FirstTestTable::getName()));
53
        }
54
    }
55
}
56

tests/Database/SchemaTest.php 1 location

@@ 24-57 (lines=34) @@
21
     * @covers Schema::removeDatabase
22
     * @covers Schema::createDatabaseIfNotExists
23
     */
24
    public function testCreateDatabase()
25
    {
26
        $schema = new Schema();
27
        $this->assertCount(0, $schema->getDatabases());
28
29
        $database = new TestDatabase();
30
31
        for ($i = 0; $i < 2; $i++) {
32
            try {
33
                $schema->createDatabase($database);
34
            } catch (InvalidArgumentException $e) {
35
                $this->assertGreaterThan(0, $i);
36
            }
37
            $this->assertCount(1, $schema->getDatabases());
38
            $this->assertEquals($database, $schema->getDatabases()[TestDatabase::getName()]);
39
            $this->assertEquals($database, $schema->getDatabase(TestDatabase::getName()));
40
            $this->assertTrue($schema->hasDatabase(TestDatabase::getName()));
41
        }
42
43
        for ($i = 0; $i < 2; $i++) {
44
            try {
45
                $schema->removeDatabase($database);
46
            } catch (InvalidArgumentException $e) {
47
                $this->assertGreaterThan(0, $i);
48
            }
49
            $this->assertCount(0, $schema->getDatabases());
50
        }
51
52
        for ($i = 0; $i < 2; $i++) {
53
            $schema->createDatabaseIfNotExists($database);
54
            $this->assertCount(1, $schema->getDatabases());
55
            $this->assertTrue($schema->hasDatabase(TestDatabase::getName()));
56
        }
57
    }
58
59
    /**
60
     * @covers Schema::generateOutputXml

tests/Database/TableTest.php 1 location

@@ 22-56 (lines=35) @@
19
     * @covers Table::hasColumn
20
     * @covers Table::removeColumn
21
     */
22
    public function testColumnMethods()
23
    {
24
        $table = new FirstTestTable();
25
        $this->assertCount(0, $table->getColumns());
26
27
        $column = new TestColumn();
28
29
        for ($i = 0; $i < 2; $i++) {
30
            try {
31
                $table->createColumn($column);
32
            } catch (InvalidArgumentException $e) {
33
                $this->assertGreaterThan(0, $i);
34
            }
35
36
            $this->assertCount(1, $table->getColumns());
37
            $this->assertEquals($column, $table->getColumns()[TestColumn::getName()]);
38
            $this->assertEquals($column, $table->getColumn(TestColumn::getName()));
39
            $this->assertTrue($table->hasColumn(TestColumn::getName()));
40
        }
41
42
        for ($i = 0; $i < 2; $i++) {
43
            try {
44
                $table->removeColumn($column);
45
            } catch (InvalidArgumentException $e) {
46
                $this->assertGreaterThan(0, $i);
47
            }
48
            $this->assertCount(0, $table->getColumns());
49
        }
50
51
        for ($i = 0; $i < 2; $i++) {
52
            $table->createColumnIfNotExists($column);
53
            $this->assertCount(1, $table->getColumns());
54
            $this->assertEquals($column, $table->getColumn(TestColumn::getName()));
55
        }
56
    }
57
58
    /**
59
     * @covers Table::addForeignKey