|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* This file is part of graze/queue. |
|
5
|
|
|
* |
|
6
|
|
|
* Copyright (c) 2015 Nature Delivered Ltd. <https://www.graze.com> |
|
7
|
|
|
* |
|
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
9
|
|
|
* file that was distributed with this source code. |
|
10
|
|
|
* |
|
11
|
|
|
* @license https://github.com/graze/queue/blob/master/LICENSE MIT |
|
12
|
|
|
* |
|
13
|
|
|
* @link https://github.com/graze/queue |
|
14
|
|
|
*/ |
|
15
|
|
|
|
|
16
|
|
|
namespace Graze\Queue\Handler; |
|
17
|
|
|
|
|
18
|
|
|
use ArrayIterator; |
|
19
|
|
|
use Closure; |
|
20
|
|
|
use Graze\Queue\Adapter\AdapterInterface; |
|
21
|
|
|
use Graze\Queue\Message\MessageInterface; |
|
22
|
|
|
use Mockery as m; |
|
23
|
|
|
use Mockery\MockInterface; |
|
24
|
|
|
use Graze\Queue\Test\TestCase; |
|
25
|
|
|
|
|
26
|
|
|
class ResultAcknowledgementHandlerTest extends TestCase |
|
27
|
|
|
{ |
|
28
|
|
|
/** @var AdapterInterface|MockInterface */ |
|
29
|
|
|
private $adapter; |
|
30
|
|
|
/** @var ResultAcknowledgementHandler */ |
|
31
|
|
|
private $handler; |
|
32
|
|
|
/** @var MessageInterface|MockInterface */ |
|
33
|
|
|
private $message; |
|
34
|
|
|
/** @var ArrayIterator */ |
|
35
|
|
|
private $messages; |
|
36
|
|
|
|
|
37
|
|
|
public function setUp() |
|
38
|
|
|
{ |
|
39
|
|
|
$this->adapter = m::mock('Graze\Queue\Adapter\AdapterInterface'); |
|
40
|
|
|
|
|
41
|
|
|
$this->message = m::mock('Graze\Queue\Message\MessageInterface'); |
|
42
|
|
|
$this->messages = new ArrayIterator([$this->message]); |
|
43
|
|
|
|
|
44
|
|
|
$this->handler = new EagerAcknowledgementHandler(); |
|
|
|
|
|
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
public function testHandleTrueResult() |
|
48
|
|
|
{ |
|
49
|
|
|
$handler = new ResultAcknowledgementHandler(function ($result) { |
|
50
|
|
|
return $result === true; |
|
51
|
|
|
}, $this->handler); |
|
52
|
|
|
|
|
53
|
|
|
$this->message->shouldReceive('isValid')->once()->withNoArgs()->andReturn(true); |
|
|
|
|
|
|
54
|
|
|
$this->adapter->shouldReceive('acknowledge')->once()->with(m::mustBe([$this->message])); |
|
|
|
|
|
|
55
|
|
|
|
|
56
|
|
|
$msgs = []; |
|
57
|
|
|
$handler($this->messages, $this->adapter, function ($msg, Closure $done) use (&$msgs) { |
|
|
|
|
|
|
58
|
|
|
$msgs[] = $msg; |
|
59
|
|
|
return true; |
|
60
|
|
|
}); |
|
61
|
|
|
|
|
62
|
|
|
assertThat($msgs, is(identicalTo(iterator_to_array($this->messages)))); |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
public function testHandleNonTrueResponse() |
|
66
|
|
|
{ |
|
67
|
|
|
$handler = new ResultAcknowledgementHandler(function ($result) { |
|
68
|
|
|
return $result === true; |
|
69
|
|
|
}, $this->handler); |
|
70
|
|
|
|
|
71
|
|
|
$this->message->shouldReceive('isValid')->once()->withNoArgs()->andReturn(true); |
|
72
|
|
|
$this->adapter->shouldReceive('reject')->once()->with(m::mustBe([$this->message])); |
|
73
|
|
|
|
|
74
|
|
|
$handler($this->messages, $this->adapter, function ($msg, Closure $done) use (&$msgs) { |
|
|
|
|
|
|
75
|
|
|
return false; |
|
76
|
|
|
}); |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
|
public function testCustomResultAcknowledgementHandler() |
|
80
|
|
|
{ |
|
81
|
|
|
$handler = new ResultAcknowledgementHandler(function ($result) { |
|
82
|
|
|
return $result === false; |
|
83
|
|
|
}, $this->handler); |
|
84
|
|
|
|
|
85
|
|
|
$this->message->shouldReceive('isValid')->once()->withNoArgs()->andReturn(true); |
|
86
|
|
|
$this->adapter->shouldReceive('acknowledge')->once()->with(m::mustBe([$this->message])); |
|
87
|
|
|
|
|
88
|
|
|
$handler($this->messages, $this->adapter, function ($msg) { |
|
|
|
|
|
|
89
|
|
|
return false; |
|
90
|
|
|
}); |
|
91
|
|
|
} |
|
92
|
|
|
} |
|
93
|
|
|
|
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..