diff --git a/tests/php-unit-tests/unitary-tests/core/CMDBSource/CMDBSourceTest.php b/tests/php-unit-tests/unitary-tests/core/CMDBSource/CMDBSourceTest.php index 62a6af66d..f0286dd5d 100644 --- a/tests/php-unit-tests/unitary-tests/core/CMDBSource/CMDBSourceTest.php +++ b/tests/php-unit-tests/unitary-tests/core/CMDBSource/CMDBSourceTest.php @@ -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 diff --git a/tests/php-unit-tests/unitary-tests/core/CMDBSource/TransactionsTest.php b/tests/php-unit-tests/unitary-tests/core/CMDBSource/TransactionsTest.php index 17de3252d..d4459dd36 100644 --- a/tests/php-unit-tests/unitary-tests/core/CMDBSource/TransactionsTest.php +++ b/tests/php-unit-tests/unitary-tests/core/CMDBSource/TransactionsTest.php @@ -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(); } } \ No newline at end of file