Exemple #1
0
 /**
  * @test
  */
 public function deserializeWillHydrateDeserializedSaga()
 {
     $serializer = new JsonSerializer();
     $factory = $this->createFactory();
     $saga = new SagaSerializerTest_Saga(Identity::createNew(), new AssociationValues([]));
     $sagaType = get_class($saga);
     $serializedSaga = $serializer->serialize($saga);
     $factory->expects(self::once())->method('hydrate')->with($saga);
     $sagaSerializer = new SagaSerializer($serializer, $factory);
     $sagaSerializer->deserialize($serializedSaga, $sagaType);
 }
 /**
  * @return void
  */
 public function run()
 {
     $logger = new Logger('default');
     $serializer = new JsonSerializer();
     $stateStorage = new MemoryStateStorage();
     $toDoItemProjections = new ToDoItemProjections($stateStorage);
     $eventStore = new EventStore(new SimpleEventBus([ToDoItemCreated::class => [$toDoItemProjections], ToDoItemDone::class => [$toDoItemProjections], DeadlineExpired::class => [$toDoItemProjections]]), new MemoryEventStorage(), $serializer, new EventClassMap([ToDoItemCreated::class, ToDoItemDone::class, DeadlineExpired::class]));
     $repository = new EventSourcingRepository(new GenericAggregateFactory(ToDoItem::class), $eventStore);
     $toDoItemCommandHandler = new ToDoCommandHandler($repository);
     $commandGateWay = new DefaultCommandGateway(new SimpleCommandBus([CreateToDoItem::class => $toDoItemCommandHandler, MarkItemDone::class => $toDoItemCommandHandler]), [new LoggingInterceptor(new CommandLogger($logger))]);
     $toDoId = Identity::createNew();
     $commandGateWay->send(new CreateToDoItem($toDoId, "Wash the dishes", 5));
     $logger->debug("Current state of ToDoItem", ['item' => $serializer->serialize($stateStorage->find($toDoId->getValue()))]);
     $commandGateWay->send(new MarkItemDone($toDoId));
     $logger->debug("Current state of ToDoItem", ['item' => $serializer->serialize($stateStorage->find($toDoId->getValue()))]);
 }
Exemple #3
0
 /**
  * @test
  */
 public function deleteRemovesSaga()
 {
     $serializer = new JsonSerializer();
     $sagaIdentity = Identity::createNew();
     $saga = $this->getMockBuilder(Saga::class)->setConstructorArgs([$sagaIdentity, new AssociationValues([new AssociationValue('foo', 'bar')])])->getMock();
     $storage = $this->createSagaStorage();
     $storage->insert(get_class($saga), $saga->getId()->getValue(), $this->associationValuesToArray($saga->getAssociationValues()), $serializer->serialize($saga));
     $storage->delete($sagaIdentity->getValue());
     $foundSaga = $storage->findById($sagaIdentity->getValue());
     self::assertEmpty($foundSaga);
 }