【问题标题】:$scenario var in functional test error with Yii2 and CodeceptionYii2 和 Codeception 的功能测试错误中的 $scenario var
【发布时间】:2015-05-25 04:49:29
【问题描述】:

我正在尝试编写功能测试,但出现错误:

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();
  }

}

我需要添加什么才能使 $scenario 可用?

【问题讨论】:

  • 好的,当我通过运行 "codecept generate:cept functional account/Account" 创建测试时,我更进一步。但是,我无法使用大多数方法,例如 sendPost()。
  • 你运行codecept build了吗?查看advanced application template 提供的测试

标签: php testing yii yii2 codeception


【解决方案1】:

为您的testMe() 方法提供参数$I$scenario

public function($I, $scenario)
{
    [...]
}

你不需要实例化FunctionalTester()

【讨论】:

  • 这给了我这个错误:PHPUnit_Framework_Exception:AccountTest::testMe() 缺少参数 1。我猜没有参数被传递给该方法。
猜你喜欢
  • 2014-08-17
  • 2015-08-14
  • 1970-01-01
  • 2015-07-16
  • 1970-01-01
  • 1970-01-01
  • 2015-03-18
  • 1970-01-01
  • 2015-07-21
相关资源
最近更新 更多