/** * @test */ public function purgeShouldResultInAnEmptyQueue() { $this->adapter->purge(); for ($x = 10; $x <= 10; $x++) { $this->adapter->enqueue("message {$x}", 'tenhunen'); } list($msg, $identifier, $internals) = $this->adapter->dequeue(); $this->assertInternalType('string', $msg); $this->adapter->ack($identifier, $internals); $this->adapter->purge(); $this->assertFalse($this->adapter->dequeue()); }
/** * Dequeues message * * @return Message */ public function dequeue() { $raw = $this->adapter->dequeue(); if (!$raw) { return false; } list($json, $identifier, $internals) = $raw; $json = $this->inputFilters->filter($json); $json = json_decode($json, true); $serialized = SerializedData::fromJson($json['data']); $serializer = $this->dataSerializers->getUnserializerFor($serialized); if (!$serializer) { throw (new RuntimeException('Unserializer not found'))->setContext($raw); } $json['data'] = $serializer->unserialize($serialized->getData()); $message = Message::fromArray($json); $message->setIdentifier($identifier); foreach ($internals as $key => $value) { $message->setInternal($key, $value); } return $message; }