public function testPutActionWithNestedCollectionAndExistingItemAndNewItem()
{
$car = new Car();
$car->name = 'Honda';
$car->year = 2006;
$person = new Person();
$person->name = "Stan Lemon";
$person->cars[] = $car;
$this->em->persist($person);
$this->em->flush($person);
$this->em->clear();
$request = $this->makeRequest('PUT', '/person/' . $person->id, json_encode(array('name' => $person->name, 'cars' => array(array('id' => $car->id, 'name' => "Honda Odyssey", 'year' => 2006), array('name' => "Mercedes Benz 300c", 'year' => 2013)))));
/** @var \Symfony\Component\HttpFoundation\Response $response */
$response = $this->controller->putAction($request, 'person', $person->id);
$data = json_decode($response->getContent());
$refresh = $this->em->getRepository('Lemon\\RestBundle\\Tests\\Fixtures\\Person')->findOneBy(array('id' => $data->id));
$this->assertNotNull($refresh);
$this->assertEquals($person->id, $refresh->id);
$this->assertEquals($person->name, $refresh->name);
$this->assertCount(2, $refresh->cars);
$this->assertArrayHasObjectWithValue("Honda Odyssey", $refresh->cars, 'name');
$this->assertArrayHasObjectWithValue("2006", $refresh->cars, 'year');
$this->assertArrayHasObjectWithValue("Mercedes Benz 300c", $refresh->cars, 'name');
$this->assertArrayHasObjectWithValue("2013", $refresh->cars, 'year');
}