Skip to content

Commit

Permalink
Added tests for checking always apply files
Browse files Browse the repository at this point in the history
  • Loading branch information
FaimMedia committed Apr 30, 2024
1 parent 97365a9 commit c945dcb
Showing 1 changed file with 65 additions and 0 deletions.
65 changes: 65 additions & 0 deletions test/Migration/MigrationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,71 @@ public function testVersion0Migration(): void
$this->migration->run('0000');
}

/**
* Test migration version 0 that should always run
*/
public function testAlwaysRunMigration(): void
{
$this->migration->run('0001');

parent::assertTrue(parent::tableExists('always_run'));
}

/**
* Test migration version 0 when table is removed
*/
public function testAlwaysRunMigrationWhenTableRemoval(): void
{
$this->testAlwaysRunMigration();

$this->pdo->query('DROP TABLE "always_run"');

parent::assertFalse(parent::tableExists('always_run'));

$this->migration->run("0001");

parent::assertTrue(parent::tableExists('always_run'));
}

/**
* Test migration version 0 when value is changed
*/
public function testAlwaysRunMigrationWhenValueIsChanged(): void
{
$defaultValue = 'Test value 2';

$this->testAlwaysRunMigration();

parent::assertSame($defaultValue, $this->getValueFromAlwaysRun());

$randomValue = 'New random string: ' . md5(uniqid(time()));

$prepare = $this->pdo->prepare('UPDATE "always_run" SET "col2" = ? WHERE "col1" = ?');
$prepare->execute([
$randomValue,
'key2',
]);

parent::assertSame($randomValue, $this->getValueFromAlwaysRun());

$this->testAlwaysRunMigration();

parent::assertSame($defaultValue, $this->getValueFromAlwaysRun());
}

/**
* Get value from always run key2 table
*/
protected function getValueFromAlwaysRun(): ?string
{
$prepare = $this->pdo->prepare('SELECT "col2" FROM "always_run" WHERE "col1" = ?');
$prepare->execute([
'key2',
]);

return $prepare->fetchColumn(0);
}

/**
* Full migration test
*/
Expand Down

0 comments on commit c945dcb

Please sign in to comment.