/** * @test */ public function it_assigns_cargo_to_route() { $trackingId = $this->bookingService->bookNewCargo('USNYC', 'DEHAM'); $routeCandidates = $this->bookingService->requestPossibleRoutesForCargo($trackingId); $this->bookingService->assignCargoToRoute($trackingId, $routeCandidates[0]); $cargo = $this->cargoRepository->get(TrackingId::fromString($trackingId)); $legs = $cargo->itinerary()->legs(); $this->assertEquals(1, count($legs)); $this->assertEquals('USNYC', $legs[0]->loadLocation()); $this->assertEquals('DEHAM', $legs[0]->unloadLocation()); }
/** * @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; } }
/** * @test */ public function it_constructs_itself_from_string() { $uuid = Uuid::uuid4(); $trackingId = TrackingId::fromString($uuid->toString()); $this->assertEquals($uuid->toString(), $trackingId->toString()); }