Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
codeliner committed Feb 10, 2016
2 parents b784ed0 + 535b384 commit 613088f
Show file tree
Hide file tree
Showing 12 changed files with 100 additions and 7 deletions.
1 change: 0 additions & 1 deletion .coveralls.yml
@@ -1,4 +1,3 @@
# for php-coveralls
service_name: travis-ci
src_dir: src
coverage_clover: build/logs/clover.xml
2 changes: 1 addition & 1 deletion .travis.yml
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion src/CommandBus.php
Expand Up @@ -60,7 +60,7 @@ public function setActionEventEmitter(ActionEventEmitter $actionEventDispatcher)

/**
* @param mixed $command
* @throws \Exception
* @throws CommandDispatchException
* @return void
*/
public function dispatch($command)
Expand Down
3 changes: 3 additions & 0 deletions src/Plugin/InvokeStrategy/AbstractInvokeStrategy.php
Expand Up @@ -27,6 +27,9 @@ abstract class AbstractInvokeStrategy implements ActionEventListenerAggregate
{
use DetachAggregateHandlers;

/**
* @var int
*/
protected $priority = 0;

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Plugin/InvokeStrategy/FinderInvokeStrategy.php
Expand Up @@ -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));
}
}
2 changes: 1 addition & 1 deletion src/Plugin/InvokeStrategy/HandleCommandStrategy.php
Expand Up @@ -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));
}
}
4 changes: 3 additions & 1 deletion src/Plugin/InvokeStrategy/OnEventStrategy.php
Expand Up @@ -21,6 +21,8 @@
*/
class OnEventStrategy extends AbstractInvokeStrategy
{
protected $foo = 'bar';

/**
* @param mixed $handler
* @param mixed $message
Expand Down Expand Up @@ -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));
}
}
38 changes: 38 additions & 0 deletions tests/Mock/CustomMessageWithName.php
@@ -0,0 +1,38 @@
<?php
/*
* This file is part of the prooph/service-bus.
* (c) 2014-2015 prooph software GmbH <contact@prooph.de>
*
* 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';
}
}
17 changes: 17 additions & 0 deletions tests/Plugin/InvokeStrategy/FinderInvokeStrategyTest.php
Expand Up @@ -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;

Expand Down Expand Up @@ -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));
}
}
17 changes: 17 additions & 0 deletions tests/Plugin/InvokeStrategy/HandleCommandStrategyTest.php
Expand Up @@ -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;

Expand Down Expand Up @@ -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));
}
}
17 changes: 17 additions & 0 deletions tests/Plugin/InvokeStrategy/OnEventStrategyTest.php
Expand Up @@ -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;

Expand Down Expand Up @@ -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));
}
}

0 comments on commit 613088f

Please sign in to comment.