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

testHttpException() public method

public testHttpException ( )
    public function testHttpException()
    {
        /** @var \Symfony\Component\EventDispatcher\EventDispatcher$eventDispatcher */
        $eventDispatcher = $this->container->get('lemon_rest.event_dispatcher');
        $eventDispatcher->addListener(RestEvents::PRE_CREATE, function () {
            throw new \Symfony\Component\HttpKernel\Exception\BadRequestHttpException("Bad Request");
        });
        $request = $this->makeRequest('POST', '/person', json_encode(array('name' => 'Stan Lemon', 'created' => date(DATE_ISO8601))));
        /** @var \Symfony\Component\HttpFoundation\Response $response */
        $response = $this->controller->postAction($request, 'person');
        $this->assertEquals(400, $response->getStatusCode());
        $data = json_decode($response->getContent());
        $this->assertEquals("Bad Request", $data->message);
    }