Lemon\RestBundle\Tests\Controller\ResourceControllerTest::testPutAction PHP Method

testPutAction() public method

public testPutAction ( )
    public function testPutAction()
    {
        $person = new Person();
        $person->name = "Stan Lemon";
        $person->created = new \DateTime("-1 day");
        $person->updated = new \DateTime("-12 hours");
        $this->em->persist($person);
        $this->em->flush($person);
        $this->em->clear();
        $created = date(DATE_ISO8601);
        $request = $this->makeRequest('PUT', '/person/' . $person->id, json_encode(array('id' => $person->id, 'name' => $person->name, 'created' => $created)));
        /** @var \Symfony\Component\HttpFoundation\Response $response */
        $response = $this->controller->putAction($request, 'person', $person->id);
        $data = json_decode($response->getContent());
        $this->assertEquals($person->id, $data->id);
        $this->assertEquals($person->name, $data->name);
        $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->assertEquals(new \DateTime($created), $refresh->created);
        $this->assertEquals($person->updated, $refresh->updated, "Excluded fields not get updated when not passed in");
    }