|
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; |
|
17
|
|
|
|
|
18
|
|
|
use Graze\Queue\Adapter\ArrayAdapter; |
|
19
|
|
|
use Graze\Queue\Message\MessageFactory; |
|
20
|
|
|
use Graze\Queue\Message\MessageInterface; |
|
21
|
|
|
use Graze\Queue\Test\TestCase; |
|
22
|
|
|
|
|
23
|
|
|
class ArrayIntegrationTest extends TestCase |
|
24
|
|
|
{ |
|
25
|
|
|
/** @var MessageInterface[] */ |
|
26
|
|
|
private $messages; |
|
27
|
|
|
/** @var Client */ |
|
28
|
|
|
private $client; |
|
29
|
|
|
|
|
30
|
|
|
public function setUp() |
|
31
|
|
|
{ |
|
32
|
|
|
$factory = new MessageFactory(); |
|
33
|
|
|
|
|
34
|
|
|
$this->messages = [ |
|
35
|
|
|
$factory->createMessage('foo'), |
|
36
|
|
|
$factory->createMessage('bar'), |
|
37
|
|
|
$factory->createMessage('baz'), |
|
38
|
|
|
]; |
|
39
|
|
|
|
|
40
|
|
|
$this->client = new Client(new ArrayAdapter($this->messages)); |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
public function testReceive() |
|
44
|
|
|
{ |
|
45
|
|
|
$msgs = []; |
|
46
|
|
|
$this->client->receive(function ($msg) use (&$msgs) { |
|
47
|
|
|
$msgs[] = $msg; |
|
48
|
|
|
}, 100); |
|
49
|
|
|
|
|
50
|
|
|
assertThat($msgs, is(identicalTo($this->messages))); |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
public function testReceiveWithPolling() |
|
54
|
|
|
{ |
|
55
|
|
|
$msgs = []; |
|
56
|
|
|
$this->client->receive(function ($msg) use (&$msgs) { |
|
57
|
|
|
$msgs[] = $msg; |
|
58
|
|
|
}, null); |
|
59
|
|
|
|
|
60
|
|
|
assertThat($msgs, is(identicalTo($this->messages))); |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
public function testReceiveWithNoMessages() |
|
64
|
|
|
{ |
|
65
|
|
|
$client = new Client(new ArrayAdapter()); |
|
66
|
|
|
|
|
67
|
|
|
$msgs = []; |
|
68
|
|
|
$client->receive(function ($msg) use (&$msgs) { |
|
69
|
|
|
$msgs[] = $msg; |
|
70
|
|
|
}, null); |
|
71
|
|
|
|
|
72
|
|
|
assertThat($msgs, is(emptyArray())); |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
|
public function testReceiveWithLimitAndNoMessages() |
|
76
|
|
|
{ |
|
77
|
|
|
$client = new Client(new ArrayAdapter()); |
|
78
|
|
|
|
|
79
|
|
|
$msgs = []; |
|
80
|
|
|
$client->receive(function ($msg) use (&$msgs) { |
|
81
|
|
|
$msgs[] = $msg; |
|
82
|
|
|
}, 10); |
|
83
|
|
|
|
|
84
|
|
|
assertThat($msgs, is(emptyArray())); |
|
85
|
|
|
} |
|
86
|
|
|
|
|
87
|
|
|
public function testSend() |
|
88
|
|
|
{ |
|
89
|
|
|
$this->client->send([$this->client->create('foo')]); |
|
90
|
|
|
} |
|
91
|
|
|
|
|
92
|
|
|
public function testPurge() |
|
93
|
|
|
{ |
|
94
|
|
|
$this->client->purge(); |
|
95
|
|
|
|
|
96
|
|
|
$msgs = []; |
|
97
|
|
|
$this->client->receive(function ($msg) use (&$msgs) { |
|
98
|
|
|
$msgs[] = $msg; |
|
99
|
|
|
}, null); |
|
100
|
|
|
|
|
101
|
|
|
assertThat($msgs, is(emptyArray())); |
|
102
|
|
|
} |
|
103
|
|
|
|
|
104
|
|
|
public function testDelete() |
|
105
|
|
|
{ |
|
106
|
|
|
$this->client->delete(); |
|
107
|
|
|
|
|
108
|
|
|
$msgs = []; |
|
109
|
|
|
$this->client->receive(function ($msg) use (&$msgs) { |
|
110
|
|
|
$msgs[] = $msg; |
|
111
|
|
|
}, null); |
|
112
|
|
|
|
|
113
|
|
|
assertThat($msgs, is(emptyArray())); |
|
114
|
|
|
} |
|
115
|
|
|
} |
|
116
|
|
|
|