/** * @param Event $event */ public function on(Event $event) { $handled = false; /* @var $sagaType string */ foreach ($this->sagaTypes as $sagaType) { $associationValues = $this->extractAssociationValues($sagaType, $event); /* @var $associationValue AssociationValue */ foreach ($associationValues->getIterator() as $associationValue) { $sagaIdentities = $this->repository->find($sagaType, $associationValue); /* @var $identity Identity */ foreach ($sagaIdentities as $identity) { $saga = $this->repository->load($identity, $sagaType); $saga->on($event); $this->commit($saga); $handled = true; } } if ($this->getSagaCreationPolicy($sagaType, $event) == SagaCreationPolicy::ALWAYS || !$handled && $this->getSagaCreationPolicy($sagaType, $event) == SagaCreationPolicy::IF_NONE_FOUND) { $saga = $this->factory->createSaga($sagaType, Identity::createNew(), $associationValues); $saga->on($event); $this->commit($saga); } } }
/** * @test */ public function loadReturnsNullIfSagaNotFound() { $storage = $this->createStorage(); $serializer = $this->createSerializer(); $sagaIdentity = Identity::createNew(); $storage->expects(self::once())->method('findById')->with($sagaIdentity->getValue())->willReturn(''); $repository = new SagaRepository($storage, $serializer); $actual = $repository->load($sagaIdentity, ''); self::assertNull($actual); }