Example #1
0
 public function testReconstructUsingExistingData()
 {
     $metadata = Metadata::from(['foo' => 'bar']);
     $id = Uuid::uuid4();
     $timestamp = DateTime::microsecondsNow();
     $eventMessage = new GenericEventMessage(new SomePayload(), $metadata, $id, $timestamp);
     $this->assertSame($timestamp, $eventMessage->getTimestamp());
     $this->assertSame($id, $eventMessage->getId());
     $this->assertSame($metadata, $eventMessage->getMetadata());
 }
Example #2
0
 public function testMicrosecondsNow()
 {
     $dateTime1 = DateTime::microsecondsNow();
     self::assertInstanceOf(DateTime::class, $dateTime1);
     $dateTime2 = DateTime::microsecondsNow();
     $diff = $dateTime2->format('U.u') - $dateTime1->format('U.u');
     self::assertGreaterThan(0, $diff);
     self::assertLessThan(1, $diff);
     $phpDateTime = new \DateTime();
     self::assertEquals($phpDateTime->getTimezone(), $dateTime1->getTimezone());
 }
Example #3
0
 /**
  * @param mixed $payload
  * @param Metadata|array|null $metadata
  * @param UuidInterface|null $id
  * @param DateTimeInterface|null $timestamp
  */
 public function __construct($payload, $metadata = null, UuidInterface $id = null, DateTimeInterface $timestamp = null)
 {
     parent::__construct($payload, $metadata, $id);
     $this->timestamp = $timestamp ?: DateTime::microsecondsNow();
 }