/**
  * @covers \PhpCqrs\Event\Listener\Exception\NoHandleMethodFound::forMessage
  */
 public function testCanConstructFromDomainEventMessage()
 {
     $message = GenericDomainEventMessage::forPayload('1', 1, new BookPublished('1234'));
     $exception = NoHandleMethodFound::forMessage($message);
     $this->assertInstanceOf(NoHandleMethodFound::class, $exception);
     $this->assertSame('No handle method for event BookPublished.', $exception->getMessage());
 }
Ejemplo n.º 2
0
 /**
  * @covers \PhpCqrs\Event\Store\MongoEventStore::__construct
  * @covers \PhpCqrs\Event\Store\MongoEventStore::save
  * @covers \PhpCqrs\Event\Store\MongoEventStore::load
  */
 public function testCanSaveAndLoadDomainEventStream()
 {
     $store = new PdoEventStore($this->pdo, new MessageSerializer(new Serializer()));
     $stream = new GenericDomainEventStream(GenericDomainEventMessage::forPayload('1234', '1', new BookRegistered('1234', 'Title!')), GenericDomainEventMessage::forPayload('1234', '2', new BookPublished('1234')));
     $store->save($stream);
     $this->assertEquals($stream, $store->load(new StringIdentifier('1234')));
 }
 /**
  * @covers \PhpCqrs\Domain\Serializer\Message\MessageSerializer::__construct
  * @covers \PhpCqrs\Domain\Serializer\Message\MessageSerializer::serialize
  * @covers \PhpCqrs\Domain\Serializer\Message\MessageSerializer::deserialize
  * @covers \PhpCqrs\Domain\Serializer\Message\MessageSerializer::payload
  */
 public function testCanSerializeAndDeserialize()
 {
     $serializer = new MessageSerializer(new Serializer());
     $message = GenericDomainEventMessage::forPayload('1234', 1, new BookPublished('1234'));
     $object = $serializer->serialize($message);
     $this->assertEquals($message, $serializer->deserialize($object));
 }
 /**
  * @covers \PhpCqrs\Event\Sourcing\EventSourcedAggregateRootTrait::initialize
  */
 public function testCanReconstituteFromEventStream()
 {
     $stream = new GenericDomainEventStream(GenericDomainEventMessage::forPayload('1', 1, new BookRegistered('1234', 'Title!')), GenericDomainEventMessage::forPayload('1', 2, new BookPublished('1234')));
     $book = Book::initialize(new StringIdentifier('1'), $stream);
     $this->assertInstanceOf(Book::class, $book);
     $this->assertSame(2, $book->sequence());
 }
 /**
  * @covers \PhpCqrs\Event\Publisher\LocatorEventPublisher::__construct
  * @covers \PhpCqrs\Event\Publisher\LocatorEventPublisher::publish
  */
 public function testCanDispatchCommand()
 {
     $locator = new InMemoryLocator();
     $listener = new BookPublishedEventListener();
     $locator->subscribe($listener, 'BookPublished');
     $publisher = new LocatorEventPublisher($locator);
     $payload = new BookPublished('1234');
     $message = GenericDomainEventMessage::forPayload('1', 1, $payload);
     $publisher->publish($message);
     $this->assertSame($payload, $listener->handled());
 }
Ejemplo n.º 6
0
 /**
  * @covers \PhpCqrs\Saga\SagaTrait::handle
  * @covers \PhpCqrs\Saga\SagaTrait::process
  * @covers \PhpCqrs\Saga\SagaTrait::commands
  * @return Saga
  */
 public function testCanProcessEventsToCommand()
 {
     $saga = new OrderConfirmationSaga();
     $stream = new GenericDomainEventStream(GenericDomainEventMessage::forPayload('1', 1, new CarRented('1')), GenericDomainEventMessage::forPayload('1', 1, new HotelReserved('1')), GenericDomainEventMessage::forPayload('1', 1, new FlightBooked('1')));
     foreach ($stream as $message) {
         $saga->handle($message);
     }
     $message = current($saga->commands());
     $this->assertEquals(new ConfirmOrder('1'), $message->payload());
     return $saga;
 }
 /**
  * @covers \PhpCqrs\Event\Listener\Locator\InMemoryLocator::locate
  */
 public function testCanNotLocateEventListener()
 {
     $locator = new InMemoryLocator();
     $message = GenericDomainEventMessage::forPayload('1', 1, new BookPublished('1234'));
     $this->assertSame([], $locator->locate($message));
 }
 /**
  * @covers \PhpCqrs\Event\Listener\CallableEventListener::handle
  * @covers \PhpCqrs\Event\Listener\CallableEventListener::method
  * @expectedException \PhpCqrs\Event\Listener\Exception\NoHandleMethodFound
  */
 public function testCanNotHandleMethod()
 {
     $listener = new BookPublishedEventListener();
     $message = GenericDomainEventMessage::forPayload('1', 1, new BookRegistered('1234', 'Title!'));
     $listener->handle($message);
 }
 /**
  * @covers \PhpCqrs\Domain\Event\GenericDomainEventMessage::forPayloadAndMetaData
  */
 public function testCanConstructForPayloadAndMetaData()
 {
     $message = GenericDomainEventMessage::forPayloadAndMetaData('1', 1, new BookPublished('1234'), new MetaData());
     $this->assertInstanceOf(GenericDomainEventMessage::class, $message);
 }
 /**
  * @covers \PhpCqrs\Domain\Event\GenericDomainEventStream::__construct
  * @return GenericDomainEventStream
  */
 public function testCanConstructAndIterate()
 {
     $stream = new GenericDomainEventStream(GenericDomainEventMessage::forPayload('1234', 1, new BookRegistered('1234', 'Title!')), GenericDomainEventMessage::forPayload('1234', 2, new BookPublished('1234')));
     return $stream;
 }
Ejemplo n.º 11
0
 /**
  * @param Payload  $payload
  * @param MetaData $metaData
  * @return void
  */
 protected function record(Payload $payload, MetaData $metaData)
 {
     $this->apply($payload, $metaData);
     $message = GenericDomainEventMessage::forPayloadAndMetaData($this->id(), $this->next(), $payload, $metaData);
     $this->events[] = $message;
 }