Skip to content

Commit

Permalink
Adjust some database statement related tests (#22356)
Browse files Browse the repository at this point in the history
  • Loading branch information
sgiehl authored Jul 2, 2024
1 parent 1cbd682 commit a391178
Showing 1 changed file with 23 additions and 4 deletions.
27 changes: 23 additions & 4 deletions tests/PHPUnit/Integration/Updater/Migration/Db/FactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
namespace Piwik\Tests\Integration\Updater\Migration\Db;

use Piwik\Common;
use Piwik\Db\Schema;
use Piwik\Tests\Framework\TestCase\IntegrationTestCase;
use Piwik\Updater\Migration\Db\AddColumn;
use Piwik\Updater\Migration\Db\AddColumns;
Expand Down Expand Up @@ -94,7 +95,9 @@ public function testCreateTableForwardsParameters()
$migration = $this->createTable();

$table = $this->testTablePrefixed;
$this->assertSame("CREATE TABLE `$table` (`column` INT(10) DEFAULT 0, `column2` VARCHAR(255)) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 ROW_FORMAT=DYNAMIC;", '' . $migration);
$createOptions = Schema::getInstance()->getTableCreateOptions();
self::assertStringContainsString('ROW_FORMAT=DYNAMIC', $createOptions);
$this->assertSame("CREATE TABLE `$table` (`column` INT(10) DEFAULT 0, `column2` VARCHAR(255)) $createOptions;", '' . $migration);
}


Expand All @@ -103,7 +106,9 @@ public function testCreateTableWithPrimaryKey()
$migration = $this->createTable('column2');

$table = $this->testTablePrefixed;
$this->assertSame("CREATE TABLE `$table` (`column` INT(10) DEFAULT 0, `column2` VARCHAR(255), PRIMARY KEY ( `column2` )) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 ROW_FORMAT=DYNAMIC;", '' . $migration);
$createOptions = Schema::getInstance()->getTableCreateOptions();
self::assertStringContainsString('ROW_FORMAT=DYNAMIC', $createOptions);
$this->assertSame("CREATE TABLE `$table` (`column` INT(10) DEFAULT 0, `column2` VARCHAR(255), PRIMARY KEY ( `column2` )) $createOptions;", '' . $migration);
}

public function testDropTableReturnsDropTableInstance()
Expand Down Expand Up @@ -171,15 +176,29 @@ public function testAddColumnsForwardsParameters()
$migration = $this->addColumns('columnafter');

$table = $this->testTablePrefixed;
$this->assertSame("ALTER TABLE `$table` ADD COLUMN `column1` INT(10) DEFAULT 0 AFTER `columnafter`, ADD COLUMN `column2` VARCHAR(10) DEFAULT \"\" AFTER `column1`;", '' . $migration);

$expectedStatement = "ALTER TABLE `$table` ADD COLUMN `column1` INT(10) DEFAULT 0 AFTER `columnafter`, ADD COLUMN `column2` VARCHAR(10) DEFAULT \"\" AFTER `column1`;";

if (!Schema::getInstance()->supportsComplexColumnUpdates()) {
$expectedStatement = "ALTER TABLE `$table` ADD COLUMN `column1` INT(10) DEFAULT 0 AFTER `columnafter`;ALTER TABLE `$table` ADD COLUMN `column2` VARCHAR(10) DEFAULT \"\" AFTER `column1`;";
}

$this->assertSame($expectedStatement, '' . $migration);
}

public function testAddColumnsNoAfterColumn()
{
$migration = $this->addColumns(null);

$table = $this->testTablePrefixed;
$this->assertSame("ALTER TABLE `$table` ADD COLUMN `column1` INT(10) DEFAULT 0, ADD COLUMN `column2` VARCHAR(10) DEFAULT \"\";", '' . $migration);

$expectedStatement = "ALTER TABLE `$table` ADD COLUMN `column1` INT(10) DEFAULT 0, ADD COLUMN `column2` VARCHAR(10) DEFAULT \"\";";

if (!Schema::getInstance()->supportsComplexColumnUpdates()) {
$expectedStatement = "ALTER TABLE `$table` ADD COLUMN `column1` INT(10) DEFAULT 0;ALTER TABLE `$table` ADD COLUMN `column2` VARCHAR(10) DEFAULT \"\";";
}

$this->assertSame($expectedStatement, '' . $migration);
}

public function testChangeColumnReturnsChangeColumnInstance()
Expand Down

0 comments on commit a391178

Please sign in to comment.