From 0d31d01a4b328f222d21b9a39a07ab9449052a9d Mon Sep 17 00:00:00 2001 From: Alexander Miertsch Date: Fri, 18 Sep 2015 23:43:57 +0200 Subject: [PATCH] Add method to check whether event store is in transaction --- src/EventStore.php | 8 ++++++++ tests/EventStoreTest.php | 4 ++++ 2 files changed, 12 insertions(+) diff --git a/src/EventStore.php b/src/EventStore.php index d3f79bb1..caaf73e0 100644 --- a/src/EventStore.php +++ b/src/EventStore.php @@ -342,6 +342,14 @@ public function rollback() $this->recordedEvents = []; } + /** + * @return bool + */ + public function isInTransaction() + { + return $this->transactionLevel > 0; + } + /** * @return ActionEventEmitter */ diff --git a/tests/EventStoreTest.php b/tests/EventStoreTest.php index 2154a3e8..a081d25b 100644 --- a/tests/EventStoreTest.php +++ b/tests/EventStoreTest.php @@ -729,10 +729,14 @@ public function it_commits_transaction_if_adapter_implements_can_handle_transact $this->eventStore->beginTransaction(); + $this->assertTrue($this->eventStore->isInTransaction()); + $this->eventStore->create($stream); $this->eventStore->commit(); + $this->assertFalse($this->eventStore->isInTransaction()); + $stream = $this->eventStore->load($stream->streamName()); $this->assertEquals('user', $stream->streamName()->toString());