diff options
Diffstat (limited to 'tests/lib/DB/MigrationsTest.php')
-rw-r--r-- | tests/lib/DB/MigrationsTest.php | 39 |
1 files changed, 25 insertions, 14 deletions
diff --git a/tests/lib/DB/MigrationsTest.php b/tests/lib/DB/MigrationsTest.php index 531e0a3805a..57ffb91e37e 100644 --- a/tests/lib/DB/MigrationsTest.php +++ b/tests/lib/DB/MigrationsTest.php @@ -93,7 +93,7 @@ class MigrationsTest extends \Test\TestCase { $this->expectExceptionMessage('Migration step \'X\' is unknown'); $this->migrationService = $this->getMockBuilder(MigrationService::class) - ->setMethods(['findMigrations']) + ->onlyMethods(['findMigrations']) ->setConstructorArgs(['testing', $this->db]) ->getMock(); $this->migrationService->expects($this->any())->method('findMigrations')->willReturn( @@ -134,7 +134,7 @@ class MigrationsTest extends \Test\TestCase { ->method('postSchemaChange'); $this->migrationService = $this->getMockBuilder(MigrationService::class) - ->setMethods(['createInstance']) + ->onlyMethods(['createInstance']) ->setConstructorArgs(['testing', $this->db]) ->getMock(); @@ -164,7 +164,7 @@ class MigrationsTest extends \Test\TestCase { ->method('postSchemaChange'); $this->migrationService = $this->getMockBuilder(MigrationService::class) - ->setMethods(['createInstance']) + ->onlyMethods(['createInstance']) ->setConstructorArgs(['testing', $this->db]) ->getMock(); @@ -191,7 +191,7 @@ class MigrationsTest extends \Test\TestCase { */ public function testGetMigration($alias, $expected): void { $this->migrationService = $this->getMockBuilder(MigrationService::class) - ->setMethods(['getMigratedVersions', 'findMigrations']) + ->onlyMethods(['getMigratedVersions', 'findMigrations']) ->setConstructorArgs(['testing', $this->db]) ->getMock(); $this->migrationService->expects($this->any())->method('getMigratedVersions')->willReturn( @@ -211,22 +211,33 @@ class MigrationsTest extends \Test\TestCase { public function testMigrate(): void { $this->migrationService = $this->getMockBuilder(MigrationService::class) - ->setMethods(['getMigratedVersions', 'findMigrations', 'executeStep']) + ->onlyMethods(['getMigratedVersions', 'findMigrations', 'executeStep']) ->setConstructorArgs(['testing', $this->db]) ->getMock(); - $this->migrationService->expects($this->any())->method('getMigratedVersions')->willReturn( - ['20170130180000', '20170130180001'] - ); - $this->migrationService->expects($this->any())->method('findMigrations')->willReturn( - ['20170130180000' => 'X', '20170130180001' => 'Y', '20170130180002' => 'Z', '20170130180003' => 'A'] - ); + $this->migrationService->method('getMigratedVersions') + ->willReturn( + ['20170130180000', '20170130180001'] + ); + $this->migrationService->method('findMigrations') + ->willReturn( + ['20170130180000' => 'X', '20170130180001' => 'Y', '20170130180002' => 'Z', '20170130180003' => 'A'] + ); $this->assertEquals( ['20170130180000', '20170130180001', '20170130180002', '20170130180003'], - $this->migrationService->getAvailableVersions()); + $this->migrationService->getAvailableVersions() + ); - $this->migrationService->expects($this->exactly(2))->method('executeStep') - ->withConsecutive(['20170130180002'], ['20170130180003']); + $calls = [ + ['20170130180002', false], + ['20170130180003', false], + ]; + $this->migrationService->expects($this->exactly(2)) + ->method('executeStep') + ->willReturnCallback(function () use (&$calls) { + $expected = array_shift($calls); + $this->assertEquals($expected, func_get_args()); + }); $this->migrationService->migrate(); } |