PHPunit: How to test a controller which throws an error.
Let’s say we have a method in a controller like this: /** ‘@Route (path’/add’, name'”add,” methods */ public function add (Request $request,): Response { throw new BadRequestHttpException (‘Error’); } To test that the exception is properly thrown, just write this public function testList(: void { $this->expectException(BadRequestHttpException::class); $client = self::createClient(); $client->catchExceptions (false); $crawler = $client->request ( … Read more