refactor(tests): teardown is now always called - also when skipped

* ref: https://github.com/sebastianbergmann/phpunit/issues/6394

Signed-off-by: Ferdinand Thiessen <opensource@fthiessen.de>
pull/55870/head
Ferdinand Thiessen 2025-10-21 00:33:19 +07:00
parent f1e82b10e6
commit 1eeed0a170
No known key found for this signature in database
GPG Key ID: 45FAE7268762B400
2 changed files with 13 additions and 5 deletions

@ -27,6 +27,7 @@ class PartitionedQueryBuilderTest extends TestCase {
protected function setUp(): void {
if (PHP_INT_SIZE < 8) {
$this->markTestSkipped('Test requires 64bit');
return;
}
$this->connection = Server::get(IDBConnection::class);
$this->shardConnectionManager = Server::get(ShardConnectionManager::class);
@ -36,7 +37,11 @@ class PartitionedQueryBuilderTest extends TestCase {
}
protected function tearDown(): void {
$this->cleanupDb();
// PHP unit also runs tearDown when the test is skipped, but we only initialized when using 64bit
// see https://github.com/sebastianbergmann/phpunit/issues/6394
if (PHP_INT_SIZE >= 8) {
$this->cleanupDb();
}
parent::tearDown();
}

@ -31,7 +31,6 @@ class TestCollationRepair extends Collation {
/**
* Tests for the converting of MySQL tables to InnoDB engine
*
*
* @see \OC\Repair\RepairMimeTypes
*/
#[\PHPUnit\Framework\Attributes\Group('DB')]
@ -48,13 +47,13 @@ class RepairCollationTest extends TestCase {
parent::setUp();
$this->connection = Server::get(ConnectionAdapter::class);
$this->config = Server::get(IConfig::class);
if ($this->connection->getDatabaseProvider() !== IDBConnection::PLATFORM_MYSQL) {
$this->markTestSkipped('Test only relevant on MySql');
return;
}
$this->logger = $this->createMock(LoggerInterface::class);
$this->config = Server::get(IConfig::class);
$dbPrefix = $this->config->getSystemValueString('dbtableprefix');
$this->tableName = $this->getUniqueID($dbPrefix . '_collation_test');
$this->connection->prepare("CREATE TABLE $this->tableName(text VARCHAR(16)) COLLATE utf8_unicode_ci")->execute();
@ -63,7 +62,11 @@ class RepairCollationTest extends TestCase {
}
protected function tearDown(): void {
$this->connection->getInner()->createSchemaManager()->dropTable($this->tableName);
$this->connection = Server::get(ConnectionAdapter::class);
if ($this->connection->getDatabaseProvider() === IDBConnection::PLATFORM_MYSQL) {
// tear down only needed on MySQL
$this->connection->getInner()->createSchemaManager()->dropTable($this->tableName);
}
parent::tearDown();
}