mirror of
https://github.com/dg/dibi.git
synced 2025-08-19 04:11:44 +02:00
Connection::transtaction() call can be nested
This commit is contained in:
committed by
David Grudl
parent
877dffd460
commit
b00e556289
@@ -73,3 +73,38 @@ test('transaction() success', function () use ($conn) {
|
||||
});
|
||||
Assert::same(5, (int) $conn->query('SELECT COUNT(*) FROM [products]')->fetchSingle());
|
||||
});
|
||||
|
||||
|
||||
test('nested transaction() call fail', function () use ($conn) {
|
||||
Assert::exception(function () use ($conn) {
|
||||
$conn->transaction(function (Dibi\Connection $connection) {
|
||||
$connection->query('INSERT INTO [products]', [
|
||||
'title' => 'Test product',
|
||||
]);
|
||||
|
||||
$connection->transaction(function (Dibi\Connection $connection2) {
|
||||
$connection2->query('INSERT INTO [products]', [
|
||||
'title' => 'Test product',
|
||||
]);
|
||||
throw new Exception('my exception');
|
||||
});
|
||||
});
|
||||
}, \Throwable::class, 'my exception');
|
||||
Assert::same(5, (int) $conn->query('SELECT COUNT(*) FROM [products]')->fetchSingle());
|
||||
});
|
||||
|
||||
|
||||
test('nested transaction() call success', function () use ($conn) {
|
||||
$conn->transaction(function (Dibi\Connection $connection) {
|
||||
$connection->query('INSERT INTO [products]', [
|
||||
'title' => 'Test product',
|
||||
]);
|
||||
|
||||
$connection->transaction(function (Dibi\Connection $connection2) {
|
||||
$connection2->query('INSERT INTO [products]', [
|
||||
'title' => 'Test product',
|
||||
]);
|
||||
});
|
||||
});
|
||||
Assert::same(7, (int) $conn->query('SELECT COUNT(*) FROM [products]')->fetchSingle());
|
||||
});
|
||||
|
Reference in New Issue
Block a user