public function testPostActionWithNestedExistingEntity() { $mother = new Person(); $mother->name = "Sharon Lemon"; $this->em->persist($mother); $this->em->flush($mother); $this->em->clear(); $request = $this->makeRequest('POST', '/person', json_encode(array('name' => "Stan Lemon", 'mother' => array('id' => $mother->id, 'name' => $mother->name)))); $response = $this->controller->postAction($request, 'person'); $data = json_decode($response->getContent()); $refresh = $this->em->getRepository('Lemon\\RestBundle\\Tests\\Fixtures\\Person')->findOneBy(array('id' => $data->id)); $this->assertNotNull($refresh); $this->assertEquals("Stan Lemon", $refresh->name); $this->assertNotNull($refresh->mother); $this->assertEquals($mother->id, $refresh->mother->id); $this->assertEquals($mother->name, $refresh->mother->name); }