aboutsummaryrefslogtreecommitdiffstats
path: root/tests/lib/DB/MigrationsTest.php
diff options
context:
space:
mode:
Diffstat (limited to 'tests/lib/DB/MigrationsTest.php')
-rw-r--r--tests/lib/DB/MigrationsTest.php52
1 files changed, 31 insertions, 21 deletions
diff --git a/tests/lib/DB/MigrationsTest.php b/tests/lib/DB/MigrationsTest.php
index 531e0a3805a..2b39b26d852 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();
@@ -175,7 +175,7 @@ class MigrationsTest extends \Test\TestCase {
$this->migrationService->executeStep('20170130180000');
}
- public function dataGetMigration() {
+ public static function dataGetMigration(): array {
return [
['current', '20170130180001'],
['prev', '20170130180000'],
@@ -185,13 +185,13 @@ class MigrationsTest extends \Test\TestCase {
}
/**
- * @dataProvider dataGetMigration
* @param string $alias
* @param string $expected
*/
+ #[\PHPUnit\Framework\Attributes\DataProvider('dataGetMigration')]
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): void {
+ $expected = array_shift($calls);
+ $this->assertEquals($expected, func_get_args());
+ });
$this->migrationService->migrate();
}
@@ -833,11 +844,10 @@ class MigrationsTest extends \Test\TestCase {
'class' => 'OCP\\Migration\\Attributes\\CreateTable',
'table' => 'new_table',
'description' => 'Table is used to store things, but also to get more things',
- 'notes' =>
- [
- 'this is a notice',
- 'and another one, if really needed'
- ],
+ 'notes' => [
+ 'this is a notice',
+ 'and another one, if really needed'
+ ],
'columns' => []
],
[