public function testPutActionWithNestedCollectionAndExistingItem()
{
$created = new \DateTime();
$created->modify("-1 month");
$car = new Car();
$car->name = 'Honda';
$car->year = 2006;
$car->created = $created;
$tag = new Tag();
$tag->name = 'foo';
$person = new Person();
$person->name = "Stan Lemon";
$car->person = $person;
$person->cars[] = $car;
$person->tags[] = $tag;
$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)), 'tags' => array(array('id' => $tag->id, 'name' => $tag->name), array('name' => 'bar')))));
/** @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(1, $refresh->cars);
$this->assertEquals("Honda Odyssey", $refresh->cars[0]->name);
$this->assertEquals(2006, $refresh->cars[0]->year);
$this->assertNotNull($refresh->cars[0]->created);
$this->assertEquals($created->format('U'), $refresh->cars[0]->created->format('U'));
$this->assertCount(2, $refresh->tags);
$this->assertEquals($tag->id, $refresh->tags[0]->id);
$this->assertEquals($tag->name, $refresh->tags[0]->name);
}