protected function setUp()
 {
     $this->amqpPublisher = $this->getMock(AMQPPublisherInterface::class);
     $this->domainMessageNormalizer = $this->getMock(DomainMessageNormalizerInterface::class);
     $this->domainMessageNormalizerAMQPPublisherDecorator = new DomainMessageNormalizerAMQPPublisherDecorator($this->amqpPublisher, $this->domainMessageNormalizer);
     $this->domainMessage = new DomainMessage('F68E71A1-DBB0-4542-AEE5-BD937E095F74', 2, new Metadata(), new DummyEvent('F68E71A1-DBB0-4542-AEE5-BD937E095F74', 'test 123 456'), BroadwayDateTime::fromString('2015-01-02T08:40:00+0100'));
 }
 /**
  * @test
  */
 public function it_throws_runtime_exception_when_payload_is_not_serializable()
 {
     $this->expectSpecificationIsSatisfied();
     $domainMessage = new DomainMessage('F68E71A1-DBB0-4542-AEE5-BD937E095F74', 2, new Metadata(), new DummyEventNotSerializable('F68E71A1-DBB0-4542-AEE5-BD937E095F74', 'test 123 456'), BroadwayDateTime::fromString('2015-01-02T08:40:00+0100'));
     $this->setExpectedException(\RuntimeException::class, 'Unable to serialize CultuurNet\\BroadwayAMQP\\Dummies\\DummyEventNotSerializable');
     $this->amqpPublisher->handle($domainMessage);
 }
 /**
  * @test
  */
 public function it_can_deserialize_a_domain_message()
 {
     $jsonData = new String(file_get_contents(__DIR__ . '/Dummies/domain-message-dummy-event.json'));
     $expectedDomainMessage = new DomainMessage('message-id-123', 0, new Metadata(), new DummyEvent('foo', 'bla'), DateTime::fromString('2016-03-25'));
     $domainMessage = $this->domainMessageJSONDeserializer->deserialize($jsonData);
     $this->assertEquals($expectedDomainMessage, $domainMessage);
 }
 /**
  * @inheritDoc
  */
 public function load($id)
 {
     try {
         $feed = $this->eventStore->openStreamFeed($id);
     } catch (StreamNotFoundException $e) {
         throw new EventStreamNotFoundException($e->getMessage());
     }
     if ($feed->hasLink(LinkRelation::LAST())) {
         $feed = $this->eventStore->navigateStreamFeed($feed, LinkRelation::LAST());
     } else {
         $feed = $this->eventStore->navigateStreamFeed($feed, LinkRelation::FIRST());
     }
     $rel = LinkRelation::PREVIOUS();
     $messages = [];
     $i = 0;
     while ($feed !== null) {
         foreach ($this->sortEntries($feed->getEntries()) as $entry) {
             $event = $this->eventStore->readEvent($entry->getEventUrl());
             $data = $event->getData();
             $recordedOn = DateTime::fromString($data['broadway_recorded_on']);
             unset($data['broadway_recorded_on']);
             $messages[] = new DomainMessage($id, $event->getVersion(), new Metadata($event->getMetadata() ?: []), call_user_func([$event->getType(), 'deserialize'], $data), $recordedOn);
         }
         $feed = $this->eventStore->navigateStreamFeed($feed, $rel);
     }
     return new DomainEventStream($messages);
 }
 public function current()
 {
     $event = $this->innerIterator->current()->getEvent();
     $data = $event->getData();
     $recordedOn = DateTime::fromString($data['broadway_recorded_on']);
     unset($data['broadway_recorded_on']);
     return new DomainMessage($this->id, $event->getVersion(), new Metadata($event->getMetadata() ?: []), call_user_func([$event->getType(), 'deserialize'], $data), $recordedOn);
 }
 /**
  * @test
  */
 public function it_returns_a_normalized_event_stream_when_normalizers_are_set()
 {
     $normalizedDomainMessage = new DomainMessage('F68E71A1-DBB0-4542-AEE5-BD937E095F74', 2, new Metadata(), new DummyEventSubclass('F68E71A1-DBB0-4542-AEE5-BD937E095F74', 'test 123 456'), BroadwayDateTime::fromString('2015-01-02T08:40:00+0100'));
     $expectedDomainEventStream = new DomainEventStream(array($normalizedDomainMessage));
     $this->dummyNormalizer->expects($this->once())->method('normalize')->with($this->dummyDomainMessage)->willReturn($expectedDomainEventStream);
     $actualEventDomainStream = $this->combinedDomainMessageNormalizer->normalize($this->dummyDomainMessage);
     $this->assertEquals($expectedDomainEventStream, $actualEventDomainStream);
 }
