From de80a8a8d21738a75cf5ae81e2840f08663569fa Mon Sep 17 00:00:00 2001 From: Anna Larch Date: Tue, 26 May 2026 23:30:05 +0200 Subject: [PATCH] test(db): replace addToAssertionCount checkbox tests with DoesNotPerformAssertions and real assertions Signed-off-by: Anna Larch AI-Assisted-By: Claude Sonnet 4.6 --- tests/lib/DB/MigratorTest.php | 28 +++++++------------ .../lib/DB/QueryBuilder/QueryBuilderTest.php | 2 -- 2 files changed, 10 insertions(+), 20 deletions(-) diff --git a/tests/lib/DB/MigratorTest.php b/tests/lib/DB/MigratorTest.php index 78d28401383f1..28499e5827a6a 100644 --- a/tests/lib/DB/MigratorTest.php +++ b/tests/lib/DB/MigratorTest.php @@ -130,6 +130,7 @@ private function getSchemaConfig() { return $config; } + #[\PHPUnit\Framework\Attributes\DoesNotPerformAssertions] public function testUpgrade(): void { [$startSchema, $endSchema] = $this->getDuplicateKeySchemas(); $migrator = $this->getMigrator(); @@ -140,9 +141,9 @@ public function testUpgrade(): void { $this->connection->insert($this->tableName, ['id' => 3, 'name' => 'qwerty']); $migrator->migrate($endSchema); - $this->addToAssertionCount(1); } + #[\PHPUnit\Framework\Attributes\DoesNotPerformAssertions] public function testUpgradeDifferentPrefix(): void { $oldTablePrefix = $this->config->getSystemValueString('dbtableprefix', 'oc_'); @@ -158,7 +159,6 @@ public function testUpgradeDifferentPrefix(): void { $this->connection->insert($this->tableName, ['id' => 3, 'name' => 'qwerty']); $migrator->migrate($endSchema); - $this->addToAssertionCount(1); $this->config->setSystemValue('dbtableprefix', $oldTablePrefix); } @@ -172,14 +172,12 @@ public function testInsertAfterUpgrade(): void { $this->connection->insert($this->tableName, ['id' => 1, 'name' => 'foo']); $this->connection->insert($this->tableName, ['id' => 2, 'name' => 'bar']); - try { - $this->connection->insert($this->tableName, ['id' => 2, 'name' => 'qwerty']); - $this->fail('Expected duplicate key insert to fail'); - } catch (Exception $e) { - $this->addToAssertionCount(1); - } + + $this->expectException(Exception::class); + $this->connection->insert($this->tableName, ['id' => 2, 'name' => 'qwerty']); } + #[\PHPUnit\Framework\Attributes\DoesNotPerformAssertions] public function testAddingPrimaryKeyWithAutoIncrement(): void { $startSchema = new Schema([], [], $this->getSchemaConfig()); $table = $startSchema->createTable($this->tableName); @@ -196,10 +194,9 @@ public function testAddingPrimaryKeyWithAutoIncrement(): void { $migrator->migrate($startSchema); $migrator->migrate($endSchema); - - $this->addToAssertionCount(1); } + #[\PHPUnit\Framework\Attributes\DoesNotPerformAssertions] public function testReservedKeywords(): void { $startSchema = new Schema([], [], $this->getSchemaConfig()); $table = $startSchema->createTable($this->tableName); @@ -217,13 +214,12 @@ public function testReservedKeywords(): void { $migrator->migrate($startSchema); $migrator->migrate($endSchema); - - $this->addToAssertionCount(1); } /** * Test for nextcloud/server#36803 */ + #[\PHPUnit\Framework\Attributes\DoesNotPerformAssertions] public function testColumnCommentsInUpdate(): void { $startSchema = new Schema([], [], $this->getSchemaConfig()); $table = $startSchema->createTable($this->tableName); @@ -241,8 +237,6 @@ public function testColumnCommentsInUpdate(): void { $migrator->migrate($startSchema); $migrator->migrate($endSchema); - - $this->addToAssertionCount(1); } public function testAddingForeignKey(): void { @@ -305,12 +299,10 @@ public function testNotNullEmptyValuesFailOracle(int $parameterType, $value, str $this->expectException(\Doctrine\DBAL\Exception\NotNullConstraintViolationException::class); } - $this->connection->insert( + $this->assertSame(1, $this->connection->insert( $this->tableName, ['id' => 1, 'will_it_blend' => $value], ['id' => ParameterType::INTEGER, 'will_it_blend' => $parameterType], - ); - - $this->addToAssertionCount(1); + )); } } diff --git a/tests/lib/DB/QueryBuilder/QueryBuilderTest.php b/tests/lib/DB/QueryBuilder/QueryBuilderTest.php index 0014ce86420dc..49e33c6f08f3f 100644 --- a/tests/lib/DB/QueryBuilder/QueryBuilderTest.php +++ b/tests/lib/DB/QueryBuilder/QueryBuilderTest.php @@ -1154,7 +1154,6 @@ public function testGetLastInsertId(): void { $qB->getLastInsertId(); $this->fail('getLastInsertId() should throw an exception, when being called before insert()'); } catch (\BadMethodCallException $e) { - $this->addToAssertionCount(1); } $qB->insert('properties') @@ -1180,7 +1179,6 @@ public function testGetLastInsertId(): void { $qB->getLastInsertId(); $this->fail('getLastInsertId() should throw an exception, when being called after delete()'); } catch (\BadMethodCallException $e) { - $this->addToAssertionCount(1); } }