From 0ec999e1014b6d416777be70a3abe7bba47640bc Mon Sep 17 00:00:00 2001 From: prolic Date: Wed, 26 Aug 2015 19:38:37 +0100 Subject: [PATCH] Add tests --- phpunit.xml.dist | 22 +++++ tests/AggregateRootTest.php | 11 +++ .../EventSourcingTest/Mock/BrokenUser.php | 85 +++++++++++++++++++ tests/bootstrap.php | 13 --- tests/phpunit.xml.dist | 9 -- 5 files changed, 118 insertions(+), 22 deletions(-) create mode 100644 phpunit.xml.dist create mode 100644 tests/Prooph/EventSourcingTest/Mock/BrokenUser.php delete mode 100644 tests/bootstrap.php delete mode 100644 tests/phpunit.xml.dist diff --git a/phpunit.xml.dist b/phpunit.xml.dist new file mode 100644 index 0000000..86679d2 --- /dev/null +++ b/phpunit.xml.dist @@ -0,0 +1,22 @@ + + + + ./tests/ + + + + + ./src/ + + + diff --git a/tests/AggregateRootTest.php b/tests/AggregateRootTest.php index f0dc305..06468f7 100644 --- a/tests/AggregateRootTest.php +++ b/tests/AggregateRootTest.php @@ -11,6 +11,7 @@ namespace Prooph\EventSourcingTest; +use Prooph\EventSourcingTest\Mock\BrokenUser; use Prooph\EventSourcingTest\Mock\User; /** @@ -49,6 +50,16 @@ public function it_applies_event_by_calling_appropriate_event_handler() $this->assertEquals(2, $userNameChangedEvent->version()); } + /** + * @test + * @expectedException RuntimeException + * @expectedExceptionMessage Missing event handler method whenUserCreated for aggregate root Prooph\EventSourcingTest\Mock\BrokenUser + */ + public function it_throws_exception_when_no_handler_on_aggregate() + { + BrokenUser::nameNew('John'); + } + /** * @test */ diff --git a/tests/Prooph/EventSourcingTest/Mock/BrokenUser.php b/tests/Prooph/EventSourcingTest/Mock/BrokenUser.php new file mode 100644 index 0000000..2997692 --- /dev/null +++ b/tests/Prooph/EventSourcingTest/Mock/BrokenUser.php @@ -0,0 +1,85 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + * + * Date: 18.04.14 - 00:04 + */ + +namespace Prooph\EventSourcingTest\Mock; + +use Prooph\EventSourcing\AggregateChanged; +use Prooph\EventSourcing\AggregateRoot; +use Rhumsaa\Uuid\Uuid; + +/** + * Class BrokenUser + * + * @package Prooph\EventStoreTest\Mock + * @author Alexander Miertsch + */ +class BrokenUser extends AggregateRoot +{ + /** + * @var string + */ + protected $id; + + /** + * @var string + */ + protected $name; + + public static function nameNew($name) + { + $id = Uuid::uuid4()->toString(); + $instance = new self(); + + $instance->recordThat(UserCreated::occur($id, ['id' => $id, 'name' => $name])); + + return $instance; + } + + /** + * @param AggregateChanged[] $historyEvents + * @return User + */ + public static function fromHistory(array $historyEvents) + { + return self::reconstituteFromHistory($historyEvents); + } + /** + * @return string + */ + public function id() + { + return $this->id; + } + + /** + * @return string + */ + public function name() + { + return $this->name; + } + + /** + * @return \Prooph\EventSourcing\AggregateChanged[] + */ + public function accessRecordedEvents() + { + return $this->popRecordedEvents(); + } + + /** + * @return string representation of the unique identifier of the aggregate root + */ + protected function aggregateId() + { + return $this->id(); + } +} diff --git a/tests/bootstrap.php b/tests/bootstrap.php deleted file mode 100644 index b4987b0..0000000 --- a/tests/bootstrap.php +++ /dev/null @@ -1,13 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - * - * Date: 08.03.14 - 15:47 - */ -require_once __DIR__ . '/../vendor/autoload.php'; - -chdir(__DIR__); \ No newline at end of file diff --git a/tests/phpunit.xml.dist b/tests/phpunit.xml.dist deleted file mode 100644 index c066f7d..0000000 --- a/tests/phpunit.xml.dist +++ /dev/null @@ -1,9 +0,0 @@ - - - - - - . - - - \ No newline at end of file