gpt4 book ai didi

php - 在 Yii2 中使用 codeception 进行功能测试时出现 404 错误

转载 作者:行者123 更新时间:2023-11-28 20:50:17 24 4
gpt4 key购买 nike

我的功能测试文件

<?php
namespace api\tests;
use api\tests\FunctionalTester;
use Yii;

class ExampleCest
{
public function _before(FunctionalTester $I)
{
}

public function _after(FunctionalTester $I)
{
}

// tests
public function tryToTest(FunctionalTester $I)
{
$I->sendGET('example/test2');
$I->seeResponseCodeIs(200); // Unauthorized
$I->seeResponseContains('test2');
}
}

我尝试了 2 个不同的 functional.suite.yml 文件来运行测试:

// 1. functional.suite.yml, test run successfully:
actor: FunctionalTester
modules:
enabled:
- REST:
url: http://api.xxxxx.local/v1/
depends: PhpBrowser
part: Json
- \api\tests\Helper\Functional


// 2. functional.suite.yml, test failed without setting defaultRoute in Yii configuration file, but succeed if I set `'defaultRoute' => 'v1/example/test2',`:
actor: FunctionalTester
modules:
enabled:
- REST:
url: v1/
depends: Yii2
part: Json
- \api\tests\Helper\Functional

失败时的错误信息:

ExampleCest: Try to test Signature: api\tests\ExampleCest:tryToTest Test: tests/functional/ExampleCest.php:tryToTest Scenario -- I send get "example/test2" [Request] GET v1/example/test2 [Request Headers] [] [yii\web\HttpException:404] 'yii\base\InvalidRouteException: Unable to resolve the request "". in /Applications/MAMP/htdocs/gaea/vendor/yiisoft/yii2/base/Module.php:537

我不知道为什么第二个 functional.suite.yml 文件失败了,因为我可以在浏览器中从 http://localhost/MYPROJECT/api/web/index.php?r=v1/example/test2 得到正确的响应。 .

我的环境:

Codeception: v2.3.8
Yii: v2.0.14
PHP: v7.0.26

最佳答案

我通过将 url: v1/ 更改为 url:/v1 或删除它来解决这个问题。

关于php - 在 Yii2 中使用 codeception 进行功能测试时出现 404 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49854215/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com