From 4aebedb078fbee676f67779d354f34c66ac44acb Mon Sep 17 00:00:00 2001 From: Josh Date: Mon, 24 Aug 2026 08:43:21 -0400 Subject: [PATCH 1/4] test(db): use realistic migration versions Signed-off-by: Josh --- tests/lib/DB/MigrationServiceTest.php | 57 +++++++++++++++++++-------- 1 file changed, 41 insertions(+), 16 deletions(-) diff --git a/tests/lib/DB/MigrationServiceTest.php b/tests/lib/DB/MigrationServiceTest.php index 72edd4aa4dfbf..b5e3ae760af3e 100644 --- a/tests/lib/DB/MigrationServiceTest.php +++ b/tests/lib/DB/MigrationServiceTest.php @@ -171,10 +171,10 @@ public function testExecuteStepWithoutSchemaChange(): void { public static function dataGetMigration(): array { return [ - ['current', '20170130180001'], - ['prev', '20170130180000'], - ['next', '20170130180002'], - ['latest', '20170130180003'], + ['current', '10000Date20200819121721'], + ['prev', '8000Date20200407115318'], + ['next', '20000Date20240717180417'], + ['latest', '20000Date20240718031959'], ]; } @@ -190,18 +190,29 @@ public function testGetMigration($alias, $expected): void { ->getMock(); $migrationService->expects($this->any())->method('getMigratedVersions')->willReturn( - ['20170130180000', '20170130180001'] + [ + '8000Date20200407115318', + '10000Date20200819121721', + ] ); $migrationService->expects($this->any())->method('findMigrations')->willReturn( - ['20170130180000' => 'X', '20170130180001' => 'Y', '20170130180002' => 'Z', '20170130180003' => 'A'] + [ + '20000Date20240718031959' => 'D', + '10000Date20200819121721' => 'B', + '8000Date20200407115318' => 'A', + '20000Date20240717180417' => 'C', + ] ); - $this->assertEquals( - ['20170130180000', '20170130180001', '20170130180002', '20170130180003'], - $migrationService->getAvailableVersions()); + $this->assertSame([ + '8000Date20200407115318', + '10000Date20200819121721', + '20000Date20240717180417', + '20000Date20240718031959', + ], $migrationService->getAvailableVersions()); $migration = $migrationService->getMigration($alias); - $this->assertEquals($expected, $migration); + $this->assertSame($expected, $migration); } public function testMigrate(): void { @@ -211,15 +222,26 @@ public function testMigrate(): void { ->getMock(); $migrationService->expects($this->any())->method('getMigratedVersions')->willReturn( - ['20170130180000', '20170130180001'] + [ + '8000Date20200407115318', + '10000Date20200819121721', + ] ); $migrationService->expects($this->any())->method('findMigrations')->willReturn( - ['20170130180000' => 'X', '20170130180001' => 'Y', '20170130180002' => 'Z', '20170130180003' => 'A'] + [ + '20000Date20240718031959' => 'D', + '10000Date20200819121721' => 'B', + '8000Date20200407115318' => 'A', + '20000Date20240717180417' => 'C', + ] ); - $this->assertEquals( - ['20170130180000', '20170130180001', '20170130180002', '20170130180003'], - $migrationService->getAvailableVersions()); + $this->assertSame([ + '8000Date20200407115318', + '10000Date20200819121721', + '20000Date20240717180417', + '20000Date20240718031959', + ], $migrationService->getAvailableVersions()); $calls = []; $migrationService @@ -230,7 +252,10 @@ public function testMigrate(): void { }); $migrationService->migrate(); - self::assertEquals(['20170130180002', '20170130180003'], $calls); + self::assertSame([ + '20000Date20240717180417', + '20000Date20240718031959', + ], $calls); } #[DataProvider('dataEnsureNamingConstraintsTableName')] From d1e6d7d3171a46a6ab63d61e0ec786f9bbc6ce1a Mon Sep 17 00:00:00 2001 From: Josh Date: Mon, 24 Aug 2026 09:02:18 -0400 Subject: [PATCH 2/4] 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 --- tests/lib/DB/MigrationServiceTest.php | 56 +++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) diff --git a/tests/lib/DB/MigrationServiceTest.php b/tests/lib/DB/MigrationServiceTest.php index b5e3ae760af3e..da5c5aa5ef9c5 100644 --- a/tests/lib/DB/MigrationServiceTest.php +++ b/tests/lib/DB/MigrationServiceTest.php @@ -215,6 +215,62 @@ public function testGetMigration($alias, $expected): void { $this->assertSame($expected, $migration); } + #[Group('DB')] + public function testGetMigratedVersionsSortsByVersionThenDate(): void { + /** @var Connection $db */ + $db = Server::get(IDBConnection::class); + $appId = 'migration_sort_' . bin2hex(random_bytes(8)); + + $migrationService = new class('testing', $db, $appId) extends MigrationService { + public function __construct( + string $appName, + Connection $connection, + private string $migrationApp, + ) { + parent::__construct($appName, $connection); + } + + #[\Override] + public function getApp(): string { + return $this->migrationApp; + } + }; + + // Ensure the migrations table exists before inserting the fixtures. + self::assertSame([], $migrationService->getMigratedVersions()); + + $versions = [ + '20000Date20240718031959', + '10000Date20200819121721', + '8000Date20200407115318', + '20000Date20240717180417', + ]; + + try { + foreach ($versions as $version) { + $db->insertIfNotExist('*PREFIX*migrations', [ + 'app' => $appId, + 'version' => $version, + ]); + } + + self::assertSame([ + '8000Date20200407115318', + '10000Date20200819121721', + '20000Date20240717180417', + '20000Date20240718031959', + ], $migrationService->getMigratedVersions()); + } finally { + $qb = $db->getQueryBuilder(); + $qb->delete('migrations') + ->where($qb->expr()->eq( + 'app', + $qb->createNamedParameter($appId), + )) + ->executeStatement(); + } + } + public function testMigrate(): void { $migrationService = $this->getMockBuilder(MigrationService::class) ->onlyMethods(['getMigratedVersions', 'findMigrations', 'executeStep']) From 4c4d8665cee47d54c03a15500d749c95b0e790bb Mon Sep 17 00:00:00 2001 From: Josh Date: Mon, 24 Aug 2026 09:05:57 -0400 Subject: [PATCH 3/4] test(db): chore - add imports to MigrationServiceTest Signed-off-by: Josh --- tests/lib/DB/MigrationServiceTest.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/lib/DB/MigrationServiceTest.php b/tests/lib/DB/MigrationServiceTest.php index da5c5aa5ef9c5..6da2bc0862a3d 100644 --- a/tests/lib/DB/MigrationServiceTest.php +++ b/tests/lib/DB/MigrationServiceTest.php @@ -22,7 +22,9 @@ use OCP\App\AppPathNotFoundException; use OCP\IDBConnection; use OCP\Migration\IMigrationStep; +use OCP\Server; use PHPUnit\Framework\Attributes\DataProvider; +use PHPUnit\Framework\Attributes\Group; use PHPUnit\Framework\Attributes\TestWith; use PHPUnit\Framework\MockObject\MockObject; use Psr\Log\LoggerInterface; From c4629f67b5c2c1a53a70603cc721b982fdcbd885 Mon Sep 17 00:00:00 2001 From: Josh Date: Mon, 24 Aug 2026 11:26:17 -0400 Subject: [PATCH 4/4] test(db): add DB dependency to migration class Signed-off-by: Josh --- tests/lib/DB/MigrationServiceTest.php | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/lib/DB/MigrationServiceTest.php b/tests/lib/DB/MigrationServiceTest.php index 6da2bc0862a3d..0366344a0cbb9 100644 --- a/tests/lib/DB/MigrationServiceTest.php +++ b/tests/lib/DB/MigrationServiceTest.php @@ -34,6 +34,7 @@ * * @package Test\DB */ +#[Group('DB')] class MigrationServiceTest extends \Test\TestCase { private Connection&MockObject $db;