#abort_if 404 exception assertion not working.

6 messages · Page 1 of 1 (latest)

weak mural
#

hello folks:)

I would want to assert that the 404 Exception thrown by my abort_if is actually thrown, in my feature test :

        $this->expectException(NotFoundHttpException::class);

With the controller's method containing:

        abort_if(
            !app(AgencyUserHelper::class)->isEmployeeInAllAgencies($authenticated, $selectedAgenciesId),
            404,
            'Documents not found',
        );

However, it says that this exception is not thrown.
Do you know why please? 😅

(according to my logs,
Symfony\\Component\\HttpKernel\\Exception\\NotFoundHttpException is really thrown...)

keen dragon
#

Add assertStatus(404) too. If you want to check the response status.

weak mural
#

okay I think it's because I am in a FeatureTest

Indeed, it works like a charm in a unit test.

weak mural
keen dragon
#

Depends how you have exception handling configured. That’s why if you expect a 404 is good to assetStatus too

#

Your tests should check for everything you expect or don’t expect, you expect that not found exception & expect that gives a 404 status, so check both.