Lemon\RestBundle\Controller\ResourceController::patchAction PHP Method

patchAction() public method

public patchAction ( Request $request, string $resource, integer $id ) : Response
$request Symfony\Component\HttpFoundation\Request
$resource string
$id integer
return Symfony\Component\HttpFoundation\Response
    public function patchAction(Request $request, $resource, $id)
    {
        return $this->handler->handle($request, $this->response, $resource, function (ManagerInterface $manager, $object) use($id) {
            $manager->partialUpdate($object);
            return $object;
        });
    }

Usage Example

 public function testPatchAction()
 {
     $person = new Person();
     $person->name = 'Stan Lemon';
     $person->ssn = '123-45-678';
     $person->favoriteColor = 'purple';
     $this->em->persist($person);
     $this->em->flush($person);
     $this->em->clear();
     $request = $this->makeRequest('PATCH', '/person/' . $person->id, json_encode(array('id' => $person->id, 'favorite_color' => 'blue')));
     $this->controller->patchAction($request, 'person', $person->id);
     $refresh = $this->em->getRepository('Lemon\\RestBundle\\Tests\\Fixtures\\Person')->findOneBy(array('id' => $person->id));
     $this->assertEquals('blue', $refresh->favoriteColor);
     $this->assertEquals($person->ssn, $refresh->ssn);
     $this->assertEquals($person->name, $refresh->name);
 }