Skip to content

Commit cc1253a

Browse files
committed
Update the tests to the comparison logic
Signed-off-by: Joas Schilling <coding@schilljs.com>
1 parent f2b8937 commit cc1253a

File tree

1 file changed

+95
-15
lines changed

1 file changed

+95
-15
lines changed

tests/lib/DB/MigrationsTest.php

Lines changed: 95 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
use Doctrine\DBAL\Schema\ForeignKeyConstraint;
1717
use Doctrine\DBAL\Schema\Index;
1818
use Doctrine\DBAL\Schema\Schema;
19+
use Doctrine\DBAL\Schema\SchemaException;
1920
use Doctrine\DBAL\Schema\Sequence;
2021
use Doctrine\DBAL\Schema\Table;
2122
use OC\DB\Connection;
@@ -102,13 +103,12 @@ public function testExecuteStepWithSchemaChange() {
102103
->method('migrateToSchema');
103104

104105
$wrappedSchema = $this->createMock(Schema::class);
105-
// TODO re-enable once stable14 is branched of: https://github.com/nextcloud/server/issues/10518
106-
/*$wrappedSchema->expects($this->once())
106+
$wrappedSchema->expects($this->once())
107107
->method('getTables')
108108
->willReturn([]);
109109
$wrappedSchema->expects($this->once())
110110
->method('getSequences')
111-
->willReturn([]);*/
111+
->willReturn([]);
112112

113113
$schemaResult = $this->createMock(SchemaWrapper::class);
114114
$schemaResult->expects($this->once())
@@ -239,12 +239,12 @@ public function testEnsureOracleIdentifierLengthLimitValid() {
239239
->willReturn(\str_repeat('a', 30));
240240

241241
$table = $this->createMock(Table::class);
242-
$table->expects($this->once())
242+
$table->expects($this->atLeastOnce())
243243
->method('getName')
244244
->willReturn(\str_repeat('a', 30));
245245

246246
$sequence = $this->createMock(Sequence::class);
247-
$sequence->expects($this->once())
247+
$sequence->expects($this->atLeastOnce())
248248
->method('getName')
249249
->willReturn(\str_repeat('a', 30));
250250

@@ -269,7 +269,15 @@ public function testEnsureOracleIdentifierLengthLimitValid() {
269269
->method('getSequences')
270270
->willReturn([$sequence]);
271271

272-
self::invokePrivate($this->migrationService, 'ensureOracleIdentifierLengthLimit', [$schema, 3]);
272+
$sourceSchema = $this->createMock(Schema::class);
273+
$sourceSchema->expects($this->any())
274+
->method('getTable')
275+
->willThrowException(new SchemaException());
276+
$sourceSchema->expects($this->any())
277+
->method('hasSequence')
278+
->willReturn(false);
279+
280+
self::invokePrivate($this->migrationService, 'ensureOracleIdentifierLengthLimit', [$sourceSchema, $schema, 3]);
273281
}
274282

275283
public function testEnsureOracleIdentifierLengthLimitValidWithPrimaryKey() {
@@ -304,7 +312,15 @@ public function testEnsureOracleIdentifierLengthLimitValidWithPrimaryKey() {
304312
->method('getSequences')
305313
->willReturn([]);
306314

307-
self::invokePrivate($this->migrationService, 'ensureOracleIdentifierLengthLimit', [$schema, 3]);
315+
$sourceSchema = $this->createMock(Schema::class);
316+
$sourceSchema->expects($this->any())
317+
->method('getTable')
318+
->willThrowException(new SchemaException());
319+
$sourceSchema->expects($this->any())
320+
->method('hasSequence')
321+
->willReturn(false);
322+
323+
self::invokePrivate($this->migrationService, 'ensureOracleIdentifierLengthLimit', [$sourceSchema, $schema, 3]);
308324
}
309325

310326
public function testEnsureOracleIdentifierLengthLimitValidWithPrimaryKeyDefault() {
@@ -349,7 +365,15 @@ public function testEnsureOracleIdentifierLengthLimitValidWithPrimaryKeyDefault(
349365
->method('getSequences')
350366
->willReturn([]);
351367

352-
self::invokePrivate($this->migrationService, 'ensureOracleIdentifierLengthLimit', [$schema, 3]);
368+
$sourceSchema = $this->createMock(Schema::class);
369+
$sourceSchema->expects($this->any())
370+
->method('getTable')
371+
->willThrowException(new SchemaException());
372+
$sourceSchema->expects($this->any())
373+
->method('hasSequence')
374+
->willReturn(false);
375+
376+
self::invokePrivate($this->migrationService, 'ensureOracleIdentifierLengthLimit', [$sourceSchema, $schema, 3]);
353377
}
354378

355379
/**
@@ -366,7 +390,15 @@ public function testEnsureOracleIdentifierLengthLimitTooLongTableName() {
366390
->method('getTables')
367391
->willReturn([$table]);
368392

369-
self::invokePrivate($this->migrationService, 'ensureOracleIdentifierLengthLimit', [$schema, 3]);
393+
$sourceSchema = $this->createMock(Schema::class);
394+
$sourceSchema->expects($this->any())
395+
->method('getTable')
396+
->willThrowException(new SchemaException());
397+
$sourceSchema->expects($this->any())
398+
->method('hasSequence')
399+
->willReturn(false);
400+
401+
self::invokePrivate($this->migrationService, 'ensureOracleIdentifierLengthLimit', [$sourceSchema, $schema, 3]);
370402
}
371403

372404
/**
@@ -411,7 +443,15 @@ public function testEnsureOracleIdentifierLengthLimitTooLongPrimaryWithDefault()
411443
->method('getTables')
412444
->willReturn([$table]);
413445

414-
self::invokePrivate($this->migrationService, 'ensureOracleIdentifierLengthLimit', [$schema, 3]);
446+
$sourceSchema = $this->createMock(Schema::class);
447+
$sourceSchema->expects($this->any())
448+
->method('getTable')
449+
->willThrowException(new SchemaException());
450+
$sourceSchema->expects($this->any())
451+
->method('hasSequence')
452+
->willReturn(false);
453+
454+
self::invokePrivate($this->migrationService, 'ensureOracleIdentifierLengthLimit', [$sourceSchema, $schema, 3]);
415455
}
416456

417457
/**
@@ -446,7 +486,15 @@ public function testEnsureOracleIdentifierLengthLimitTooLongPrimaryWithName() {
446486
->method('getTables')
447487
->willReturn([$table]);
448488

449-
self::invokePrivate($this->migrationService, 'ensureOracleIdentifierLengthLimit', [$schema, 3]);
489+
$sourceSchema = $this->createMock(Schema::class);
490+
$sourceSchema->expects($this->any())
491+
->method('getTable')
492+
->willThrowException(new SchemaException());
493+
$sourceSchema->expects($this->any())
494+
->method('hasSequence')
495+
->willReturn(false);
496+
497+
self::invokePrivate($this->migrationService, 'ensureOracleIdentifierLengthLimit', [$sourceSchema, $schema, 3]);
450498
}
451499

452500
/**
@@ -472,7 +520,15 @@ public function testEnsureOracleIdentifierLengthLimitTooLongColumnName() {
472520
->method('getTables')
473521
->willReturn([$table]);
474522

475-
self::invokePrivate($this->migrationService, 'ensureOracleIdentifierLengthLimit', [$schema, 3]);
523+
$sourceSchema = $this->createMock(Schema::class);
524+
$sourceSchema->expects($this->any())
525+
->method('getTable')
526+
->willThrowException(new SchemaException());
527+
$sourceSchema->expects($this->any())
528+
->method('hasSequence')
529+
->willReturn(false);
530+
531+
self::invokePrivate($this->migrationService, 'ensureOracleIdentifierLengthLimit', [$sourceSchema, $schema, 3]);
476532
}
477533

478534
/**
@@ -501,7 +557,15 @@ public function testEnsureOracleIdentifierLengthLimitTooLongIndexName() {
501557
->method('getTables')
502558
->willReturn([$table]);
503559

504-
self::invokePrivate($this->migrationService, 'ensureOracleIdentifierLengthLimit', [$schema, 3]);
560+
$sourceSchema = $this->createMock(Schema::class);
561+
$sourceSchema->expects($this->any())
562+
->method('getTable')
563+
->willThrowException(new SchemaException());
564+
$sourceSchema->expects($this->any())
565+
->method('hasSequence')
566+
->willReturn(false);
567+
568+
self::invokePrivate($this->migrationService, 'ensureOracleIdentifierLengthLimit', [$sourceSchema, $schema, 3]);
505569
}
506570

507571
/**
@@ -533,7 +597,15 @@ public function testEnsureOracleIdentifierLengthLimitTooLongForeignKeyName() {
533597
->method('getTables')
534598
->willReturn([$table]);
535599

536-
self::invokePrivate($this->migrationService, 'ensureOracleIdentifierLengthLimit', [$schema, 3]);
600+
$sourceSchema = $this->createMock(Schema::class);
601+
$sourceSchema->expects($this->any())
602+
->method('getTable')
603+
->willThrowException(new SchemaException());
604+
$sourceSchema->expects($this->any())
605+
->method('hasSequence')
606+
->willReturn(false);
607+
608+
self::invokePrivate($this->migrationService, 'ensureOracleIdentifierLengthLimit', [$sourceSchema, $schema, 3]);
537609
}
538610

539611
/**
@@ -553,6 +625,14 @@ public function testEnsureOracleIdentifierLengthLimitTooLongSequenceName() {
553625
->method('getSequences')
554626
->willReturn([$sequence]);
555627

556-
self::invokePrivate($this->migrationService, 'ensureOracleIdentifierLengthLimit', [$schema, 3]);
628+
$sourceSchema = $this->createMock(Schema::class);
629+
$sourceSchema->expects($this->any())
630+
->method('getTable')
631+
->willThrowException(new SchemaException());
632+
$sourceSchema->expects($this->any())
633+
->method('hasSequence')
634+
->willReturn(false);
635+
636+
self::invokePrivate($this->migrationService, 'ensureOracleIdentifierLengthLimit', [$sourceSchema, $schema, 3]);
557637
}
558638
}

0 commit comments

Comments
 (0)