-
Notifications
You must be signed in to change notification settings - Fork 56
/
FinderInvokeStrategyTest.php
83 lines (69 loc) · 2.61 KB
/
FinderInvokeStrategyTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
<?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: 05/23/15 - 6:07 PM
*/
namespace ProophTest\ServiceBus\Plugin\InvokeStrategy;
use Prooph\Common\Event\DefaultActionEvent;
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;
/**
* Class FinderInvokeStrategyTest
*
* @package ProophTest\ServiceBus\Plugin\InvokeStrategy
*/
final class FinderInvokeStrategyTest extends \PHPUnit_Framework_TestCase
{
/**
* @var FinderInvokeStrategy
*/
private $finderInvokeStrategy;
/**
* @var DefaultActionEvent
*/
private $actionEvent;
protected function setUp()
{
$this->finderInvokeStrategy = new FinderInvokeStrategy();
$this->actionEvent = new DefaultActionEvent(QueryBus::EVENT_INVOKE_FINDER, new QueryBus(), [
QueryBus::EVENT_PARAM_MESSAGE => new CustomMessage('I am a query'),
QueryBus::EVENT_PARAM_MESSAGE_NAME => CustomMessage::class,
QueryBus::EVENT_PARAM_DEFERRED => new Deferred(),
]);
}
/**
* @test
*/
public function it_invokes_a_finder_which_has_method_named_like_the_query()
{
$finder = new Finder();
$this->actionEvent->setParam(QueryBus::EVENT_PARAM_MESSAGE_HANDLER, $finder);
$invokeStrategy = $this->finderInvokeStrategy;
$invokeStrategy($this->actionEvent);
$this->assertSame($this->actionEvent->getParam(QueryBus::EVENT_PARAM_MESSAGE), $finder->getLastMessage());
$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));
}
}