/**
  * {@inheritdoc}
  *
  * @param string|null                               $value
  * @param AbstractPlatform $platform
  */
 public function convertToPHPValue($value, AbstractPlatform $platform) : TrackingId
 {
     if (empty($value)) {
         return null;
     }
     if ($value instanceof TrackingId) {
         return $value;
     }
     try {
         $value = TrackingId::fromString($value);
     } catch (\Exception $ex) {
         throw ConversionException::conversionFailed($value, self::NAME);
     }
     return $value;
 }
 /**
  * @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 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;
     }
 }
 /**
  * @test
  */
 public function it_constructs_itself_from_string()
 {
     $uuid = Uuid::uuid4();
     $trackingId = TrackingId::fromString($uuid->toString());
     $this->assertEquals($uuid->toString(), $trackingId->toString());
 }