/** * {@inheritdoc} */ public static function deserialize(array $data) : QueryMessage { $keys = ['id', 'type', 'timestamp', 'meta_data', 'payload_type', 'payload']; foreach ($keys as $key) { if (!isset($data[$key])) { $message = sprintf('Invalid serialization data: %s', VarPrinter::toString($data)); throw new DomainException($message); } } if ($data['type'] !== MessageType::QUERY) { $message = sprintf('Invalid message type: %s', $data['type']); throw new DomainException($message); } /** @var MessageId $id */ $id = MessageId::fromString($data['id']); /** @var DateTime $timestamp */ $timestamp = DateTime::fromString($data['timestamp']); /** @var MetaData $metaData */ $metaData = MetaData::create($data['meta_data']); /** @var Type $payloadType */ $payloadType = Type::create($data['payload_type']); /** @var string $payloadClass */ $payloadClass = $payloadType->toClassName(); assert(Validate::implementsInterface($payloadClass, Query::class), sprintf('Unable to deserialize: %s', $payloadClass)); /** @var Query $payload */ $payload = $payloadClass::fromArray($data['payload']); return new static($id, $timestamp, $payload, $metaData); }
/** * @expectedException \Novuso\System\Exception\DomainException */ public function test_that_set_throws_exception_for_invalid_value() { $metaData = MetaData::create(); $metaData->set('foo', [new \stdClass()]); }
public function test_that_equals_returns_false_for_different_value() { $message = $this->message->mergeMetaData(MetaData::create(['ip_address' => '127.0.0.1'])); $this->assertFalse($this->message->equals($message)); }