public function postAction(Request $request, $resource) { $response = $this->response; $router = $this->router; return $this->handler->handle($request, $this->response, $resource, function (ManagerInterface $manager, $object) use($response, $resource, $router) { $manager->create($object); $response->setStatusCode(201); $response->headers->set('Location', $router->generate('lemon_rest_get', array('resource' => $resource, 'id' => IdHelper::getId($object)), RouterInterface::ABSOLUTE_URL)); return $object; }); }
public function testInvalidMethod() { $registry = $this->container->get('lemon_rest.object_registry'); $definition = new Definition('place', 'Lemon\\RestBundle\\Tests\\Fixtures\\Place', true, false, false, true, false); $registry->add($definition); $place1 = new Place(); $place1->name = "Seymour"; $this->em->persist($place1); $this->em->flush($place1); $this->em->clear(); $place2 = new Place(); $place2->name = "Brownstown"; $this->em->persist($place2); $this->em->flush($place2); $this->em->clear(); $places = $this->em->getRepository('Lemon\\RestBundle\\Tests\\Fixtures\\Place')->findAll(); $this->assertCount(2, $places); $request = $this->makeRequest('POST', '/place', json_encode(array('name' => 'Smallville'))); /** @var \Symfony\Component\HttpFoundation\Response $response */ $response = $this->controller->postAction($request, 'place'); $this->assertEquals(405, $response->getStatusCode()); $request = $this->makeRequest('GET', '/place'); /** @var \Symfony\Component\HttpFoundation\Response $response */ $response = $this->controller->listAction($request, 'place'); $this->assertEquals(2, $response->headers->get('X-Total-Count')); }