Create a console command that throws an exception:
public function actionFail() {
throw new \Exception("An exception is not ideal");
}
A non-zero return value.
A zero return value (https://github.com/yiisoft/yii2/blob/master/framework/base/ErrorHandler.php#L112)
...
if (!YII_ENV_TEST) {
\Yii::getLogger()->flush(true);
if (defined('HHVM_VERSION')) {
flush();
}
exit(1);
}
To me it would make more sense to always return exit code 1 in case we are handling an exception, no matter the environment.
Disagreed.
The code block you refer prevents application termination in case of exception in test mode.
Console application is often used during unit test running. Enforcing exit on error will cause it to terminate PHPUnit script.
Agree with @klimov-paul. The reason for handing it differently is running tests for commands.
Hi!
I've read carefully this and all similar issues. And I understand why behavior works so.
I don't ask to change it permanently. I suggest to provide possibility to manage this behavior.
Because it is problem, if you are running some console command while Continuous Integration.
Real Example:
passed. But really there was a bug - fixtures were not applied because one of them crashed:Additionally
I've tried to workaround this problem with ExitException: throw \yii\base\ExitException(1, 'error', 1);. But exit code still 0.
Most helpful comment
Disagreed.
The code block you refer prevents application termination in case of exception in test mode.
Console application is often used during unit test running. Enforcing exit on error will cause it to terminate PHPUnit script.