Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
prolic committed Aug 26, 2015
1 parent 34c3da8 commit 0ec999e
Show file tree
Hide file tree
Showing 5 changed files with 118 additions and 22 deletions.
22 changes: 22 additions & 0 deletions phpunit.xml.dist
@@ -0,0 +1,22 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit backupGlobals="false"
backupStaticAttributes="false"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false"
syntaxCheck="false"
bootstrap="vendor/autoload.php"
>
<testsuite name="Prooph Event-Sourcing Test Suite">
<directory>./tests/</directory>
</testsuite>

<filter>
<whitelist>
<directory>./src/</directory>
</whitelist>
</filter>
</phpunit>
11 changes: 11 additions & 0 deletions tests/AggregateRootTest.php
Expand Up @@ -11,6 +11,7 @@

namespace Prooph\EventSourcingTest;

use Prooph\EventSourcingTest\Mock\BrokenUser;
use Prooph\EventSourcingTest\Mock\User;

/**
Expand Down Expand Up @@ -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
*/
Expand Down
85 changes: 85 additions & 0 deletions tests/Prooph/EventSourcingTest/Mock/BrokenUser.php
@@ -0,0 +1,85 @@
<?php
/*
* This file is part of the prooph/event-store.
* (c) Alexander Miertsch <contact@prooph.de>
*
* 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 <contact@prooph.de>
*/
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();
}
}
13 changes: 0 additions & 13 deletions tests/bootstrap.php

This file was deleted.

9 changes: 0 additions & 9 deletions tests/phpunit.xml.dist

This file was deleted.

0 comments on commit 0ec999e

Please sign in to comment.