/**
  * @test
  */
 public function it_returns_its_tracking_id()
 {
     $uuid = Uuid::uuid4();
     $routeSpecification = new RouteSpecification("Hongkong", "Hamburg");
     $cargo = new Cargo(new TrackingId($uuid), $routeSpecification);
     $checkTrackingId = new TrackingId($uuid);
     $this->assertTrue($checkTrackingId->sameValueAs($cargo->trackingId()));
 }
 /**
  * {@inheritdoc}
  *
  * @param TrackingId|null $value
  * @param AbstractPlatform $platform
  */
 public function convertToDatabaseValue($value, AbstractPlatform $platform)
 {
     if (null === $value) {
         return null;
     }
     if ($value instanceof TrackingId) {
         return $value->toString();
     }
     throw ConversionException::conversionFailed($value, self::NAME);
 }
 /**
  * @param TrackingId $aTrackingId
  * @return CargoNotFoundException
  */
 public static function forTrackingId(TrackingId $aTrackingId)
 {
     return new self(sprintf('Cargo with TrackingId -%s- can not be found.', $aTrackingId->toString()));
 }
 /**
  * @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;
     }
 }
 /**
  * @return TrackingId A unique, generated tracking Id.
  */
 public function getNextTrackingId() : TrackingId
 {
     return TrackingId::generate();
 }
 /**
  * @param TrackingId $other
  * @return bool
  */
 public function sameValueAs(TrackingId $other)
 {
     return $this->toString() === $other->toString();
 }
 /**
  * @test
  */
 public function it_is_not_same_value_as()
 {
     $trackingId = new TrackingId(Uuid::uuid4());
     $otherTrackingId = new TrackingId(Uuid::uuid4());
     $this->assertFalse($trackingId->sameValueAs($otherTrackingId));
 }