mirror of
https://github.com/Combodo/iTop.git
synced 2026-03-06 09:34:13 +01:00
✅ Optimize tests execution time (test rework and defensive cleanup)
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user