public function testCanReturnAMessageWithEnrichedMetadata() { $data = ['new_data' => 'new_data_value']; $enrichedMessage = $this->message->enrichMetadata($data); $this->assertNotSame($this->message, $enrichedMessage); $this->assertEquals($data, $enrichedMessage->metadata()->all()); $this->assertSame($this->message->identifier(), $enrichedMessage->identifier()); $this->assertSame($this->message->payload(), $enrichedMessage->payload()); $this->assertInstanceOf('RayRutjes\\DomainFoundation\\Message\\GenericMessage', $enrichedMessage); }
/** * @param AggregateRootIdentifier $aggregateRootIdentifier * @param int $sequenceNumber * @param MessageIdentifier $identifier * @param Serializable $payload * @param Metadata $metadata * @param ContractFactory $contractFactory */ public function __construct(AggregateRootIdentifier $aggregateRootIdentifier, $sequenceNumber, MessageIdentifier $identifier, Serializable $payload, Metadata $metadata = null, ContractFactory $contractFactory = null) { parent::__construct($identifier, $payload, $metadata, $contractFactory); if (!is_int($sequenceNumber)) { throw new \InvalidArgumentException('Sequence number should be an integer.'); } $this->sequenceNumber = $sequenceNumber; $this->aggregateRootIdentifier = $aggregateRootIdentifier; }
/** * @param array $data * * @return Message */ public function enrichMetadata(array $data) { $metadata = $this->message->metadata()->mergeWith($data); return new self($this->identifier(), $this->payload(), $metadata); }
/** * @param array $data * * @return Message */ public function enrichMetadata(array $data) { $metadata = $this->message->metadata()->mergeWith($data); return new self($this->aggregateRootIdentifier, $this->sequenceNumber, $this->identifier(), $this->payload(), $metadata); }
/** * @param string $commandName * @param MessageIdentifier $identifier * @param Serializable $payload * @param Metadata $metadata * @param ContractFactory $contractFactory */ public function __construct($commandName, MessageIdentifier $identifier, Serializable $payload, Metadata $metadata = null, ContractFactory $contractFactory = null) { parent::__construct($identifier, $payload, $metadata, $contractFactory); $this->commandName = $commandName; }