Skip to content

Commit

Permalink
Merge pull request #4 from Pol-Valentin/fix-doctrine-dbal
Browse files Browse the repository at this point in the history
fix: improve DoctrineDbalConnectionTransactionManager
  • Loading branch information
remi-san committed Jul 12, 2018
2 parents 8550db8 + 4e7ae10 commit eaf0c6b
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/Doctrine/DoctrineDbalConnectionTransactionManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public function beginTransaction()
try {
$this->dbalConnection->beginTransaction();
} catch (\Exception $e) {
throw new BeginException('Cannot begin Doctrine DBAL transaction');
throw new BeginException('Cannot begin Doctrine DBAL transaction', 0, $e);
}
}

Expand All @@ -46,7 +46,7 @@ public function commit()
try {
$this->dbalConnection->commit();
} catch (ConnectionException $e) {
throw new CommitException('Cannot commit Doctrine DBAL transaction');
throw new CommitException('Cannot commit Doctrine DBAL transaction', 0, $e);
}
}

Expand All @@ -56,9 +56,9 @@ public function commit()
public function rollback()
{
try {
$this->dbalConnection->commit();
$this->dbalConnection->rollBack();
} catch (ConnectionException $e) {
throw new RollbackException('Cannot rollback Doctrine DBAL transaction');
throw new RollbackException('Cannot rollback Doctrine DBAL transaction', 0, $e);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
<?php

namespace spec\RemiSan\TransactionManager\Doctrine;

use Doctrine\DBAL\Connection;
use Doctrine\DBAL\ConnectionException;
use PhpSpec\ObjectBehavior;
use RemiSan\TransactionManager\Doctrine\DoctrineDbalConnectionTransactionManager;
use RemiSan\TransactionManager\Exception\BeginException;
use RemiSan\TransactionManager\Exception\CommitException;
use RemiSan\TransactionManager\Exception\RollbackException;

class DoctrineDbalConnectionTransactionManagerSpec extends ObjectBehavior
{
function let(Connection $connection)
{
$this->beConstructedWith($connection);
}

function it_is_initializable()
{
$this->shouldHaveType(DoctrineDbalConnectionTransactionManager::class);
}

function it_should_begin_the_dbal_transaction(Connection $connection)
{
$connection->beginTransaction();

$this->beginTransaction();
}

function it_should_throw_an_exception_if_dbal_transaction_begin_failed(Connection $connection)
{
$connection->beginTransaction()->willThrow(new \Exception());

$this->shouldThrow(BeginException::class)
->duringBeginTransaction();
}

function it_should_commit_the_dbal_transaction(Connection $connection)
{
$connection->commit();

$this->commit();
}

function it_should_throw_an_exception_if_dbal_transaction_commit_failed(Connection $connection)
{
$connection->commit()->willThrow(ConnectionException::class);

$this->shouldThrow(CommitException::class)
->duringCommit();
}

function it_should_rollback_the_dbal_transaction(Connection $connection)
{
$connection->rollBack();

$this->rollback();
}

function it_should_throw_an_exception_if_dbal_transaction_rollback_failed(Connection $connection)
{
$connection->rollBack()->willThrow(ConnectionException::class);

$this->shouldThrow(RollbackException::class)
->duringRollback();
}

}

0 comments on commit eaf0c6b

Please sign in to comment.