mirror of
https://github.com/dg/dibi.git
synced 2025-08-01 11:50:15 +02:00
Connection: begin(), commit() & rollback() calls are forbidden in transaction()
This commit is contained in:
committed by
David Grudl
parent
b00e556289
commit
3066fea2aa
@@ -337,6 +337,10 @@ class Connection implements IConnection
|
||||
*/
|
||||
public function begin(string $savepoint = null): void
|
||||
{
|
||||
if ($this->transactionDepth !== 0) {
|
||||
throw new \LogicException(__METHOD__ . '() call is forbidden inside a transaction() callback');
|
||||
}
|
||||
|
||||
if (!$this->driver) {
|
||||
$this->connect();
|
||||
}
|
||||
@@ -361,6 +365,10 @@ class Connection implements IConnection
|
||||
*/
|
||||
public function commit(string $savepoint = null): void
|
||||
{
|
||||
if ($this->transactionDepth !== 0) {
|
||||
throw new \LogicException(__METHOD__ . '() call is forbidden inside a transaction() callback');
|
||||
}
|
||||
|
||||
if (!$this->driver) {
|
||||
$this->connect();
|
||||
}
|
||||
@@ -385,6 +393,10 @@ class Connection implements IConnection
|
||||
*/
|
||||
public function rollback(string $savepoint = null): void
|
||||
{
|
||||
if ($this->transactionDepth !== 0) {
|
||||
throw new \LogicException(__METHOD__ . '() call is forbidden inside a transaction() callback');
|
||||
}
|
||||
|
||||
if (!$this->driver) {
|
||||
$this->connect();
|
||||
}
|
||||
|
@@ -108,3 +108,24 @@ test('nested transaction() call success', function () use ($conn) {
|
||||
});
|
||||
Assert::same(7, (int) $conn->query('SELECT COUNT(*) FROM [products]')->fetchSingle());
|
||||
});
|
||||
|
||||
|
||||
test('begin(), commit() & rollback() calls are forbidden in transaction()', function () use ($conn) {
|
||||
Assert::exception(function () use ($conn) {
|
||||
$conn->transaction(function (Dibi\Connection $connection) {
|
||||
$connection->begin();
|
||||
});
|
||||
}, \LogicException::class, Dibi\Connection::class . '::begin() call is forbidden inside a transaction() callback');
|
||||
|
||||
Assert::exception(function () use ($conn) {
|
||||
$conn->transaction(function (Dibi\Connection $connection) {
|
||||
$connection->commit();
|
||||
});
|
||||
}, \LogicException::class, Dibi\Connection::class . '::commit() call is forbidden inside a transaction() callback');
|
||||
|
||||
Assert::exception(function () use ($conn) {
|
||||
$conn->transaction(function (Dibi\Connection $connection) {
|
||||
$connection->rollback();
|
||||
});
|
||||
}, \LogicException::class, Dibi\Connection::class . '::rollback() call is forbidden inside a transaction() callback');
|
||||
});
|
||||
|
Reference in New Issue
Block a user