Skip to content

Commit

Permalink
Add transaction event callback tests
Browse files Browse the repository at this point in the history
  • Loading branch information
trowski committed Dec 9, 2023
1 parent f15097a commit 4b464c1
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions test/AbstractConnectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use Amp\Sql\SqlException;
use Revolt\EventLoop;
use function Amp\async;
use function Amp\delay;

abstract class AbstractConnectionTest extends AbstractLinkTest
{
Expand Down Expand Up @@ -110,4 +111,35 @@ public function testQueryAfterErroredQuery()

$this->assertSame(1, $result->getRowCount());
}

public function testTransactionsCallbacksOnCommit(): void
{
$transaction = $this->executor->beginTransaction();
$transaction->onCommit($this->createCallback(1));
$transaction->onRollback($this->createCallback(0));
$transaction->onClose($this->createCallback(1));

$transaction->commit();
}

public function testTransactionsCallbacksOnRollback(): void
{
$transaction = $this->executor->beginTransaction();
$transaction->onCommit($this->createCallback(0));
$transaction->onRollback($this->createCallback(1));
$transaction->onClose($this->createCallback(1));

$transaction->rollback();
}

public function testTransactionsCallbacksOnDestruct(): void
{
$transaction = $this->executor->beginTransaction();
$transaction->onCommit($this->createCallback(0));
$transaction->onRollback($this->createCallback(1));
$transaction->onClose($this->createCallback(1));

unset($transaction);
delay(0.1); // Destructor is async, so give control to the loop to invoke callbacks.
}
}

0 comments on commit 4b464c1

Please sign in to comment.