Open tahpot opened 5 years ago
Would you please try dev-master? Also it's a good idea to upgrade Codeception, there were fixes.
Thanks.
I upgraded Yii2 to dev-master and Codeception is v2.5.1 and the issue remains.
See here: https://github.com/Codeception/Codeception/blob/2.5/src/Codeception/Lib/Connector/Yii2.php#L336
Your exception must be an instance of HttpException or it will be passed up to codeception.
Thanks @joshgagnon
Isn't the flow supposed to be this?
Isn't the flow supposed to be this? /.../ Yii ErrorHandler catches exception, modifies output and raises HTTP 500 Exception
Normally it is. But Codeception explicitly disables Yii error handling for non-http exceptions.
I don't think that there is anything to do at Yii side, this behavior comes from Codeception. I also think that current behavior is correct - usually you expect that your code will work and converting all exceptions into HTTP 500 response will make debugging much harder.
What steps will reproduce the problem?
Create a REST API test that calls an action that throws an Exception.
This is the test:
What is the expected result?
Expect Yii2 to catch the Exception via ErrorHandler and still generate a valid JSON response that can be checked using Codeception.
For example $I->seeResponseCodeIs(HttpCode::INTERNAL_SERVER_ERROR); should return true, but the HTTP code seen by Codeception is null.
What do you get instead?
The Exception propagates up to Codeception which automatically fails the test and also causes the following tests to not have correct information.
Additional info
@samdark