Пример #1
0
 public function extract(CarEntity $entity)
 {
     $data = [];
     $data['id'] = $entity->getId();
     $data['name'] = $entity->getName();
     $data['manufacturer'] = $entity->getManufacturer();
     $data['colour'] = $entity->getColour();
     $data['airConditioning'] = $entity->getAirConditioning();
     $data['centralLocking'] = $entity->getCentralLocking();
     $data['created'] = $entity->getCreated();
     $data['updated'] = $entity->getUpdated();
     return $data;
 }
 /**
  * Test the edit form submit method.
  */
 public function testEditSubmit()
 {
     $now = new \DateTime();
     $hydrator = new Hydrator();
     // Hydrate the car entity with some example data.
     $hydrator->hydrate($this->car, ['name' => 'polo', 'manufacturer' => 'vw', 'colour' => 'red', 'airConditioning' => true, 'centralLocking' => false, 'created' => $now, 'updated' => $now]);
     // Persist the entity to the database.
     $this->em->persist($this->car);
     $this->em->flush();
     $carId = $this->car->getId();
     $newData = ['name' => 'astra', 'manufacturer' => 'vauxhall', 'colour' => 'blue', 'airConditioning' => false, 'centralLocking' => true];
     // Issue the post request to update the existing car with new data.
     $this->client->request('POST', "/car/{$carId}", [], [], [], $newData);
     // Reload the car object.
     $car = static::$kernel->getContainer()->get('doctrine')->getRepository('AppBundle\\Entity\\Car')->find($carId);
     // Test for matching data.
     $this->assertEquals($car->getName(), $newData['name']);
     $this->assertEquals($car->getManufacturer(), $newData['manufacturer']);
     $this->assertEquals($car->getColour(), $newData['colour']);
     $this->assertEquals($car->getAirConditioning(), $newData['airConditioning']);
     $this->assertEquals($car->getCentralLocking(), $newData['centralLocking']);
 }
Пример #3
0
 /**
  * @param Car $car
  * @return boolean
  */
 public function has(Car $car)
 {
     return $this->cars->containsKey($car->getId());
 }
Пример #4
0
 public function isOrderedCar(Car $car)
 {
     $cars = $this->getOrderedCars();
     return array_key_exists($car->getId(), $cars);
 }
Пример #5
0
 /**
  * Displays a form to create a new Car entity.
  *
  * @Route("/hire/{car}", name="car_hire")
  * @Method("GET")
  * @param Request $request
  * @param Car $car
  * @return RedirectResponse
  */
 public function hireAction(Request $request, Car $car)
 {
     if ($car->getAmount() < 1) {
         $this->addFlash('error', 'Brak wolnych pojazdów');
         return $this->redirectToRoute('car_show', ['id' => $car->getId()]);
     }
     $entity = new Orders();
     $entity->setCar($car)->setUser($this->getUser())->setDays($request->get('days', 1))->setStatus('Do zapłaty');
     $car->setAmount($car->getAmount() - 1);
     $em = $this->getDoctrine()->getManager();
     $em->persist($entity);
     $em->flush();
     $this->addFlash('success', 'Zamówienie zostało zapisane, czekamy na kontakt w salonie');
     return $this->redirectToRoute('orders');
 }