Php 带有Yi2和Codeception的功能测试错误中的$scenario变量
我正在尝试编写功能测试,但出现错误:Php 带有Yi2和Codeception的功能测试错误中的$scenario变量,php,testing,yii,yii2,codeception,Php,Testing,Yii,Yii2,Codeception,我正在尝试编写功能测试,但出现错误: PHPUnit_Framework_Exception: Undefined variable: scenario 我的测试如下所示: <?php use tests\functional; class AccountTest extends \Codeception\TestCase\Test { /** * @var \FunctionalTester */ protected $tester; protected $url = 'ht
PHPUnit_Framework_Exception: Undefined variable: scenario
我的测试如下所示:
<?php
use tests\functional;
class AccountTest extends \Codeception\TestCase\Test
{
/**
* @var \FunctionalTester
*/
protected $tester;
protected $url = 'http://domain.api/v1/api';
// tests
public function testMe()
{
$I = new FunctionalTester($scenario);
$I->haveHttpHeader('Content-Type', 'application/json'); //remove
$I->haveHttpHeader('Accept', 'application/json'); //remove
$I->sendPost('/account/register');
$I->seeResponseCodeIs(200);
$I->seeResponseIsJson();
}
}
为您的testMe()
方法提供参数$I
和$scenario
:
public function($I, $scenario)
{
[...]
}
您不需要实例化FunctionalTester()
。这会导致以下错误:PHPUnit\u Framework\u异常:AccountTest::testMe()缺少参数1。我想没有任何参数被传递给该方法。好的,当我通过运行“codecept generate:cept functional account/account”创建测试时,我又前进了一步。但是,大多数方法对我都不可用,例如sendPost()。您是否运行了codecept build
?请查看随提供的测试