2
votes

According to the Codeption documentation I should be able to catch an HttpException by running the following:

$I->expectException(HttpException::class, function () {
    $I->amOnRoute('that-doesnt/exist');
});

However instead I get en error:

[RuntimeException] Call to undefined method FunctionalTester::expectException

I am using Codeception 2.4.3

2
Have you enabled Asserts module in functional.suite.yml? - Naktibalda
and I do not... well thats embarrassing. Please put as answer and I will accept. - keeg

2 Answers

5
votes

In order to make expectException method available in the tests, Assert module must be enabled in functional.suite.yml file:

modules:
    enabled:
        - Asserts
0
votes

In addition to @Naktibalda answer - in latest version of Codeception expectException was deprecated and replaced with expectThrowable: https://codeception.com/docs/modules/Asserts#expectThrowable