diff --git a/.coveralls.yml b/.coveralls.yml index 5049181..75aefc8 100644 --- a/.coveralls.yml +++ b/.coveralls.yml @@ -1,4 +1,3 @@ # for php-coveralls service_name: travis-ci -src_dir: src coverage_clover: build/logs/clover.xml diff --git a/.travis.yml b/.travis.yml index 056f4a4..d5916d3 100644 --- a/.travis.yml +++ b/.travis.yml @@ -13,7 +13,7 @@ script: - php ./vendor/bin/phpunit --coverage-text --coverage-clover ./build/logs/clover.xml - ./vendor/bin/php-cs-fixer fix -v --diff --dry-run -after_script: +after_success: - php vendor/bin/coveralls -v notifications: diff --git a/composer.json b/composer.json index 9f3b496..21265ab 100644 --- a/composer.json +++ b/composer.json @@ -30,7 +30,7 @@ "require-dev": { "phpunit/phpunit": "~4.8", "fabpot/php-cs-fixer": "1.7.*", - "satooshi/php-coveralls": "dev-master", + "satooshi/php-coveralls": "^1.0", "container-interop/container-interop" : "^1.1", "sandrokeil/interop-config": "^0.3", "tobiju/bookdown-bootswatch-templates": "^0.2.0" diff --git a/src/CommandBus.php b/src/CommandBus.php index 857c8aa..76cb98a 100644 --- a/src/CommandBus.php +++ b/src/CommandBus.php @@ -60,7 +60,7 @@ public function setActionEventEmitter(ActionEventEmitter $actionEventDispatcher) /** * @param mixed $command - * @throws \Exception + * @throws CommandDispatchException * @return void */ public function dispatch($command) diff --git a/src/Plugin/InvokeStrategy/AbstractInvokeStrategy.php b/src/Plugin/InvokeStrategy/AbstractInvokeStrategy.php index 42d7a34..59e1c4d 100644 --- a/src/Plugin/InvokeStrategy/AbstractInvokeStrategy.php +++ b/src/Plugin/InvokeStrategy/AbstractInvokeStrategy.php @@ -27,6 +27,9 @@ abstract class AbstractInvokeStrategy implements ActionEventListenerAggregate { use DetachAggregateHandlers; + /** + * @var int + */ protected $priority = 0; /** diff --git a/src/Plugin/InvokeStrategy/FinderInvokeStrategy.php b/src/Plugin/InvokeStrategy/FinderInvokeStrategy.php index 790f1f2..7d9e580 100644 --- a/src/Plugin/InvokeStrategy/FinderInvokeStrategy.php +++ b/src/Plugin/InvokeStrategy/FinderInvokeStrategy.php @@ -69,7 +69,7 @@ public function __invoke(ActionEvent $actionEvent) */ private function determineQueryName($query) { - $queryName = ($query instanceof HasMessageName)? $query->messageName() : is_object($query)? get_class($query) : gettype($query); + $queryName = ($query instanceof HasMessageName)? $query->messageName() : (is_object($query)? get_class($query) : gettype($query)); return implode('', array_slice(explode('\\', $queryName), -1)); } } diff --git a/src/Plugin/InvokeStrategy/HandleCommandStrategy.php b/src/Plugin/InvokeStrategy/HandleCommandStrategy.php index 4032419..0609997 100644 --- a/src/Plugin/InvokeStrategy/HandleCommandStrategy.php +++ b/src/Plugin/InvokeStrategy/HandleCommandStrategy.php @@ -54,7 +54,7 @@ public function invoke($handler, $message) */ protected function determineCommandName($message) { - $eventName = ($message instanceof HasMessageName)? $message->messageName() : is_object($message)? get_class($message) : gettype($message); + $eventName = ($message instanceof HasMessageName)? $message->messageName() : (is_object($message)? get_class($message) : gettype($message)); return implode('', array_slice(explode('\\', $eventName), -1)); } } diff --git a/src/Plugin/InvokeStrategy/OnEventStrategy.php b/src/Plugin/InvokeStrategy/OnEventStrategy.php index e759853..2b78973 100644 --- a/src/Plugin/InvokeStrategy/OnEventStrategy.php +++ b/src/Plugin/InvokeStrategy/OnEventStrategy.php @@ -21,6 +21,8 @@ */ class OnEventStrategy extends AbstractInvokeStrategy { + protected $foo = 'bar'; + /** * @param mixed $handler * @param mixed $message @@ -50,7 +52,7 @@ public function invoke($handler, $message) */ protected function determineEventName($event) { - $eventName = ($event instanceof HasMessageName)? $event->messageName() : is_object($event)? get_class($event) : gettype($event); + $eventName = ($event instanceof HasMessageName)? $event->messageName() : (is_object($event)? get_class($event) : gettype($event)); return implode('', array_slice(explode('\\', $eventName), -1)); } } diff --git a/tests/Mock/CustomMessageWithName.php b/tests/Mock/CustomMessageWithName.php new file mode 100644 index 0000000..3fbe6bd --- /dev/null +++ b/tests/Mock/CustomMessageWithName.php @@ -0,0 +1,38 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + * + * Date: 08/02/15 - 8:35 PM + */ + +namespace ProophTest\ServiceBus\Mock; + +use Prooph\Common\Messaging\HasMessageName; + +/** + * Class CustomMessage + * @package ProophTest\ServiceBus\Mock + */ +final class CustomMessageWithName implements HasMessageName +{ + private $text; + + public function __construct($text) + { + $this->text = $text; + } + + public function getText() + { + return $this->text; + } + + public function messageName() + { + return 'Prooph\Test\ServiceBus\Mock\CustomMessageWithSomeOtherName'; + } +} diff --git a/tests/Plugin/InvokeStrategy/FinderInvokeStrategyTest.php b/tests/Plugin/InvokeStrategy/FinderInvokeStrategyTest.php index c9a121c..e90d7a8 100644 --- a/tests/Plugin/InvokeStrategy/FinderInvokeStrategyTest.php +++ b/tests/Plugin/InvokeStrategy/FinderInvokeStrategyTest.php @@ -15,6 +15,7 @@ use Prooph\ServiceBus\Plugin\InvokeStrategy\FinderInvokeStrategy; use Prooph\ServiceBus\QueryBus; use ProophTest\ServiceBus\Mock\CustomMessage; +use ProophTest\ServiceBus\Mock\CustomMessageWithName; use ProophTest\ServiceBus\Mock\Finder; use React\Promise\Deferred; @@ -63,4 +64,20 @@ public function it_invokes_a_finder_which_has_method_named_like_the_query() $this->assertSame($this->actionEvent->getParam(QueryBus::EVENT_PARAM_DEFERRED), $finder->getLastDeferred()); $this->assertTrue($this->actionEvent->getParam(QueryBus::EVENT_PARAM_MESSAGE_HANDLED)); } + + /** + * @test + */ + public function it_determines_the_query_name_from_message_name_call_if_event_has_one() + { + $finderInvokeStrategy = new FinderInvokeStrategy(); + $customQuery = new CustomMessageWithName("I am an event with a messageName() method"); + + $closure = function ($query) { + return $this->determineQueryName($query); + }; + $determineQueryName = $closure->bindTo($finderInvokeStrategy, $finderInvokeStrategy); + + $this->assertSame('CustomMessageWithSomeOtherName', $determineQueryName($customQuery)); + } } diff --git a/tests/Plugin/InvokeStrategy/HandleCommandStrategyTest.php b/tests/Plugin/InvokeStrategy/HandleCommandStrategyTest.php index 9669a1d..471337e 100644 --- a/tests/Plugin/InvokeStrategy/HandleCommandStrategyTest.php +++ b/tests/Plugin/InvokeStrategy/HandleCommandStrategyTest.php @@ -14,6 +14,7 @@ use Prooph\ServiceBus\Plugin\InvokeStrategy\HandleCommandStrategy; use ProophTest\ServiceBus\Mock\CustomMessage; use ProophTest\ServiceBus\Mock\CustomMessageCommandHandler; +use ProophTest\ServiceBus\Mock\CustomMessageWithName; use ProophTest\ServiceBus\Mock\MessageHandler; use ProophTest\ServiceBus\TestCase; @@ -60,4 +61,20 @@ public function it_invokes_the_handle_command_method_of_the_handler_without_comm $this->assertSame($doSomething, $handleCommandHandler->getLastMessage()); } + + /** + * @test + */ + public function it_determines_the_command_name_from_message_name_call_if_event_has_one() + { + $handleCommandStrategy = new HandleCommandStrategy(); + $customCommand = new CustomMessageWithName("I am an event with a messageName() method"); + + $closure = function ($command) { + return $this->determineCommandName($command); + }; + $determineCommandName = $closure->bindTo($handleCommandStrategy, $handleCommandStrategy); + + $this->assertSame('CustomMessageWithSomeOtherName', $determineCommandName($customCommand)); + } } diff --git a/tests/Plugin/InvokeStrategy/OnEventStrategyTest.php b/tests/Plugin/InvokeStrategy/OnEventStrategyTest.php index 231512a..83f810d 100644 --- a/tests/Plugin/InvokeStrategy/OnEventStrategyTest.php +++ b/tests/Plugin/InvokeStrategy/OnEventStrategyTest.php @@ -13,6 +13,7 @@ use Prooph\ServiceBus\Plugin\InvokeStrategy\OnEventStrategy; use ProophTest\ServiceBus\Mock\CustomMessage; +use ProophTest\ServiceBus\Mock\CustomMessageWithName; use ProophTest\ServiceBus\Mock\MessageHandler; use ProophTest\ServiceBus\TestCase; @@ -41,4 +42,20 @@ public function it_invokes_the_on_event_method_of_the_handler() $this->assertSame($customEvent, $onEventHandler->getLastMessage()); } + + /** + * @test + */ + public function it_determines_the_event_name_from_message_name_call_if_event_has_one() + { + $onEventStrategy = new OnEventStrategy(); + $customEvent = new CustomMessageWithName("I am an event with a messageName() method"); + + $closure = function ($event) { + return $this->determineEventName($event); + }; + $determineEventName = $closure->bindTo($onEventStrategy, $onEventStrategy); + + $this->assertSame('CustomMessageWithSomeOtherName', $determineEventName($customEvent)); + } }