MCPcopy Create free account
hub / github.com/Rello/analytics / AnalyticsMigratorTest

Class AnalyticsMigratorTest

tests/UserMigration/AnalyticsMigratorTest.php:10–72  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

8use PHPUnit\Framework\TestCase;
9
10class AnalyticsMigratorTest extends TestCase {
11 public function testCanImportAllowsMissingOptionalMigratorVersion(): void {
12 $importSource = $this->createImportSourceWithVersion(null);
13
14 $this->assertTrue($this->createMigrator()->canImport($importSource));
15 }
16
17 /**
18 * @dataProvider migratorVersions
19 */
20 public function testCanImportChecksMigratorVersion(?int $version, bool $expected): void {
21 $importSource = $this->createImportSourceWithVersion($version);
22
23 $this->assertSame($expected, $this->createMigrator()->canImport($importSource));
24 }
25
26 public function testCanImportRejectsUnreadableMigratorVersion(): void {
27 $importSource = $this->createMock(IImportSource::class);
28 $importSource->expects($this->once())
29 ->method('getMigratorVersion')
30 ->with('analytics')
31 ->willThrowException(new UserMigrationException('Unreadable migration metadata'));
32
33 $this->assertFalse($this->createMigrator()->canImport($importSource));
34 }
35
36 public function testNormalizeNullableIntPreservesNull(): void {
37 $migrator = $this->createMigrator();
38
39 $method = new \ReflectionMethod(AnalyticsMigrator::class, 'normalizeNullableInt');
40 $method->setAccessible(true);
41
42 $this->assertNull($method->invoke($migrator, null));
43 $this->assertNull($method->invoke($migrator, ''));
44 $this->assertSame(2, $method->invoke($migrator, 2));
45 $this->assertSame(2, $method->invoke($migrator, '2'));
46 }
47
48 public function migratorVersions(): array {
49 return [
50 'older version' => [0, true],
51 'current version' => [1, true],
52 'newer version' => [2, false],
53 ];
54 }
55
56 private function createMigrator(): AnalyticsMigrator {
57 return new AnalyticsMigrator(
58 $this->createMock(\OCP\IDBConnection::class),
59 new FakeL10N()
60 );
61 }
62
63 private function createImportSourceWithVersion(?int $version): IImportSource {
64 $importSource = $this->createMock(IImportSource::class);
65 $importSource->expects($this->once())
66 ->method('getMigratorVersion')
67 ->with('analytics')

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected