@@ -96,7 +96,7 @@ public function testShouldReceiveNoWaitFromQueueAndReturnNullIfNoMessageInQueue(
96
96
public function testShouldReceiveNoWaitFromQueueAndReturnMessageIfMessageInQueue ()
97
97
{
98
98
$ destination = new PheanstalkDestination ('theQueueName ' );
99
- $ message = new PheanstalkMessage ('theBody ' , ['foo ' => 'fooVal ' ], ['bar ' => 'barVal ' ]);
99
+ $ message = new PheanstalkMessage ('theBody ' , ['foo ' => 'fooVal ' ], ['bar ' => 'barVal ' ]);
100
100
101
101
$ job = new Job ('theJobId ' , json_encode ($ message ));
102
102
@@ -118,6 +118,109 @@ public function testShouldReceiveNoWaitFromQueueAndReturnMessageIfMessageInQueue
118
118
$ this ->assertSame ($ job , $ actualMessage ->getJob ());
119
119
}
120
120
121
+ public function testShouldAcknowledgeMessage ()
122
+ {
123
+ $ destination = new PheanstalkDestination ('theQueueName ' );
124
+ $ message = new PheanstalkMessage ();
125
+
126
+ $ job = new Job ('theJobId ' , json_encode ($ message ));
127
+ $ message ->setJob ($ job );
128
+
129
+ $ pheanstalk = $ this ->createPheanstalkMock ();
130
+ $ pheanstalk
131
+ ->expects ($ this ->once ())
132
+ ->method ('delete ' )
133
+ ->with ($ job )
134
+ ;
135
+
136
+ $ consumer = new PheanstalkConsumer ($ destination , $ pheanstalk );
137
+
138
+ $ consumer ->acknowledge ($ message );
139
+ }
140
+
141
+ public function testAcknowledgeShouldThrowExceptionIfMessageHasNoJob ()
142
+ {
143
+ $ destination = new PheanstalkDestination ('theQueueName ' );
144
+ $ pheanstalk = $ this ->createPheanstalkMock ();
145
+
146
+ $ consumer = new PheanstalkConsumer ($ destination , $ pheanstalk );
147
+
148
+ $ this ->expectException (\LogicException::class);
149
+ $ this ->expectExceptionMessage ('The message could not be acknowledged because it does not have job set. ' );
150
+
151
+ $ consumer ->acknowledge (new PheanstalkMessage ());
152
+ }
153
+
154
+ public function testShouldRejectMessage ()
155
+ {
156
+ $ destination = new PheanstalkDestination ('theQueueName ' );
157
+ $ message = new PheanstalkMessage ();
158
+
159
+ $ job = new Job ('theJobId ' , json_encode ($ message ));
160
+ $ message ->setJob ($ job );
161
+
162
+ $ pheanstalk = $ this ->createPheanstalkMock ();
163
+ $ pheanstalk
164
+ ->expects ($ this ->once ())
165
+ ->method ('delete ' )
166
+ ->with ($ job )
167
+ ;
168
+
169
+ $ consumer = new PheanstalkConsumer ($ destination , $ pheanstalk );
170
+
171
+ $ consumer ->reject ($ message );
172
+ }
173
+
174
+ public function testRejectShouldThrowExceptionIfMessageHasNoJob ()
175
+ {
176
+ $ destination = new PheanstalkDestination ('theQueueName ' );
177
+ $ pheanstalk = $ this ->createPheanstalkMock ();
178
+
179
+ $ consumer = new PheanstalkConsumer ($ destination , $ pheanstalk );
180
+
181
+ $ this ->expectException (\LogicException::class);
182
+ $ this ->expectExceptionMessage ('The message could not be rejected because it does not have job set. ' );
183
+
184
+ $ consumer ->reject (new PheanstalkMessage ());
185
+ }
186
+
187
+ public function testShouldRequeueMessage ()
188
+ {
189
+ $ destination = new PheanstalkDestination ('theQueueName ' );
190
+ $ message = new PheanstalkMessage ();
191
+
192
+ $ job = new Job ('theJobId ' , json_encode ($ message ));
193
+ $ message ->setJob ($ job );
194
+
195
+ $ pheanstalk = $ this ->createPheanstalkMock ();
196
+ $ pheanstalk
197
+ ->expects ($ this ->once ())
198
+ ->method ('release ' )
199
+ ->with ($ job , Pheanstalk::DEFAULT_PRIORITY , Pheanstalk::DEFAULT_DELAY )
200
+ ;
201
+ $ pheanstalk
202
+ ->expects ($ this ->never ())
203
+ ->method ('delete ' )
204
+ ;
205
+
206
+ $ consumer = new PheanstalkConsumer ($ destination , $ pheanstalk );
207
+
208
+ $ consumer ->reject ($ message , true );
209
+ }
210
+
211
+ public function testRequeueShouldThrowExceptionIfMessageHasNoJob ()
212
+ {
213
+ $ destination = new PheanstalkDestination ('theQueueName ' );
214
+ $ pheanstalk = $ this ->createPheanstalkMock ();
215
+
216
+ $ consumer = new PheanstalkConsumer ($ destination , $ pheanstalk );
217
+
218
+ $ this ->expectException (\LogicException::class);
219
+ $ this ->expectExceptionMessage ('The message could not be requeued because it does not have job set. ' );
220
+
221
+ $ consumer ->reject (new PheanstalkMessage (), true );
222
+ }
223
+
121
224
/**
122
225
* @return \PHPUnit_Framework_MockObject_MockObject|Pheanstalk
123
226
*/
0 commit comments