/**
  * @test
  */
 public function it_stores_and_returns_a_cargo()
 {
     $trackingId = $this->cargoRepository->getNextTrackingId();
     $routeSpecification = new RouteSpecification("Hongkong", "Hamburg");
     $cargo = new Cargo\Cargo($trackingId, $routeSpecification);
     $legs = [LegFixture::get(LegFixture::HONGKONG_NEWYORK), LegFixture::get(LegFixture::NEWYORK_HAMBURG)];
     $itinerary = new Cargo\Itinerary($legs);
     $cargo->assignToRoute($itinerary);
     $this->cargoRepository->store($cargo);
     $this->getTestEntityManager()->clear();
     $checkCargo = $this->cargoRepository->get($trackingId);
     $this->assertTrue($cargo->sameIdentityAs($checkCargo));
     $this->assertTrue($itinerary->sameValueAs($checkCargo->itinerary()));
 }
 /**
  * @param string $aTrackingId
  * @param RouteCandidateDto $aRoute
  * @throws CargoNotFoundException
  * @throws \Exception
  * @return void
  */
 public function assignCargoToRoute($aTrackingId, RouteCandidateDto $aRoute)
 {
     $aTrackingId = TrackingId::fromString($aTrackingId);
     $cargo = $this->cargoRepository->get($aTrackingId);
     if (!$cargo) {
         throw CargoNotFoundException::forTrackingId($aTrackingId);
     }
     $routeCandidateAssembler = new RouteCandidateDtoAssembler();
     $itinerary = $routeCandidateAssembler->toItinerary($aRoute);
     $this->transactionManager->beginTransaction();
     try {
         $cargo->assignToRoute($itinerary);
         $this->cargoRepository->store($cargo);
         $this->transactionManager->commit();
     } catch (\Exception $ex) {
         $this->transactionManager->rollback();
         throw $ex;
     }
 }