-
Notifications
You must be signed in to change notification settings - Fork 55
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
Fix OnEventStrategy #151
Fix OnEventStrategy #151
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you also please update the copyright year to 2017 ?
MessageBus::PRIORITY_INVOKE_HANDLER | ||
); | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
one new line too much
LICENSE file is missing update |
TestCase? |
$handlers = $actionEvent->getParam(EventBus::EVENT_PARAM_EVENT_LISTENERS); | ||
|
||
foreach ($handlers as $handler) { | ||
$this->invoke($handler, $message); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can be simply: $handler->onEvent($message);
and method public function invoke($handler, $message): void
can be removed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
okay
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can be simply: $handler->onEvent($message);
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
@@ -1,4 +1,4 @@ | |||
Copyright (c) 2013, Alexander Miertsch contact@prooph.de | |||
Copyright (c) 2017, Alexander Miertsch contact@prooph.de |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should be:
Copyright (c) 2013-2017, prooph software GmbH
Copyright (c) 2015-2017, Sascha-Oliver Prolic
6844740
to
8cc2ad9
Compare
use Prooph\ServiceBus\MessageBus; | ||
use Prooph\ServiceBus\Plugin\AbstractPlugin; | ||
|
||
class OnEventStrategy extends AbstractPlugin | ||
{ | ||
/** | ||
* @param mixed $handler |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unnecessary doc header parameters could be removed.
use Prooph\ServiceBus\MessageBus; | ||
use Prooph\ServiceBus\Plugin\AbstractPlugin; | ||
|
||
class OnEventStrategy extends AbstractPlugin |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This class could be final, i guess.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, final class please
$onEventStrategy->attachToMessageBus($bus->reveal()); | ||
|
||
$bus->attach(Argument::type('string'), Argument::type('callable'), Argument::type('integer'))->shouldHaveBeenCalled(); | ||
$prophet->checkPredictions(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of manuell run checkPredictions(), you could run
$bus->attach(Argument::type('string'), Argument::type('callable'), Argument::type('integer'))
->shouldBeCalled()
->willReturn(new DefaultListenerHandler(function () {}));
Then checkPredictions() would be executed from PHPUnit.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@oqq Thank you, I will try it!
{ | ||
$onEventStrategy = new OnEventStrategy(); | ||
|
||
$prophet = new \Prophecy\Prophet(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This line is unnecessary. See comment below.
|
||
$prophet = new \Prophecy\Prophet(); | ||
|
||
$bus = $prophet->prophesize(EventBus::class); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could be $this->prophesize()
. See comment below.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
only some last minor things
use Prooph\ServiceBus\MessageBus; | ||
use Prooph\ServiceBus\Plugin\AbstractPlugin; | ||
|
||
class OnEventStrategy extends AbstractPlugin |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, final class please
@@ -22,4 +27,22 @@ public function invoke($handler, $message): void | |||
{ | |||
$handler->onEvent($message); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove this method
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Then I need to adjust the testcases, too and mock the handler->onEvent() call, too?
$handlers = $actionEvent->getParam(EventBus::EVENT_PARAM_EVENT_LISTENERS); | ||
|
||
foreach ($handlers as $handler) { | ||
$this->invoke($handler, $message); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can be simply: $handler->onEvent($message);
new DefaultListenerHandler( | ||
function () { | ||
|
||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
function () {}: void
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
{}
on the same line would be against PSR-2 (not sure whether this repository is following PSR-2).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, php-cs-fixer would complain then, been there already :)
Closes #150