Skip to content

Commit

Permalink
Merge 8f22d17 into 32b20d2
Browse files Browse the repository at this point in the history
  • Loading branch information
codeliner committed Sep 18, 2015
2 parents 32b20d2 + 8f22d17 commit ac220b6
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 6 deletions.
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@
"prooph"
],
"require": {
"php": ">=5.5"
"php": ">=5.5",
"prooph/event-store" : "^5.1"
},
"require-dev": {
"phpunit/phpunit": "~4.7",
"prooph/event-store" : "dev-master",
"prooph/service-bus" : "dev-master",
"fabpot/php-cs-fixer": "1.7.*",
"satooshi/php-coveralls": "dev-master"
Expand Down
10 changes: 6 additions & 4 deletions src/TransactionManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,10 +118,12 @@ public function onInitialize(ActionEvent $actionEvent)
*/
public function onFinalize(ActionEvent $actionEvent)
{
if ($actionEvent->getParam(CommandBus::EVENT_PARAM_EXCEPTION)) {
$this->eventStore->rollback();
} else {
$this->eventStore->commit();
if ($this->eventStore->isInTransaction()) {
if ($actionEvent->getParam(CommandBus::EVENT_PARAM_EXCEPTION)) {
$this->eventStore->rollback();
} else {
$this->eventStore->commit();
}
}

$this->currentCommand = null;
Expand Down
26 changes: 26 additions & 0 deletions tests/TransactionManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,8 @@ public function it_commits_a_transaction_on_command_dispatch_finalize_if_no_exce
{
$eventStoreMock = $this->getEventStoreObjectProphecy();

$eventStoreMock->isInTransaction()->willReturn(true);

$eventStoreMock->commit()->shouldBeCalled();

$transactionManager = new TransactionManager($eventStoreMock->reveal());
Expand All @@ -121,6 +123,8 @@ public function it_rollback_a_transaction_on_command_dispatch_finalize_if_except
{
$eventStoreMock = $this->getEventStoreObjectProphecy();

$eventStoreMock->isInTransaction()->willReturn(true);

$eventStoreMock->rollback()->shouldBeCalled();

$transactionManager = new TransactionManager($eventStoreMock->reveal());
Expand All @@ -134,6 +138,28 @@ public function it_rollback_a_transaction_on_command_dispatch_finalize_if_except
$transactionManager->onFinalize($actionEvent->reveal());
}

/**
* @test
*/
public function it_does_not_perform_rollback_after_transaction_commit()
{
$eventStoreMock = $this->getEventStoreObjectProphecy();

$eventStoreMock->isInTransaction()->willReturn(false);

$eventStoreMock->rollback()->shouldNotBeCalled();

$transactionManager = new TransactionManager($eventStoreMock->reveal());

$actionEvent = $this->prophesize(ActionEvent::class);

$exception = $this->prophesize(\Exception::class);

$actionEvent->getParam(CommandBus::EVENT_PARAM_EXCEPTION)->willReturn($exception->reveal());

$transactionManager->onFinalize($actionEvent->reveal());
}

/**
* @test
*/
Expand Down

0 comments on commit ac220b6

Please sign in to comment.