Skip to content

Commit 6fae50f

Browse files
committed
test(db): add coverage for getMigratedVersions()
A follow-up to #47515 that exercises getMigratedVersions() for regressions for real, since the existing tests mock it and don't test it. Assisted-by: Copilot:gpt-5.6-sol Signed-off-by: Josh <josh.t.richards@gmail.com>
1 parent 19c61af commit 6fae50f

1 file changed

Lines changed: 56 additions & 0 deletions

File tree

tests/lib/DB/MigrationServiceTest.php

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,62 @@ public function testGetMigration($alias, $expected): void {
215215
$this->assertSame($expected, $migration);
216216
}
217217

218+
#[Group('DB')]
219+
public function testGetMigratedVersionsSortsByVersionThenDate(): void {
220+
/** @var Connection $db */
221+
$db = Server::get(IDBConnection::class);
222+
$appId = 'migration_sort_' . bin2hex(random_bytes(8));
223+
224+
$migrationService = new class('testing', $db, $appId) extends MigrationService {
225+
public function __construct(
226+
string $appName,
227+
Connection $connection,
228+
private string $migrationApp,
229+
) {
230+
parent::__construct($appName, $connection);
231+
}
232+
233+
#[\Override]
234+
public function getApp(): string {
235+
return $this->migrationApp;
236+
}
237+
};
238+
239+
// Ensure the migrations table exists before inserting the fixtures.
240+
self::assertSame([], $migrationService->getMigratedVersions());
241+
242+
$versions = [
243+
'20000Date20240718031959',
244+
'10000Date20200819121721',
245+
'8000Date20200407115318',
246+
'20000Date20240717180417',
247+
];
248+
249+
try {
250+
foreach ($versions as $version) {
251+
$db->insertIfNotExist('*PREFIX*migrations', [
252+
'app' => $appId,
253+
'version' => $version,
254+
]);
255+
}
256+
257+
self::assertSame([
258+
'8000Date20200407115318',
259+
'10000Date20200819121721',
260+
'20000Date20240717180417',
261+
'20000Date20240718031959',
262+
], $migrationService->getMigratedVersions());
263+
} finally {
264+
$qb = $db->getQueryBuilder();
265+
$qb->delete('migrations')
266+
->where($qb->expr()->eq(
267+
'app',
268+
$qb->createNamedParameter($appId),
269+
))
270+
->executeStatement();
271+
}
272+
}
273+
218274
public function testMigrate(): void {
219275
$migrationService = $this->getMockBuilder(MigrationService::class)
220276
->onlyMethods(['getMigratedVersions', 'findMigrations', 'executeStep'])

0 commit comments

Comments
 (0)