Exemplo n.º 7
0
 /**
  * @test
  * @dataProvider idDataProvider
  */
 public function it_appends_to_an_already_existing_stream($id)
 {
     $dateTime = DateTime::fromString('2014-03-12T14:17:19.176169+00:00');
     $domainEventStream = new DomainEventStream(array($this->createDomainMessage($id, 0, $dateTime), $this->createDomainMessage($id, 1, $dateTime), $this->createDomainMessage($id, 2, $dateTime)));
     $this->eventStore->append($id, $domainEventStream);
     $appendedEventStream = new DomainEventStream(array($this->createDomainMessage($id, 3, $dateTime), $this->createDomainMessage($id, 4, $dateTime), $this->createDomainMessage($id, 5, $dateTime)));
     $this->eventStore->append($id, $appendedEventStream);
     $expected = new DomainEventStream(array($this->createDomainMessage($id, 0, $dateTime), $this->createDomainMessage($id, 1, $dateTime), $this->createDomainMessage($id, 2, $dateTime), $this->createDomainMessage($id, 3, $dateTime), $this->createDomainMessage($id, 4, $dateTime), $this->createDomainMessage($id, 5, $dateTime)));
     $this->assertEquals($expected, $this->eventStore->load($id));
 }
 /**
  * @test
  */
 public function it_should_deserialize_to_a_DomainMessage()
 {
     $metadata = new Metadata();
     $payload = [];
     $time = DateTime::fromString('2015-01-01');
     $event = new DomainMessage('a', 0, $metadata, $payload, $time);
     $serializer = new ThirdPartyPayloadAndMetadataDomainMessageSerializer($this->payloadSerializer, $this->metadataSerializer);
     $this->metadataSerializer->shouldReceive('deserialize')->with(['metadata'])->andReturn($metadata);
     $this->payloadSerializer->shouldReceive('deserialize')->with(['payload'])->andReturn($payload);
     $serialized = ['id' => 'a', 'playhead' => 0, 'metadata' => ['metadata'], 'payload' => ['payload'], 'recordedOn' => (new \DateTime('2015-01-01'))->format(DateTime::FORMAT_STRING)];
     $deserialized = $serializer->deserialize($serialized);
     $this->assertEquals($event, $deserialized);
 }
 /**
  * @test
  */
 public function metadata_is_saved_properly()
 {
     $id = (string) new UUID();
     $dateTime = DateTime::fromString('2014-03-12T14:17:19.176169+00:00');
     $metadata = ['foo' => 'bar'];
     $events = [$this->createDomainMessageWithMetadata($id, 0, $metadata, $dateTime, 'event-42')];
     $events = new DomainEventStream($events);
     $this->eventStore->append($id, $events);
     $events = $this->eventStore->load($id);
     $eventIterator = $events->getIterator();
     $firstMessage = $eventIterator->current();
     $this->assertEquals($metadata, $firstMessage->getMetadata()->serialize());
 }
 private function rebuildStream($id)
 {
     /** @var \Broadway\EventStore\EventStoreInterface $eventStore */
     $eventStore = app('Broadway\\EventStore\\EventStoreInterface');
     $stream = $eventStore->load($id);
     foreach ($stream->getIterator() as $event) {
         $limit = DateTime::fromString($this->limitDate);
         $recordedOnDate = $event->getRecordedOn();
         if ($recordedOnDate->comesAfter($limit)) {
             continue;
         }
         $this->addEventToBuffer($event);
         $this->guardBufferNotFull();
     }
 }
 /**
  * {@inheritdoc}
  */
 public function deserialize(array $serializedObject)
 {
     return new DomainMessage($serializedObject['uuid'], $serializedObject['playhead'], $this->metadataSerializer->deserialize(json_decode($serializedObject['metadata'], true)), $this->payloadSerializer->deserialize(json_decode($serializedObject['payload'], true)), DateTime::fromString($serializedObject['recorded_on']));
 }
 /**
  * @test
  */
 public function it_satisfies_payload_is_a_subclass_of()
 {
     $domainMessage = new DomainMessage('F68E71A1-DBB0-4542-AEE5-BD937E095F74', 2, new Metadata(), new DummyEventSubclass('F68E71A1-DBB0-4542-AEE5-BD937E095F74', 'test 123 456'), BroadwayDateTime::fromString('2015-01-02T08:40:00+0100'));
     $payloadIsInstanceOf = new PayloadIsInstanceOf(DummyEvent::class);
     $this->assertTrue($payloadIsInstanceOf->isSatisfiedBy($domainMessage));
 }
Exemplo n.º 13
0
 /**
  * @test
  */
 public function it_is_not_satisfied_when_none_match()
 {
     $domainMessage = new DomainMessage('F68E71A1-DBB0-4542-AEE5-BD937E095F74', 2, new Metadata(), new DummyEventNotSerializable('F68E71A1-DBB0-4542-AEE5-BD937E095F74', 'test 123 456'), BroadwayDateTime::fromString('2015-01-02T08:40:00+0100'));
     $this->assertFalse($this->anyOf->isSatisfiedBy($domainMessage));
 }
