/**
  * @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 Cargo $aCargo
  * @return CargoRoutingDto
  */
 public function toDto(Cargo $aCargo)
 {
     $cargoRoutingDto = new CargoRoutingDto();
     $cargoRoutingDto->setTrackingId($aCargo->trackingId()->toString());
     $cargoRoutingDto->setOrigin($aCargo->origin());
     $cargoRoutingDto->setFinalDestination($aCargo->routeSpecification()->destination());
     foreach ($aCargo->itinerary()->legs() as $leg) {
         $legDto = new LegDto();
         $legDto->setLoadLocation($leg->loadLocation());
         $legDto->setUnloadLocation($leg->unloadLocation());
         $legDto->setLoadTime($leg->loadTime()->format(\DateTime::ISO8601));
         $legDto->setUnloadTime($leg->unloadTime()->format(\DateTime::ISO8601));
         $cargoRoutingDto->addLeg($legDto);
     }
     return $cargoRoutingDto;
 }
 /**
  * @test
  */
 public function it_detects_different_tracking_id()
 {
     $uuid = Uuid::uuid4();
     $routeSpecification = new RouteSpecification("Hongkong", "Hamburg");
     $cargo1 = new Cargo(new TrackingId($uuid), $routeSpecification);
     $uuid2 = Uuid::uuid4();
     $otherCargo = new Cargo(new TrackingId($uuid2), $routeSpecification);
     $this->assertFalse($cargo1->sameIdentityAs($otherCargo));
 }