Skip to content

Commit de80a8a

Browse files
committed
test(db): replace addToAssertionCount checkbox tests with DoesNotPerformAssertions and real assertions
Signed-off-by: Anna Larch <anna@nextcloud.com> AI-Assisted-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 492a42b commit de80a8a

2 files changed

Lines changed: 10 additions & 20 deletions

File tree

tests/lib/DB/MigratorTest.php

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ private function getSchemaConfig() {
130130
return $config;
131131
}
132132

133+
#[\PHPUnit\Framework\Attributes\DoesNotPerformAssertions]
133134
public function testUpgrade(): void {
134135
[$startSchema, $endSchema] = $this->getDuplicateKeySchemas();
135136
$migrator = $this->getMigrator();
@@ -140,9 +141,9 @@ public function testUpgrade(): void {
140141
$this->connection->insert($this->tableName, ['id' => 3, 'name' => 'qwerty']);
141142

142143
$migrator->migrate($endSchema);
143-
$this->addToAssertionCount(1);
144144
}
145145

146+
#[\PHPUnit\Framework\Attributes\DoesNotPerformAssertions]
146147
public function testUpgradeDifferentPrefix(): void {
147148
$oldTablePrefix = $this->config->getSystemValueString('dbtableprefix', 'oc_');
148149

@@ -158,7 +159,6 @@ public function testUpgradeDifferentPrefix(): void {
158159
$this->connection->insert($this->tableName, ['id' => 3, 'name' => 'qwerty']);
159160

160161
$migrator->migrate($endSchema);
161-
$this->addToAssertionCount(1);
162162

163163
$this->config->setSystemValue('dbtableprefix', $oldTablePrefix);
164164
}
@@ -172,14 +172,12 @@ public function testInsertAfterUpgrade(): void {
172172

173173
$this->connection->insert($this->tableName, ['id' => 1, 'name' => 'foo']);
174174
$this->connection->insert($this->tableName, ['id' => 2, 'name' => 'bar']);
175-
try {
176-
$this->connection->insert($this->tableName, ['id' => 2, 'name' => 'qwerty']);
177-
$this->fail('Expected duplicate key insert to fail');
178-
} catch (Exception $e) {
179-
$this->addToAssertionCount(1);
180-
}
175+
176+
$this->expectException(Exception::class);
177+
$this->connection->insert($this->tableName, ['id' => 2, 'name' => 'qwerty']);
181178
}
182179

180+
#[\PHPUnit\Framework\Attributes\DoesNotPerformAssertions]
183181
public function testAddingPrimaryKeyWithAutoIncrement(): void {
184182
$startSchema = new Schema([], [], $this->getSchemaConfig());
185183
$table = $startSchema->createTable($this->tableName);
@@ -196,10 +194,9 @@ public function testAddingPrimaryKeyWithAutoIncrement(): void {
196194
$migrator->migrate($startSchema);
197195

198196
$migrator->migrate($endSchema);
199-
200-
$this->addToAssertionCount(1);
201197
}
202198

199+
#[\PHPUnit\Framework\Attributes\DoesNotPerformAssertions]
203200
public function testReservedKeywords(): void {
204201
$startSchema = new Schema([], [], $this->getSchemaConfig());
205202
$table = $startSchema->createTable($this->tableName);
@@ -217,13 +214,12 @@ public function testReservedKeywords(): void {
217214
$migrator->migrate($startSchema);
218215

219216
$migrator->migrate($endSchema);
220-
221-
$this->addToAssertionCount(1);
222217
}
223218

224219
/**
225220
* Test for nextcloud/server#36803
226221
*/
222+
#[\PHPUnit\Framework\Attributes\DoesNotPerformAssertions]
227223
public function testColumnCommentsInUpdate(): void {
228224
$startSchema = new Schema([], [], $this->getSchemaConfig());
229225
$table = $startSchema->createTable($this->tableName);
@@ -241,8 +237,6 @@ public function testColumnCommentsInUpdate(): void {
241237
$migrator->migrate($startSchema);
242238

243239
$migrator->migrate($endSchema);
244-
245-
$this->addToAssertionCount(1);
246240
}
247241

248242
public function testAddingForeignKey(): void {
@@ -305,12 +299,10 @@ public function testNotNullEmptyValuesFailOracle(int $parameterType, $value, str
305299
$this->expectException(\Doctrine\DBAL\Exception\NotNullConstraintViolationException::class);
306300
}
307301

308-
$this->connection->insert(
302+
$this->assertSame(1, $this->connection->insert(
309303
$this->tableName,
310304
['id' => 1, 'will_it_blend' => $value],
311305
['id' => ParameterType::INTEGER, 'will_it_blend' => $parameterType],
312-
);
313-
314-
$this->addToAssertionCount(1);
306+
));
315307
}
316308
}

tests/lib/DB/QueryBuilder/QueryBuilderTest.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1154,7 +1154,6 @@ public function testGetLastInsertId(): void {
11541154
$qB->getLastInsertId();
11551155
$this->fail('getLastInsertId() should throw an exception, when being called before insert()');
11561156
} catch (\BadMethodCallException $e) {
1157-
$this->addToAssertionCount(1);
11581157
}
11591158

11601159
$qB->insert('properties')
@@ -1180,7 +1179,6 @@ public function testGetLastInsertId(): void {
11801179
$qB->getLastInsertId();
11811180
$this->fail('getLastInsertId() should throw an exception, when being called after delete()');
11821181
} catch (\BadMethodCallException $e) {
1183-
$this->addToAssertionCount(1);
11841182
}
11851183
}
11861184

0 commit comments

Comments
 (0)