Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

phpspec/prophecy#332 #7

Merged
merged 3 commits into from
Mar 4, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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