Skip to content

Commit

Permalink
Merge pull request prooph#7 from basz/patch-2
Browse files Browse the repository at this point in the history
  • Loading branch information
prolic authored Mar 4, 2017
2 parents 070251e + b2f0da2 commit 6dbacf0
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 54 deletions.
12 changes: 3 additions & 9 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@
},
"require-dev": {
"prooph/pdo-event-store": "1.0.x-dev",
"phpunit/phpunit": "^5.7",
"phpspec/prophecy": "dev-patch-1 as 1.6.2",
"phpunit/phpunit": "^6.0",
"phpspec/prophecy": "^1.7",
"prooph/php-cs-fixer-config": "^0.1.1",
"satooshi/php-coveralls": "^1.0",
"malukenho/docheader": "^0.1.4",
Expand All @@ -46,11 +46,5 @@
"ProophTest\\StandardProjections\\": "tests/",
"ProophTest\\EventStore\\": "vendor/prooph/event-store/tests/"
}
},
"repositories": [
{
"type": "git",
"url": "https://github.com/prolic/prophecy.git"
}
]
}
}
21 changes: 7 additions & 14 deletions src/AllStreamProjectionRunner.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,31 +12,24 @@

namespace Prooph\StandardProjections;

use Prooph\EventStore\EventStore;
use Prooph\EventStore\Projection\ProjectionOptions;
use Prooph\EventStore\Projection\ProjectionManager;

class AllStreamProjectionRunner
{
/**
* @var EventStore
* @var ProjectionManager
*/
private $eventStore;
private $projectionManager;

/**
* @var ProjectionOptions|null
*/
private $projectionOptions;

public function __construct(EventStore $eventStore, ProjectionOptions $projectionOptions = null)
public function __construct(ProjectionManager $projectionManager)
{
$this->eventStore = $eventStore;
$this->projectionOptions = $projectionOptions;
$this->projectionManager = $projectionManager;
}

public function __invoke(bool $keepRunning = true): void
{
$this->eventStore
->createProjection('$all', $this->projectionOptions)
$this->projectionManager
->createProjection('$all')
->fromAll()
->whenAny(function ($state, $event): void {
$this->emit($event);
Expand Down
21 changes: 7 additions & 14 deletions src/CategoryStreamProjectionRunner.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,31 +12,24 @@

namespace Prooph\StandardProjections;

use Prooph\EventStore\EventStore;
use Prooph\EventStore\Projection\ProjectionOptions;
use Prooph\EventStore\Projection\ProjectionManager;

class CategoryStreamProjectionRunner
{
/**
* @var EventStore
* @var ProjectionManager
*/
private $eventStore;
private $projectionManager;

/**
* @var ProjectionOptions|null
*/
private $projectionOptions;

public function __construct(EventStore $eventStore, ProjectionOptions $projectionOptions = null)
public function __construct(ProjectionManager $projectionManager)
{
$this->eventStore = $eventStore;
$this->projectionOptions = $projectionOptions;
$this->projectionManager = $projectionManager;
}

public function __invoke(bool $keepRunning = true): void
{
$this->eventStore
->createProjection('$by_category', $this->projectionOptions)
$this->projectionManager
->createProjection('$by_category')
->fromAll()
->whenAny(function ($state, $event): void {
$streamName = $this->streamName();
Expand Down
21 changes: 7 additions & 14 deletions src/MessageNameStreamProjectionRunner.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,31 +13,24 @@
namespace Prooph\StandardProjections;

use Prooph\Common\Messaging\Message;
use Prooph\EventStore\EventStore;
use Prooph\EventStore\Projection\ProjectionOptions;
use Prooph\EventStore\Projection\ProjectionManager;

class MessageNameStreamProjectionRunner
{
/**
* @var EventStore
* @var ProjectionManager
*/
private $eventStore;
private $projectionManager;

/**
* @var ProjectionOptions|null
*/
private $projectionOptions;

public function __construct(EventStore $eventStore, ProjectionOptions $projectionOptions = null)
public function __construct(ProjectionManager $projectionManager)
{
$this->eventStore = $eventStore;
$this->projectionOptions = $projectionOptions;
$this->projectionManager = $projectionManager;
}

public function __invoke(bool $keepRunning = true): void
{
$this->eventStore
->createProjection('$by_message_name', $this->projectionOptions)
$this->projectionManager
->createProjection('$by_message_name')
->fromAll()
->whenAny(function ($state, Message $event): void {
$messageName = $event->messageName();
Expand Down
4 changes: 3 additions & 1 deletion tests/AllStreamProjectionRunnerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
use PHPUnit\Framework\TestCase;
use Prooph\Common\Event\ProophActionEventEmitter;
use Prooph\EventStore\InMemoryEventStore;
use Prooph\EventStore\Projection\InMemoryProjectionManager;
use Prooph\EventStore\Stream;
use Prooph\EventStore\StreamName;
use Prooph\StandardProjections\AllStreamProjectionRunner;
Expand Down Expand Up @@ -69,7 +70,8 @@ public function it_emits_events_for_all_streams()

$eventStore->commit();

$allStreamProjection = new AllStreamProjectionRunner($eventStore);
$projectionManager = new InMemoryProjectionManager($eventStore);
$allStreamProjection = new AllStreamProjectionRunner($projectionManager);
$allStreamProjection(false);

$this->assertTrue($eventStore->hasStream(new StreamName('$all')));
Expand Down
4 changes: 3 additions & 1 deletion tests/CategoryStreamProjectionRunnerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
use PHPUnit\Framework\TestCase;
use Prooph\Common\Event\ProophActionEventEmitter;
use Prooph\EventStore\InMemoryEventStore;
use Prooph\EventStore\Projection\InMemoryProjectionManager;
use Prooph\EventStore\Stream;
use Prooph\EventStore\StreamName;
use Prooph\StandardProjections\CategoryStreamProjectionRunner;
Expand Down Expand Up @@ -83,7 +84,8 @@ public function it_emits_events_for_all_streams()

$eventStore->commit();

$categoryStreamProjection = new CategoryStreamProjectionRunner($eventStore);
$projectionManager = new InMemoryProjectionManager($eventStore);
$categoryStreamProjection = new CategoryStreamProjectionRunner($projectionManager);
$categoryStreamProjection(false);

$this->assertTrue($eventStore->hasStream(new StreamName('$ct-foo')));
Expand Down
4 changes: 3 additions & 1 deletion tests/MessageNameStreamProjectionRunnerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
use PHPUnit\Framework\TestCase;
use Prooph\Common\Event\ProophActionEventEmitter;
use Prooph\EventStore\InMemoryEventStore;
use Prooph\EventStore\Projection\InMemoryProjectionManager;
use Prooph\EventStore\Stream;
use Prooph\EventStore\StreamName;
use Prooph\StandardProjections\MessageNameStreamProjectionRunner;
Expand Down Expand Up @@ -53,7 +54,8 @@ public function it_emits_events_for_all_streams()

$eventStore->commit();

$categoryStreamProjection = new MessageNameStreamProjectionRunner($eventStore);
$projectionManager = new InMemoryProjectionManager($eventStore);
$categoryStreamProjection = new MessageNameStreamProjectionRunner($projectionManager);
$categoryStreamProjection(false);

$this->assertTrue($eventStore->hasStream(new StreamName('$mn-event-a')));
Expand Down

0 comments on commit 6dbacf0

Please sign in to comment.