Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 10 additions & 18 deletions tests/lib/DB/MigratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ private function getSchemaConfig() {
return $config;
}

#[\PHPUnit\Framework\Attributes\DoesNotPerformAssertions]
public function testUpgrade(): void {
[$startSchema, $endSchema] = $this->getDuplicateKeySchemas();
$migrator = $this->getMigrator();
Expand All @@ -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_');

Expand All @@ -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);
}
Expand All @@ -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);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We may be able to narrow this so not just any Exception is accepted; though this is existing behavior admittedly

return $this->insert($entity);
} catch (Exception $ex) {
if ($ex->getReason() === Exception::REASON_UNIQUE_CONSTRAINT_VIOLATION) {

$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);
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -241,8 +237,6 @@ public function testColumnCommentsInUpdate(): void {
$migrator->migrate($startSchema);

$migrator->migrate($endSchema);

$this->addToAssertionCount(1);
}

public function testAddingForeignKey(): void {
Expand Down Expand Up @@ -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);
));
}
}
2 changes: 0 additions & 2 deletions tests/lib/DB/QueryBuilder/QueryBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll fully admit I'm not familiar with using addToAssertionCount, but should there still be something like $this->expectException(\BadMethodCallException::class); here?

}

$qB->insert('properties')
Expand All @@ -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);
}
}

Expand Down
Loading