/**
  * Edit car form submit action.
  *
  * Route: /car/{id}
  *
  * @param \Symfony\Component\HttpFoundation\Request $request
  *  Request.
  * @param integer $id
  *  Car identifier.
  *
  * @return \Symfony\Component\HttpFoundation\RedirectResponse
  */
 public function editSubmitAction(Request $request, $id)
 {
     // Fetch the data, both required for the test to clear.
     $data = (array) $request->getContent();
     $data += $request->request->all();
     // Find the existing car entity.
     $car = $this->getCarOrFail($id);
     $hydrator = new Hydrator();
     $em = $this->getDoctrine()->getManager();
     // Hydrate th car entity
     $hydrator->hydrate($car, $data);
     $car->setUpdated(new \DateTime());
     $em->persist($car);
     $em->flush();
     return $this->redirectToRoute('app_home');
 }
 /**
  * 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']);
 }