Add store method to list all migrations

[MAILPOET-4466]
This commit is contained in:
Jan Jakes
2022-10-27 16:18:50 +02:00
committed by Aschepikov
parent b10cd32449
commit 17ab79aa6f
2 changed files with 38 additions and 0 deletions

View File

@@ -44,6 +44,14 @@ class Store {
", [$error ?: 'Unknown error', $name]); ", [$error ?: 'Unknown error', $name]);
} }
public function getAll(): array {
return $this->connection->fetchAllAssociative("
SELECT *
FROM {$this->table}
ORDER BY id ASC
");
}
public function ensureMigrationsTable(): void { public function ensureMigrationsTable(): void {
$collate = Env::$dbCharsetCollate; $collate = Env::$dbCharsetCollate;
$this->connection->executeStatement(" $this->connection->executeStatement("

View File

@@ -82,6 +82,36 @@ class StoreTest extends MailPoetTest {
$this->assertSame($data['error'], 'test-error'); $this->assertSame($data['error'], 'test-error');
} }
public function testItListsAllMigrations(): void {
$this->store->ensureMigrationsTable();
$this->store->startMigration('Started');
$this->store->startMigration('Completed');
$this->store->completeMigration('Completed');
$this->store->startMigration('Failed');
$this->store->failMigration('Failed', 'test-error');
$migrations = $this->store->getAll();
$this->assertCount(3, $migrations);
$data = $migrations[0];
$this->assertSame('Started', $data['name']);
$this->assertStringMatchesFormat(self::DATE_TIME_FORMAT, $data['started_at']);
$this->assertNull($data['completed_at']);
$this->assertNull($data['error']);
$data = $migrations[1];
$this->assertSame('Completed', $data['name']);
$this->assertStringMatchesFormat(self::DATE_TIME_FORMAT, $data['started_at']);
$this->assertStringMatchesFormat(self::DATE_TIME_FORMAT, $data['completed_at']);
$this->assertNull($data['error']);
$data = $migrations[2];
$this->assertSame('Failed', $data['name']);
$this->assertStringMatchesFormat(self::DATE_TIME_FORMAT, $data['started_at']);
$this->assertStringMatchesFormat(self::DATE_TIME_FORMAT, $data['completed_at']);
$this->assertSame($data['error'], 'test-error');
}
public function _after() { public function _after() {
parent::_after(); parent::_after();
$this->connection->executeStatement("DROP TABLE IF EXISTS {$this->table}"); $this->connection->executeStatement("DROP TABLE IF EXISTS {$this->table}");