mirror of
https://github.com/Combodo/iTop.git
synced 2026-04-24 11:08:45 +02: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');
|
$this->RequireOnceItopFile('/core/cmdbsource.class.inc.php');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected function tearDown(): void
|
||||||
|
{
|
||||||
|
DbConnectionWrapper::SetDbConnectionMockForQuery();
|
||||||
|
|
||||||
|
parent::tearDown();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @covers CMDBSource::IsSameFieldTypes
|
* @covers CMDBSource::IsSameFieldTypes
|
||||||
* @dataProvider compareFieldTypesProvider
|
* @dataProvider compareFieldTypesProvider
|
||||||
|
|||||||
@@ -257,36 +257,27 @@ class TransactionsTest extends ItopTestCase
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @return void
|
* @return void
|
||||||
* @doesNotPerformAssertions
|
|
||||||
*/
|
*/
|
||||||
public function testTransactionOpenedThenClosed()
|
public function testIsInsideTransaction()
|
||||||
{
|
{
|
||||||
CMDBSource::Query('START TRANSACTION;');
|
static::assertFalse(CMDBSource::IsInsideTransaction(), 'Should not be already inside a transaction');
|
||||||
CMDBSource::Query('COMMIT;');
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
// First, with a transaction ended by a "COMMIT" statement
|
||||||
* 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()
|
|
||||||
{
|
|
||||||
CMDBSource::Query('START TRANSACTION;');
|
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
|
protected function tearDown(): void
|
||||||
{
|
{
|
||||||
try {
|
DbConnectionWrapper::SetDbConnectionMockForQuery();
|
||||||
DbConnectionWrapper::SetDbConnectionMockForQuery();
|
parent::tearDown();
|
||||||
parent::tearDown();
|
|
||||||
}
|
|
||||||
catch (MySQLTransactionNotClosedException $e) {
|
|
||||||
if ($this->getName() === 'testTransactionOpenedNotClosed') {
|
|
||||||
$this->debug('Executing the testTransactionOpenNoClose method throws a '.MySQLTransactionNotClosedException::class.' exception in tearDown');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user