Optimize tests execution time (test rework and defensive cleanup)

This commit is contained in:
Romain Quetiez
2023-10-26 21:35:52 +02:00
parent 798cd10d6b
commit fba668207f
2 changed files with 21 additions and 23 deletions

View File

@@ -26,6 +26,13 @@ class CMDBSourceTest extends ItopTestCase
$this->RequireOnceItopFile('/core/cmdbsource.class.inc.php');
}
protected function tearDown(): void
{
DbConnectionWrapper::SetDbConnectionMockForQuery();
parent::tearDown();
}
/**
* @covers CMDBSource::IsSameFieldTypes
* @dataProvider compareFieldTypesProvider

View File

@@ -257,36 +257,27 @@ class TransactionsTest extends ItopTestCase
/**
* @return void
* @doesNotPerformAssertions
*/
public function testTransactionOpenedThenClosed()
public function testIsInsideTransaction()
{
CMDBSource::Query('START TRANSACTION;');
CMDBSource::Query('COMMIT;');
}
static::assertFalse(CMDBSource::IsInsideTransaction(), 'Should not be already inside a transaction');
/**
* This will throw an exception in the tearDown method.
* This cannot be detected nor by `@expectedException` nor `expectException` method, so we have a specific tearDown impl
*
* @return void
* @doesNotPerformAssertions
*/
public function testTransactionOpenedNotClosed()
{
// First, with a transaction ended by a "COMMIT" statement
CMDBSource::Query('START TRANSACTION;');
static::assertTrue(CMDBSource::IsInsideTransaction(), 'Should be inside a translation');
CMDBSource::Query('COMMIT;');
static::assertFalse(CMDBSource::IsInsideTransaction(), 'Should not be inside a transaction anymore');
// Second, with a transaction ended by a "ROLLBACK" statement
CMDBSource::Query('START TRANSACTION;');
static::assertTrue(CMDBSource::IsInsideTransaction(), 'Should be inside a translation (again)');
CMDBSource::Query('ROLLBACK;');
static::assertFalse(CMDBSource::IsInsideTransaction(), 'Should not be inside a transaction anymore');
}
protected function tearDown(): void
{
try {
DbConnectionWrapper::SetDbConnectionMockForQuery();
parent::tearDown();
}
catch (MySQLTransactionNotClosedException $e) {
if ($this->getName() === 'testTransactionOpenedNotClosed') {
$this->debug('Executing the testTransactionOpenNoClose method throws a '.MySQLTransactionNotClosedException::class.' exception in tearDown');
}
}
DbConnectionWrapper::SetDbConnectionMockForQuery();
parent::tearDown();
}
}