/** * @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 \CargoBackend\API\Exception\CargoNotFoundException * @throws \Exception * @return void */ public function assignCargoToRoute($aTrackingId, RouteCandidateDto $aRoute) { $cargo = $this->cargoRepository->get(TrackingId::fromString($aTrackingId)); if (!$cargo) { throw new CargoNotFoundException(sprintf('Cargo with TrackingId -%s- could not be found', $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; } }