/**
  * @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()));
 }
 /**
  * Construct
  *
  * @param TrackingId $aTrackingId
  * @param RouteSpecification $aRouteSpecification
  */
 public function __construct(TrackingId $aTrackingId, RouteSpecification $aRouteSpecification)
 {
     //Unfortunately, doctrine does not work with ValueObjects as identifier,
     //so we have to use the string representation internally
     //@see http://www.doctrine-project.org/jira/browse/DDC-2984
     $this->trackingIdString = $aTrackingId->toString();
     //Construct is only called when the Cargo is initially created.
     //Doctrine do not call __construct when it recreates a persisted entity.
     //Therefor we can assign the origin here.
     //It will be always the same for that specific Cargo even if the RouteSpecification changes.
     $this->origin = $aRouteSpecification->origin();
     $this->routeSpecification = $aRouteSpecification;
 }
 /**
  * @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;
     }
 }
 /**
  * {@inheritDoc}
  */
 public function get(TrackingId $trackingId)
 {
     return $this->find($trackingId->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());
 }
 /**
  * @test
  */
 public function it_is_not_same_value_as()
 {
     $trackingId = new TrackingId(Uuid::uuid4());
     $otherTrackingId = new TrackingId(Uuid::uuid4());
     $this->assertFalse($trackingId->sameValueAs($otherTrackingId));
 }