diff options
author | Joas Schilling <213943+nickvergessen@users.noreply.github.com> | 2022-03-15 10:53:11 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-03-15 10:53:11 +0100 |
commit | 04a4562a01e3594797ff4179769f3f9a45c3d9d2 (patch) | |
tree | db1d4dba8e4843ad63242f8e014a62b5184f10ad /tests | |
parent | 1ae6b2be71acecca486ce24f61a713ad6a669fc8 (diff) | |
parent | 1970d3dc9ab599e67ad1a0393fc5707ec283cf08 (diff) | |
download | nextcloud-server-04a4562a01e3594797ff4179769f3f9a45c3d9d2.tar.gz nextcloud-server-04a4562a01e3594797ff4179769f3f9a45c3d9d2.zip |
Merge pull request #31513 from nextcloud/techdebt/noid/enforce-primary-keys
Enforce primary keys as they are required to be performant in MySQL c…
Diffstat (limited to 'tests')
-rw-r--r-- | tests/lib/DB/MigrationsTest.php | 44 |
1 files changed, 43 insertions, 1 deletions
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); |