/** * @param string $topic * @param mixed $data * @return Message * @throws RuntimeException */ public function enqueue($topic, $data = null) { $serializer = $this->dataSerializers->getSerializerFor($data); if (!$serializer) { throw new RuntimeException("Serializer not found"); } $serializedData = new SerializedData($serializer->getIdentifier(), $serializer->serialize($data)); $message = Message::create($topic, $data); $arr = array('uuid' => $message->getUuid(), 'topic' => $message->getTopic(), 'data' => $serializedData->toJson()); $json = json_encode($arr); $json = $this->outputFilters->filter($json); try { $this->adapter->enqueue($json, $topic); return $message; } catch (\Exception $e) { throw new RuntimeException('Queuing a message failed', 0, $e); } }
/** * @test */ public function unknownDataThrowsExceptionWhenUnserializing() { $this->setExpectedException('RuntimeException', 'Unserializer not found'); $serialized = new SerializedData('SomeRandomSerializer', 'xooxoo'); $arr = array('uuid' => 'uuid', 'topic' => 'lus.tus', 'data' => $serialized->toJson()); $json = json_encode($arr); $this->adapter->expects($this->once())->method('dequeue')->will($this->returnValue(array($json, 'aybabtu', []))); $this->queue->dequeue(); }