forked from php-enqueue/enqueue-dev
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDelegateProcessorTest.php
78 lines (66 loc) · 2.16 KB
/
DelegateProcessorTest.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
<?php
namespace Enqueue\Tests\Client;
use Enqueue\Client\Config;
use Enqueue\Client\DelegateProcessor;
use Enqueue\Null\NullMessage;
use Enqueue\ProcessorRegistryInterface;
use Interop\Queue\Context;
use Interop\Queue\Processor;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;
class DelegateProcessorTest extends TestCase
{
public function testShouldThrowExceptionIfProcessorNameIsNotSet()
{
$this->expectException(\LogicException::class);
$this->expectExceptionMessage('Got message without required parameter: "enqueue.processor"');
$processor = new DelegateProcessor($this->createProcessorRegistryMock());
$processor->process(new NullMessage(), $this->createContextMock());
}
public function testShouldProcessMessage()
{
$session = $this->createContextMock();
$message = new NullMessage();
$message->setProperties([
Config::PROCESSOR => 'processor-name',
]);
$processor = $this->createProcessorMock();
$processor
->expects($this->once())
->method('process')
->with($this->identicalTo($message), $this->identicalTo($session))
->willReturn('return-value')
;
$processorRegistry = $this->createProcessorRegistryMock();
$processorRegistry
->expects($this->once())
->method('get')
->with('processor-name')
->willReturn($processor)
;
$processor = new DelegateProcessor($processorRegistry);
$return = $processor->process($message, $session);
$this->assertEquals('return-value', $return);
}
/**
* @return MockObject|ProcessorRegistryInterface
*/
protected function createProcessorRegistryMock()
{
return $this->createMock(ProcessorRegistryInterface::class);
}
/**
* @return MockObject|Context
*/
protected function createContextMock()
{
return $this->createMock(Context::class);
}
/**
* @return MockObject|Processor
*/
protected function createProcessorMock()
{
return $this->createMock(Processor::class);
}
}