反应处理期望
在下面的YII2框架中运行一个功能测试。
public function checkEmptyToken2(FunctionalTester $I)
{
$I->amOnRoute('site/verify-email', ['token' => '']);
$I->canSee('Email verify token did not come through for some reason');
}
导致下面的错误。
Codeception PHP Testing Framework v4.2.1
Powered by PHPUnit 8.5.27
Frontend\tests.functional Tests (1) -------------------------------------------------------------------------------------------------------------------------------------------------------------
E VerifyEmailCest: Check empty token2 (0.01s)
-------------------------------------------------------------------------------------------------------------------------------------------------------------
1) VerifyEmailCest: Check empty token2
Test tests/functional/VerifyEmailCest.php:checkEmptyToken2
[yii\base\UserException] Email verify token did not come through for some reason.
You can either copy/paste the verification email again OR
request a new verification email from the <a href="/index-test.php/site/login">Login</a> page.
Scenario Steps:
1. $I->amOnRoute("site/verify-email",{"token":""}) at tests/functional/VerifyEmailCest.php:41
#1 /data/www/frontend/models/VerifyEmailForm.php:38
#2 /data/www/frontend/controllers/SiteController.php:345
#3 frontend\controllers\SiteController->actionVerifyEmail
#4 /data/www/vendor/yiisoft/yii2/base/InlineAction.php:57
#5 /data/www/vendor/yiisoft/yii2/base/Controller.php:178
#6 /data/www/vendor/yiisoft/yii2/base/Module.php:552
#7 /data/www/vendor/yiisoft/yii2/web/Application.php:103
#8 /data/www/vendor/symfony/browser-kit/Client.php:405
#9 Codeception\Module\Yii2->amOnRoute
#10 /data/www/frontend/tests/_support/_generated/FunctionalTesterActions.php:661
Time: 718 ms, Memory: 16.00 MB
There was 1 error:
---------
ERRORS!
Tests: 1, Assertions: 0, Errors: 1.
我希望这是一个错误!我只想简单地忽略它并继续前进,以便我可以在“ cansee”中检查错误文本。我尝试使用try/catch语句,这会导致不同的错误。尝试使用“ ExpectException”,但也无法使用。
Running a function test as below for an application in Yii2 framework.
public function checkEmptyToken2(FunctionalTester $I)
{
$I->amOnRoute('site/verify-email', ['token' => '']);
$I->canSee('Email verify token did not come through for some reason');
}
Results in an error as below.
Codeception PHP Testing Framework v4.2.1
Powered by PHPUnit 8.5.27
Frontend\tests.functional Tests (1) -------------------------------------------------------------------------------------------------------------------------------------------------------------
E VerifyEmailCest: Check empty token2 (0.01s)
-------------------------------------------------------------------------------------------------------------------------------------------------------------
1) VerifyEmailCest: Check empty token2
Test tests/functional/VerifyEmailCest.php:checkEmptyToken2
[yii\base\UserException] Email verify token did not come through for some reason.
You can either copy/paste the verification email again OR
request a new verification email from the <a href="/index-test.php/site/login">Login</a> page.
Scenario Steps:
1. $I->amOnRoute("site/verify-email",{"token":""}) at tests/functional/VerifyEmailCest.php:41
#1 /data/www/frontend/models/VerifyEmailForm.php:38
#2 /data/www/frontend/controllers/SiteController.php:345
#3 frontend\controllers\SiteController->actionVerifyEmail
#4 /data/www/vendor/yiisoft/yii2/base/InlineAction.php:57
#5 /data/www/vendor/yiisoft/yii2/base/Controller.php:178
#6 /data/www/vendor/yiisoft/yii2/base/Module.php:552
#7 /data/www/vendor/yiisoft/yii2/web/Application.php:103
#8 /data/www/vendor/symfony/browser-kit/Client.php:405
#9 Codeception\Module\Yii2->amOnRoute
#10 /data/www/frontend/tests/_support/_generated/FunctionalTesterActions.php:661
Time: 718 ms, Memory: 16.00 MB
There was 1 error:
---------
ERRORS!
Tests: 1, Assertions: 0, Errors: 1.
I expect the error to be exactly that! All I want Codeception to do is to simply ignore it and move on so I can check for the error text in "canSee". I tried using try/catch statement and that results in a different error. Tried using "expectException" and that did not work either.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
编码模块将仅处理
yii \ web \ httpexception
作为正常请求流的一部分的子类。如果您要抛出
yii \ base \ userexception
,则状态代码始终为500,因为对于任何其他例外情况。虽然我怀疑投掷
userexception
s不会扩展httpexception
yii错误处理程序支持它。我将更新编码模块以支持它。The codeception module will only handle subclasses of
yii\web\HttpException
as part of the normal request flow.If you are throwing a
yii\base\UserException
then the status code will always be 500 as it is for any other exception.While I doubt that throwing
UserException
s that do not extend theHttpException
the Yii error handler supports it. I'll update the codeception module to support it as well.