public function run(Command $command) { $this->exceptionIfCommandNotManaged($command); $request = $command->getRequest(); $trip = Trip::createWithFirstRoute(new TripIdentity(uniqid()), $request->get('name')); $this->tripRepository->add($trip); return $trip; }
public function testAdd() { $identity = uniqid(); $tripIdentity = new TripIdentity($identity); $trip = Trip::createWithFirstRoute($tripIdentity, 'another trip'); $this->repo->add($trip); $trip = $this->em->getRepository('TripPlannerDomain:Trip')->findOneBy(array('name' => 'another trip')); $this->assertInstanceOf('Leopro\\TripPlanner\\Domain\\Entity\\Trip', $trip); }
public function load(ObjectManager $manager) { $tripIdentity = new TripIdentity('abcd'); $trip = Trip::createWithFirstRoute($tripIdentity, 'my complete trip'); $route = $trip->getRoutes()->first(); $route->addLeg('01/01/2014', -3.386665, 36.736908, 'd/m/Y'); $manager->persist($trip); $manager->flush(); }
public function testCreateTrip() { $trip = Trip::createWithFirstRoute(new TripIdentity(1), 'my first planning'); $this->assertEquals(0, $trip->getRoute(null)->getLegs()->count()); $tripRepository = $this->getMockBuilder('Leopro\\TripPlanner\\Domain\\Contract\\TripRepository')->disableOriginalConstructor()->getMock(); $tripRepository->expects($this->once())->method('get')->will($this->returnValue($trip)); $tripRepository->expects($this->once())->method('add'); $command = new AddLegToRouteCommand('abcde', null, '01/01/2014', 'd/m/Y', -3.386665, 36.736908); $useCase = new AddLegToRouteUseCase($tripRepository); $trip = $useCase->run($command); $this->assertInstanceOf('Leopro\\TripPlanner\\Domain\\Entity\\Trip', $trip); $this->assertEquals(1, $trip->getRoute(null)->getLegs()->count()); }
public function testCreateTrip() { $trip = Trip::createWithFirstRoute(new TripIdentity(1), 'my first planning'); $route = $trip->getRoute(null); $route->addLeg('01-01-2014', -3.386665, 36.736908); $tripRepository = $this->getMockBuilder('Leopro\\TripPlanner\\Domain\\Contract\\TripRepository')->disableOriginalConstructor()->getMock(); $tripRepository->expects($this->once())->method('get')->will($this->returnValue($trip)); $tripRepository->expects($this->once())->method('add'); $command = new UpdateLocationCommand(null, '01-01-2014', 'new location name'); $useCase = new UpdateLocationUseCase($tripRepository); $trip = $useCase->run($command); $this->assertInstanceOf('Leopro\\TripPlanner\\Domain\\Entity\\Trip', $trip); $this->assertEquals('new location name', $route->getLegs()->first()->getLocation()->getName()); }
public function testADuplicatedRouteCouldBeAdded() { $trip = Trip::createWithFirstRoute(new TripIdentity(1), 'my first planning'); $trip->duplicateRoute(null); $this->assertEquals(2, $trip->getRoutes()->count()); }