From: Joas Schilling Date: Thu, 10 Mar 2022 13:04:04 +0000 (+0100) Subject: Add a test for primary keys X-Git-Tag: v24.0.0beta1~61^2 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=refs%2Fpull%2F31513%2Fhead;p=nextcloud-server.git Add a test for primary keys Signed-off-by: Joas Schilling --- diff --git a/tests/lib/DB/MigrationsTest.php b/tests/lib/DB/MigrationsTest.php index 507f3d0e228..f22de8c5e6e 100644 --- a/tests/lib/DB/MigrationsTest.php +++ b/tests/lib/DB/MigrationsTest.php @@ -246,6 +246,8 @@ class MigrationsTest extends \Test\TestCase { ->method('getName') ->willReturn(\str_repeat('a', 30)); + $primaryKey = $this->createMock(Index::class); + $table->expects($this->once()) ->method('getColumns') ->willReturn([$column]); @@ -257,7 +259,7 @@ class MigrationsTest extends \Test\TestCase { ->willReturn([$foreignKey]); $table->expects($this->once()) ->method('getPrimaryKey') - ->willReturn(null); + ->willReturn($primaryKey); $schema = $this->createMock(Schema::class); $schema->expects($this->once()) @@ -607,6 +609,46 @@ class MigrationsTest extends \Test\TestCase { } + public function testEnsureOracleConstraintsNoPrimaryKey() { + $this->expectException(\InvalidArgumentException::class); + + $table = $this->createMock(Table::class); + $table->expects($this->atLeastOnce()) + ->method('getName') + ->willReturn(\str_repeat('a', 30)); + $table->expects($this->once()) + ->method('getColumns') + ->willReturn([]); + $table->expects($this->once()) + ->method('getIndexes') + ->willReturn([]); + $table->expects($this->once()) + ->method('getForeignKeys') + ->willReturn([]); + $table->expects($this->once()) + ->method('getPrimaryKey') + ->willReturn(null); + + $schema = $this->createMock(Schema::class); + $schema->expects($this->once()) + ->method('getTables') + ->willReturn([$table]); + $schema->expects($this->once()) + ->method('getSequences') + ->willReturn([]); + + $sourceSchema = $this->createMock(Schema::class); + $sourceSchema->expects($this->any()) + ->method('getTable') + ->willThrowException(new SchemaException()); + $sourceSchema->expects($this->any()) + ->method('hasSequence') + ->willReturn(false); + + self::invokePrivate($this->migrationService, 'ensureOracleConstraints', [$sourceSchema, $schema, 3]); + } + + public function testEnsureOracleConstraintsTooLongSequenceName() { $this->expectException(\InvalidArgumentException::class);