Exemplo n.º 14
0
 /**
  * @param $row
  * @return DomainMessage
  */
 protected function deserializeEvent($row)
 {
     $metadata = json_decode($row['metadata'], true);
     $payload = json_decode($row['payload'], true);
     return new DomainMessage($row['uuid'], $row['playhead'], $this->metadataSerializer->deserialize($metadata, $metadata['payload']), $this->payloadSerializer->deserialize($payload, $payload['payload']), DateTime::fromString($row['recorded_on']));
 }
 /**
  * @test
  */
 public function it_throws_serialization_exception_when_payload_is_not_serializable()
 {
     $this->setExpectedException(SerializationException::class, 'Unable to serialize CultuurNet\\BroadwayAMQP\\Dummies\\DummyEventNotSerializable');
     $domainMessage = new DomainMessage('F68E71A1-DBB0-4542-AEE5-BD937E095F74', 2, new Metadata(), new DummyEventNotSerializable('F68E71A1-DBB0-4542-AEE5-BD937E095F74', 'test 123 456'), BroadwayDateTime::fromString('2015-01-02T08:40:00+0100'));
     $this->entireDomainMessageBodyFactory->createBody($domainMessage);
 }
 private function createDomainMessage()
 {
     return new DomainMessage(1337, 42, new Metadata([]), new Event(), DateTime::fromString('2015-03-14 13:37:42'));
 }
Exemplo n.º 17
0
 /**
  * @test
  * @dataProvider provideBeginningOfWeek
  */
 public function it_converts_to_the_beginning_of_week($dateTime, $expectedBeginningOfWeek)
 {
     $beginningOfWeek = DateTime::fromString($dateTime)->toBeginningOfWeek();
     $this->assertEquals(DateTime::fromString($expectedBeginningOfWeek), $beginningOfWeek);
 }
 /**
  * @inheritdoc
  */
 public function deserialize(StringLiteral $data)
 {
     $data = parent::deserialize($data);
     $payloadClass = $this->payloadClass;
     return new DomainMessage($data['id'], $data['playhead'], Metadata::deserialize($data['metadata']), $payloadClass::deserialize($data['payload']), DateTime::fromString($data['recorded_on']));
 }
 /**
  * Hydrates a DomainEventStream from an array of database records.
  *
  * @param array $records The array representation of
  *                                    the domain messages.
  * @throws SerializationException     When the serializers cannot perform.
  * @return DomainEventStreamInterface A DomainEventStream.
  */
 public function deserialize(array $records)
 {
     $payloadSerializer = $this->payloadSerializer;
     $metaSerializer = $this->metadataSerializer;
     $messages = array_map(function ($row) use($payloadSerializer, $metaSerializer) {
         // laravel db returns stdClass objects
         $row = (array) $row;
         // Unfortunately Broadway's default implementation require this.
         return new DomainMessage($row['uuid'], $row['playhead'], $metaSerializer->deserialize(json_decode($row['metadata'], true)), $payloadSerializer->deserialize(json_decode($row['payload'], true)), DateTime::fromString($row['recorded_on']));
     }, $records);
     return new DomainEventStream($messages);
 }
Exemplo n.º 20
0
 private function deserializeEvent($row)
 {
     return new DomainMessage($row['uuid'], $row['playhead'], $this->metadataSerializer->deserialize(json_decode($row['metadata'], true)), $this->payloadSerializer->deserialize(json_decode($row['payload'], true)), DateTime::fromString($row['recorded_on']));
 }
 private function createDomainMessage($payload)
 {
     return new DomainMessage(1, 1, new Metadata(array()), new SimpleTestEvent($payload), DateTime::fromString('2015-11-29 18:24:55.072250'));
 }
 /**
  * Deserialize a result row to a DomainMessage
  *
  * @author Dennis Schepers
  *
  * @param $row
  *
  * @return \Broadway\Domain\DomainMessage
  */
 private function deserializeEvent($event)
 {
     return new DomainMessage($event->uuid, (int) $event->playhead, $this->deserialize($event->metadata), $this->deserialize($event->payload), DateTime::fromString($event->recorded_on));
 }
 protected function setUp()
 {
     $this->domainMessage = new DomainMessage('F68E71A1-DBB0-4542-AEE5-BD937E095F74', 2, new Metadata(), new DummyEvent('F68E71A1-DBB0-4542-AEE5-BD937E095F74', 'test 123 456'), BroadwayDateTime::fromString('2015-01-02T08:40:00+0100'));
 }