![](/img/trans.png)
[英]$scenario var in functional test error with Yii2 and Codeception
[英]Functional test in Yii2 with codeception get 404 error
我的功能測試文件
<?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:嘗試測試簽名:api \\ tests \\ ExampleCest:tryToTest測試:tests / functional / ExampleCest.php:tryToTest方案-我發送get“ example / test2” [請求] GET v1 / example / test2 [請求標頭] [ ] [yii \\ web \\ HttpException:404]'yii \\ base \\ InvalidRouteException:無法解決請求“”。 在/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
或將其刪除解決了這個問題。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.