Skip to content

Commit

Permalink
add last transaction manager test
Browse files Browse the repository at this point in the history
  • Loading branch information
prolic committed Aug 31, 2015
1 parent 43f0310 commit f4adf0a
Showing 1 changed file with 54 additions and 0 deletions.
54 changes: 54 additions & 0 deletions tests/TransactionManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

use Prooph\Common\Event\ActionEvent;
use Prooph\Common\Event\ActionEventEmitter;
use Prooph\Common\Event\DefaultActionEvent;
use Prooph\Common\Event\ListenerHandler;
use Prooph\Common\Messaging\Message;
use Prooph\EventStore\EventStore;
Expand Down Expand Up @@ -243,6 +244,59 @@ public function it_adds_causation_id_and_causation_name_on_event_store_append_to
$this->assertSame($recordedEventCopy2->reveal(), $enrichedEvents[0]);
}

/**
* @test
*/
public function it_returns_early_on_event_store_create_stream_if_event_has_no_stream()
{
$createStreamActionEvent = $this->prophesize(ActionEvent::class);

$createStreamActionEvent->getParam('stream')->willReturn(false);

$eventStoreMock = $this->getEventStoreObjectProphecy();

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

$this->assertNull($transactionManager->onEventStoreCreateStream($createStreamActionEvent->reveal()));
}

/**
* @test
*/
public function it_returns_early_if_command_was_null_when_handling_events()
{
//Step 1: Create null command
$command = null;

$causationId = Uuid::uuid4();

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

$initializeActionEvent->getParam(CommandBus::EVENT_PARAM_MESSAGE)->willReturn($command);

$eventStoreMock = $this->getEventStoreObjectProphecy();

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

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

$transactionManager->onInitialize($initializeActionEvent->reveal());

$recordedEvent = $this->prophesize(Message::class);
$recordedEventCopy1 = $this->prophesize(Message::class);

$recordedEvent->withAddedMetadata('causation_id', $causationId->toString())->willReturn($recordedEventCopy1->reveal());

$stream = new Stream(new StreamName('event_stream'), [$recordedEvent->reveal()]);

$createStreamActionEvent = new DefaultActionEvent('test');
$createStreamActionEvent->setParam('stream', $stream);

$transactionManager->onEventStoreCreateStream($createStreamActionEvent);

$this->assertEquals($stream, $createStreamActionEvent->getParam('stream'));
}

/**
* @return \Prophecy\Prophecy\ObjectProphecy
*/
Expand Down

0 comments on commit f4adf0a

Please sign in to comment.