-
-
Notifications
You must be signed in to change notification settings - Fork 9.4k
/
HandlersLocatorTest.php
60 lines (51 loc) · 2.06 KB
/
HandlersLocatorTest.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
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Component\Messenger\Tests\Handler;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Messenger\Envelope;
use Symfony\Component\Messenger\Handler\HandlerDescriptor;
use Symfony\Component\Messenger\Handler\HandlersLocator;
use Symfony\Component\Messenger\Stamp\ReceivedStamp;
use Symfony\Component\Messenger\Tests\Fixtures\DummyMessage;
class HandlersLocatorTest extends TestCase
{
public function testItYieldsHandlerDescriptors()
{
$handler = $this->createPartialMock(HandlersLocatorTestCallable::class, ['__invoke']);
$locator = new HandlersLocator([
DummyMessage::class => [$handler],
]);
$this->assertEquals([new HandlerDescriptor($handler)], iterator_to_array($locator->getHandlers(new Envelope(new DummyMessage('a')))));
}
public function testItReturnsOnlyHandlersMatchingTransport()
{
$firstHandler = $this->createPartialMock(HandlersLocatorTestCallable::class, ['__invoke']);
$secondHandler = $this->createPartialMock(HandlersLocatorTestCallable::class, ['__invoke']);
$locator = new HandlersLocator([
DummyMessage::class => [
$first = new HandlerDescriptor($firstHandler, ['alias' => 'one']),
new HandlerDescriptor($this->createPartialMock(HandlersLocatorTestCallable::class, ['__invoke']), ['from_transport' => 'ignored', 'alias' => 'two']),
$second = new HandlerDescriptor($secondHandler, ['from_transport' => 'transportName', 'alias' => 'three']),
],
]);
$this->assertEquals([
$first,
$second,
], iterator_to_array($locator->getHandlers(
new Envelope(new DummyMessage('Body'), [new ReceivedStamp('transportName')])
)));
}
}
class HandlersLocatorTestCallable
{
public function __invoke()
{
}
}