Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/258.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php Yii2 Codeception路由无效?_Php_Yii2_Codeception - Fatal编程技术网

Php Yii2 Codeception路由无效?

Php Yii2 Codeception路由无效?,php,yii2,codeception,Php,Yii2,Codeception,我正在尝试使用Yii2中的Codeception设置验收测试。 到目前为止,安装方面还不错,但我遇到了一个路线问题 当我这样做时: codeception运行验收 我得到的反馈是: 1) Failed to ensure login page works in LoginCept (./acceptance/LoginCept.php) Step I fill field "input[name="LoginForm[username]"]","" Fail Form field by L

我正在尝试使用Yii2中的Codeception设置验收测试。 到目前为止,安装方面还不错,但我遇到了一个路线问题

当我这样做时: codeception运行验收

我得到的反馈是:

1) Failed to ensure login page works in LoginCept (./acceptance/LoginCept.php)

Step  I fill field "input[name="LoginForm[username]"]",""
Fail  Form field by Label or CSS element with    'input[name="LoginForm[username]"]' was not found.

Scenario Steps:

 3. $I->fillField("input[name="LoginForm[username]"]","")
 2. // I am going to submit login form with no data
 1. $I->amOnPage("/backend/web/index-test.php/")
页面上存在名为LoginForm[username]的输入,但Codeception显然没有获得正确的页面

/backend/web/index-test.php是否也应该包含approt路径?当我在浏览器中请求approt/backend/web/index-test.php时,一切正常

谢谢你的指点。 亚历克斯

更新:特此更新acceptance.suite.yml的内容:

# Codeception Test Suite Configuration

# suite for acceptance tests.
# perform tests in browser using the Selenium-like tools.
# powered by Mink (http://mink.behat.org).
# (tip: that's what your customer will see).
# (tip: test your ajax and javascript by one of Mink drivers).

# RUN `build` COMMAND AFTER ADDING/REMOVING MODULES.

class_name: AcceptanceTester
modules:
        enabled:
    - PhpBrowser
    - tests\codeception\common\_support\FixtureHelper
# you can use WebDriver instead of PhpBrowser to test javascript and ajax.
# This will require you to install selenium. See http://codeception.com/docs/04-AcceptanceTests#Selenium
# "restart" option is used by the WebDriver to start each time per test-file new session and cookies,
# it is useful if you want to login in your app in each test.
#        - WebDriver
    config:
        PhpBrowser:
# PLEASE ADJUST IT TO THE ACTUAL ENTRY POINT WITHOUT PATH INFO
            url: http://localhost:8080
#        WebDriver:
#            url: http://localhost:8080
#            browser: firefox
#            restart: true
根据以下评论更新:

我迷路了。我尝试对路径进行硬编码,甚至尝试对本地主机URL进行硬编码,但随后得到以下响应:

$I->amOnPage("/backend/web/index-test.php/localhost/www/yii2KickDish/backend/web") 
这显然是一个伪造的URL…那么我如何才能让Codeception解析到正确的位置呢?

我也遇到了同样的问题

似乎构建在AcceptanceTesterActions特性中的“amOnPage”方法在yii2 url模式中不起作用

我就是这样解决的

创建从AcceptanceTester扩展的类MainTester

namespace tests\codeception\master\Step\Acceptance;

use tests\codeception\master\AcceptanceTester;

class MainTester extends AcceptanceTester
{
    public function amOnPage($url)
        {
           $page = \Yii::$app->getUrlManager()->createUrl($url);
           return parent::amOnPage($page);
        }
}
然后在我的Cest课上

use tests\codeception\master\Step\Acceptance\MainTester as AcceptanceTester;

class TestClassCest
{
    public function testMethod(AcceptanceTester $I)
    {
        $I->amOnPage('/example/something');
    }
}
我也有同样的问题

似乎构建在AcceptanceTesterActions特性中的“amOnPage”方法在yii2 url模式中不起作用

我就是这样解决的

创建从AcceptanceTester扩展的类MainTester

namespace tests\codeception\master\Step\Acceptance;

use tests\codeception\master\AcceptanceTester;

class MainTester extends AcceptanceTester
{
    public function amOnPage($url)
        {
           $page = \Yii::$app->getUrlManager()->createUrl($url);
           return parent::amOnPage($page);
        }
}
然后在我的Cest课上

use tests\codeception\master\Step\Acceptance\MainTester as AcceptanceTester;

class TestClassCest
{
    public function testMethod(AcceptanceTester $I)
    {
        $I->amOnPage('/example/something');
    }
}

Yii2不使用URL重写吗?您的代码应该是$I->amOnPage(“/”);或$I->amOnPage(“/login”);不幸的是,同样的结果…什么url在浏览器中工作?请将acceptance.suite.yml文件的内容添加到您的question.approt/和approt/sign-in/login中,这两个文件也可以通过浏览器approt/index-test.php工作。我将在问题中添加acceptance.suite.yml。然后在测试中使用这些URL。Yii2不使用URL重写吗?您的代码应该是$I->amOnPage(“/”);或$I->amOnPage(“/login”);不幸的是,同样的结果…什么url在浏览器中工作?请将acceptance.suite.yml文件的内容添加到您的question.approt/和approt/sign-in/login中,这两个文件也可以通过浏览器approt/index-test.php工作。我将在问题中添加acceptance.suite.yml,然后在测试中使用这些URL。