Skip to content

Commit bc53b69

Browse files
committed
Refactor QueueTest
1 parent c1958cd commit bc53b69

File tree

1 file changed

+26
-20
lines changed

1 file changed

+26
-20
lines changed

tests/QueueTest.php

Lines changed: 26 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -422,16 +422,14 @@ public function testCount()
422422
*/
423423
public function ack()
424424
{
425-
$messageOne = $this->getMessage(['key1' => 0, 'key2' => true]);
426-
427-
$this->queue->send($messageOne);
428-
$this->queue->send($this->getMessage(['key' => 'value']));
429-
430-
$result = $this->queue->get($messageOne->getPayload())[0];
431-
$this->assertSame(2, $this->collection->count());
432-
433-
$this->queue->ack($result);
434-
$this->assertSame(1, $this->collection->count());
425+
$messages = [$this->getMessage(), $this->getMessage()];
426+
$this->sendAllMessages($messages);
427+
$count = $this->collection->count();
428+
$this->assertSame(2, $count);
429+
foreach ($this->queue->get([], ['maxNumberOfMessages' => 10]) as $message) {
430+
$this->queue->ack($message);
431+
$this->assertSame(--$count, $this->collection->count());
432+
}
435433
}
436434

437435
/**
@@ -441,18 +439,14 @@ public function ack()
441439
public function requeue()
442440
{
443441
$messages = [
444-
$this->getMessage(['id' => 1, 'key' => 'value']),
445-
$this->getMessage(['id' => 2, 'key' => 'value']),
446-
$this->getMessage(['id' => 3, 'key' => 'value']),
442+
$this->getMessage(['key' => 1]),
443+
$this->getMessage(['key' => 2]),
444+
$this->getMessage(['key' => 3]),
447445
];
448446

449-
foreach ($messages as $message) {
450-
$this->queue->send($message);
451-
}
452-
453-
$query = ['key' => 'value'];
447+
$this->sendAllMessages($messages);
454448

455-
$message = $this->queue->get($query)[0];
449+
$message = $this->queue->get([])[0];
456450

457451
$this->assertSameMessage($messages[0], $message);
458452

@@ -522,6 +516,18 @@ private function assertSingleMessage(Message $expected)
522516

523517
private function getMessage(array $payload = [], UTCDateTime $earliestGet = null, float $priority = 0.0)
524518
{
525-
return new Message(new ObjectId(), $payload, $earliestGet ?? new UTCDateTime(0), $priority);
519+
return new Message(
520+
new ObjectId(),
521+
$payload,
522+
$earliestGet ?? new UTCDateTime((int)microtime() * 1000),
523+
$priority
524+
);
525+
}
526+
527+
private function sendAllMessages(array $messages)
528+
{
529+
foreach ($messages as $message) {
530+
$this->queue->send($message);
531+
}
526532
}
527533
}

0 commit comments

Comments
 (0)