反应处理期望

发布于 2025-02-12 20:59:52 字数 2135 浏览 0 评论 0原文

在下面的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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

话少情深 2025-02-19 20:59:53

编码模块将仅处理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 UserExceptions that do not extend the HttpException the Yii error handler supports it. I'll update the codeception module to support it as well.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文