Skip to content

Commit

Permalink
makes sure that listeners and projectors do not override each other
Browse files Browse the repository at this point in the history
  • Loading branch information
nixilla committed Feb 20, 2017
1 parent 01c1a15 commit 350a181
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 6 deletions.
15 changes: 14 additions & 1 deletion spec/Services/ListenerResolverSpec.php
Expand Up @@ -7,6 +7,7 @@
use PhpSpec\ObjectBehavior;
use Prooph\Common\Event\ActionEvent;
use Prooph\Common\Event\ActionEventEmitter;
use Prooph\ServiceBus\EventBus;
use Prophecy\Argument;

class ListenerResolverSpec extends ObjectBehavior
Expand Down Expand Up @@ -38,16 +39,28 @@ function it_detach_is_not_implemented(ActionEventEmitter $dispatcher)
;
}

function it_finds_listeners_for_given_event(ActionEvent $event)
function it_finds_listeners_for_given_event(ActionEvent $event, ListenerCollection $collection)
{
$event
->setParam(Argument::any(), Argument::any())
->shouldBeCalled();

$event
->getParam(EventBus::EVENT_PARAM_EVENT_LISTENERS)
->willReturn([]);

$event
->getParam(EventBus::EVENT_PARAM_MESSAGE)
->willReturn(new \stdClass());

$event
->getParam(Argument::any())
->shouldBeCalled();

$collection
->getListeners(Argument::any())
->willReturn([]);

$this->onRoute($event);
}
}
13 changes: 10 additions & 3 deletions spec/Services/ProjectorResolverSpec.php
Expand Up @@ -7,6 +7,7 @@
use PhpSpec\ObjectBehavior;
use Prooph\Common\Event\ActionEvent;
use Prooph\Common\Event\ActionEventEmitter;
use Prooph\ServiceBus\EventBus;
use Prophecy\Argument;

class ProjectorResolverSpec extends ObjectBehavior
Expand Down Expand Up @@ -38,15 +39,21 @@ function it_detach_is_not_implemented(ActionEventEmitter $dispatcher)
;
}

function it_finds_listeners_for_given_event(ActionEvent $event)
function it_finds_listeners_for_given_event(ActionEvent $event, ProjectorCollection $collection)
{
$event
->setParam(Argument::any(), Argument::any())
->shouldBeCalled();

$event
->getParam(Argument::any())
->shouldBeCalled();
->getParam(EventBus::EVENT_PARAM_EVENT_LISTENERS)
->willReturn([]);

$event
->getParam(EventBus::EVENT_PARAM_MESSAGE)
->willReturn(new \stdClass());

$collection->getProjectors(Argument::any())->willReturn([]);

$this->onRoute($event);
}
Expand Down
8 changes: 7 additions & 1 deletion src/Services/ListenerResolver.php
Expand Up @@ -33,6 +33,12 @@ public function detach(ActionEventEmitter $dispatcher)

public function onRoute(ActionEvent $event)
{
$event->setParam(EventBus::EVENT_PARAM_EVENT_LISTENERS, $this->collection->getListeners(get_class($event->getParam(EventBus::EVENT_PARAM_MESSAGE))));
$event->setParam(
EventBus::EVENT_PARAM_EVENT_LISTENERS,
array_merge(
$event->getParam(EventBus::EVENT_PARAM_EVENT_LISTENERS),
$this->collection->getListeners(get_class($event->getParam(EventBus::EVENT_PARAM_MESSAGE)))
)
);
}
}
8 changes: 7 additions & 1 deletion src/Services/ProjectorResolver.php
Expand Up @@ -33,6 +33,12 @@ public function detach(ActionEventEmitter $dispatcher)

public function onRoute(ActionEvent $event)
{
$event->setParam(EventBus::EVENT_PARAM_EVENT_LISTENERS, $this->collection->getProjectors(get_class($event->getParam(EventBus::EVENT_PARAM_MESSAGE))));
$event->setParam(
EventBus::EVENT_PARAM_EVENT_LISTENERS,
array_merge(
$event->getParam(EventBus::EVENT_PARAM_EVENT_LISTENERS),
$this->collection->getProjectors(get_class($event->getParam(EventBus::EVENT_PARAM_MESSAGE)))
)
);
}
}

0 comments on commit 350a181

Please sign in to comment.