/** * {@inheritDoc} */ public function save(State $state, $sagaId) { if ($state->isDone()) { unset($this->states[$sagaId][$state->getId()]); } else { $this->states[$sagaId][$state->getId()] = $state; } }
/** * {@inheritDoc} */ public function save(State $state, $sagaId) { $serializedState = $state->serialize(); $serializedState['_id'] = $serializedState['id']; $serializedState['sagaId'] = $sagaId; $serializedState['removed'] = $state->isDone(); $this->collection->save($serializedState); }
public function handleReservationRejected(ReservationRejected $event, State $state) { // the seat reservation for the given order is has been rejected, reject the order as well $command = new RejectOrder($state->get('orderId')); $this->commandBus->dispatch($command); // the saga ends here $state->setDone(); return $state; }
/** * @test */ public function it_returns_an_existing_state_instance_matching_the_returned_criteria() { $state = new State(1337); $state->set('appId', 1337); $this->repository->save($state, 'sagaId'); $criteria = new Criteria(array('appId' => 1337)); $resolvedState = $this->manager->findOneBy($criteria, 'sagaId'); self::assertEquals($state, $resolvedState); }
/** * @test */ public function it_can_be_serialized_and_deserialized_to_itself() { $this->state->set('foo', 'bar'); $state = State::deserialize($this->state->serialize()); $this->assertEquals($this->state, $state); $this->state->setDone(); $state = State::deserialize($this->state->serialize()); $this->assertEquals($this->state, $state); }
/** * @test */ public function saving_a_state_object_with_the_same_id_only_keeps_the_last_one() { $s1 = new State(31415); $s1->set('appId', 42); $this->repository->save($s1, 'sagaId'); $s2 = new State(31415); $s2->set('appId', 1337); $this->repository->save($s2, 'sagaId'); $found = $this->repository->findOneBy(new Criteria(array('appId' => 1337)), 'sagaId'); $this->assertEquals(31415, $found->getId()); }
public function handle($event, State $state = null) { $this->isCalled = true; if ($event instanceof TestEvent1) { $state->set('event', 'testevent1'); } elseif ($event instanceof TestEvent2) { $state->set('event', 'testevent2'); } elseif ($event instanceof TestEventDone) { $state->setDone(); } return $state; }