/** * @test * @dataProvider exceptionResponseProvider * * @param \Exception $exception * @param Rsp $expectedResponse */ public function it_can_convert_exceptions_into_responses(\Exception $exception, Rsp $expectedResponse) { // Technically it's not the EventRepository that throws these // exceptions, but it's the easiest to mock and the code doesn't care // where the exception was thrown exactly. $this->eventRepository->expects($this->once())->method('save')->willThrowException($exception); // Mocking any supported request will cause the controller to check // for any exceptions. Deleting a keyword is easiest at the moment. $cdbid = '004aea08-e13d-48c9-b9eb-a18f20e6d44e'; $request = Request::create("/event/{$cdbid}/keywords", Request::METHOD_DELETE); $request->query->set('keyword', 'foo'); $response = $this->controller->deleteKeyword($request, $cdbid); // Make sure we get the expected response for the given exception. $this->assertEquals($expectedResponse->toXml(), $response->getContent()); }
/** * @param Rsp $rsp * @return Response */ private function createResponse(Rsp $rsp, $status = null) { $headers = array('Content-Type' => 'application/xml'); $xml = $rsp->toXml(); if (null === $status) { $status = $this->statusForRsp($rsp); } return new Response($xml, $status, $headers); }