Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Starting tests

  • Loading branch information...
commit 271afbcfac737524e937298633641e99535e239b 1 parent da4c4ce
Sean Crystal authored
View
2  library/Tracks/UnitOfWork/UnitOfWork.php
@@ -26,7 +26,7 @@ public function commit(ITransaction $transaction = NULL)
foreach ($this->_registeredSaves as $aggregateRoot) {
$this->_repository->save($aggregateRoot);
}
- } catch (Exception $e) {
+ } catch (\Exception $e) {
$transaction and $transaction->rollback();
throw $e;
}
View
71 tests/Tracks/UnitOfWork/UnitOfWorkTest.php
@@ -0,0 +1,71 @@
+<?php
+require_once 'PHPUnit/Framework/TestCase.php';
+use Tracks\UnitOfWork\UnitOfWork;
+
+class UnitOfWorkTest extends PHPUnit_Framework_TestCase
+{
+ private $unitOfWork;
+
+ public function testRegisterSave()
+ {
+ $repository = $this->getMock('Tracks\EventStore\IRepository');
+ $repository->expects($this->never())->method('save');
+ $this->unitOfWork = new UnitOfWork($repository);
+
+ $aggregateRoot = $this->getMock('Tracks\Model\AggregateRoot');
+ $aggregateRoot->expects($this->never())->method('null');
+ $this->unitOfWork->registerSave($aggregateRoot);
+ }
+
+ public function testCommitWithoutTransaction()
+ {
+ $repository = $this->getMock('Tracks\EventStore\IRepository');
+ $repository->expects($this->once())->method('save');
+
+ $aggregateRoot = $this->getMock('Tracks\Model\AggregateRoot');
+ $aggregateRoot->expects($this->never())->method('null');
+
+ $this->unitOfWork = new UnitOfWork($repository);
+ $this->unitOfWork->registerSave($aggregateRoot);
+ $this->unitOfWork->commit();
+ }
+
+ public function testCommitWithTransaction()
+ {
+ $repository = $this->getMock('Tracks\EventStore\IRepository');
+ $repository->expects($this->once())->method('save');
+
+ $aggregateRoot = $this->getMock('Tracks\Model\AggregateRoot');
+ $aggregateRoot->expects($this->never())->method('null');
+
+ $transaction = $this->getMock('Tracks\UnitOfWork\ITransaction');
+ $transaction->expects($this->once())->method('begin');
+ $transaction->expects($this->once())->method('commit');
+
+ $this->unitOfWork = new UnitOfWork($repository);
+ $this->unitOfWork->registerSave($aggregateRoot);
+ $this->unitOfWork->commit($transaction);
+ }
+
+ public function testCommitWithTransactionThatFails()
+ {
+ $this->setExpectedException('Exception');
+
+ $repository = $this->getMock('Tracks\EventStore\IRepository');
+ $repository->expects($this->once())
+ ->method('save')
+ ->will($this->throwException(new Exception));
+
+ $aggregateRoot = $this->getMock('Tracks\Model\AggregateRoot');
+ $aggregateRoot->expects($this->never())->method('null');
+
+ $transaction = $this->getMock('Tracks\UnitOfWork\ITransaction');
+ $transaction->expects($this->once())->method('begin');
+ $transaction->expects($this->once())->method('rollback');
+
+ $this->unitOfWork = new UnitOfWork($repository);
+ $this->unitOfWork->registerSave($aggregateRoot);
+ $this->unitOfWork->commit($transaction);
+ }
+}
+
View
19 tests/bootstrap.php
@@ -0,0 +1,19 @@
+<?php
+
+function tracksAutoloader($className)
+{
+ $file = __DIR__
+ .DIRECTORY_SEPARATOR
+ .'..'
+ .DIRECTORY_SEPARATOR
+ .'library'
+ .DIRECTORY_SEPARATOR
+ .str_replace('\\', DIRECTORY_SEPARATOR, $className)
+ .'.php';
+
+ if (file_exists($file)) {
+ include $file;
+ }
+}
+
+spl_autoload_register('tracksAutoloader');
View
8 tests/phpunit.xml
@@ -0,0 +1,8 @@
+<phpunit
+ bootstrap="./bootstrap.php">
+ <testsuites>
+ <testsuite name="Tracks">
+ <directory>./Tracks</directory>
+ </testsuite>
+ </testsuites>
+</phpunit>
Please sign in to comment.
Something went wrong with that request. Please try again.