代码:[RuntimeException]调用未定义的方法ApiTester :: sendDELETE

时间:2018-08-28 17:56:15

标签: yii2 codeception

我正在使用Yii2进行具有代码接收的API测试。在tests文件夹中,我还有另一个文件夹代码接收,其中包含所有配置文件,这是我运行测试的地方。

这是我的 codeception.yml 文件

paths:
    tests: tests
    output: tests/_output
    data: tests/_data
    support: tests/_support
    envs: tests/_envs
actor_suffix: Tester
extensions:
    enabled:
        - Codeception\Extension\RunFailed

这是我的 api.suite.yml

class_name: ApiTester
    modules:
        enabled:
            - \Helper\Api
            - \Helper\FactoryHelper
            - REST:
                 depends: PhpBrowser
                 url: 'http://apitest.sb.dev/api/'
            - Db:
                 dsn: 'mysql:host=127.0.0.1;dbname=test'
                 user: 'root'
                 password: ''
                 dump: 'codeception/_data/dump.sql'
                 populate: true
                 cleanup: true
                 reconnect: true
            - Yii2:
               configFile: ../config/tests/unit.php
               part: [orm, email]
               cleanup: false
            - DataFactory:
               factories: codeception/_support/factories
               depends: Yii2

我进行的典型测试将具有来自生成的文件ApiTesterActions的功能。我的问题是,每当我运行测试时,都会出现错误,指示完全看不到ApiTesterActions文件。一个例子:

  

代码接收:[RuntimeException]调用未定义的方法   ApiTester :: sendDELETE

从测试中删除sendDelete并使用该文件中的任何其他方法也会产生错误。

测试示例:

public function index(ApiTester $I) {
    $I->wantTo('view list via api');
    $I->sendGET($this->_getUrl(), ['client' => 10]);
    $I->seeResponseContainsJson(["data" => $this->menus]);
    $I->seeResponseCodeIs(200);
    $I->wantTo("try to view menus with client which doesn't exist");
    $I->sendGET($this->_getUrl(), ['client' => 150]);
    $I->seeResponseCodeIs(403);
    $I->seeResponseIsJson();
    $I->seeResponseContains(Yii::t('app', 'You need permission'));
}

我在做什么错??!

编辑:这是ApiTester.php     

/**
 * Inherited Methods
 * @method void wantToTest($text)
 * @method void wantTo($text)
 * @method void execute($callable)
 * @method void expectTo($prediction)
 * @method void expect($prediction)
 * @method void amGoingTo($argumentation)
 * @method void am($role)
 * @method void lookForwardTo($achieveValue)
 * @method void comment($description)
 * @method \Codeception\Lib\Friend haveFriend($name, $actorClass = NULL)
 * 
 * @SuppressWarnings(PHPMD)
*/
class ApiTester extends \Codeception\Actor
{
    use _generated\ApiTesterActions;


    /**
     * @param string $name
     * @return mixed
     */
    public function loadFixture($name)
    {
        return include 'codeception/fixtures/' . $name . '.php';
    }

    /**

     */
    public function autoAuthenticate($key = '')
    {
        if ($key == '') {
            $key = '17sV24Ku83q-BxeNbXHUWNcBO5iVQxDK';
        }
        return $this->amBearerAuthenticated($key);
    }
}

0 个答案:

没有答案