function test,[PHPUnit Framework_Exception]:未定义索引:config

时间:2016-06-22 08:21:35

标签: codeception yii2-basic-app

我正在尝试运行我的功能测试,这是我收到的错误消息

[PHPUnit_Framework_Exception]未定义的索引:第4行的C:\ wamp \ www \ test.qsims.com \ tests \ functional_bootstrap.php中的配置**

我正在尝试解析函数/ _bootstrap.php文件中的URL。以下代码在

下面
<?php
    define('DS', DIRECTORY_SEPARATOR);

    defined('YII_TEST_ENTRY_URL') or define('YII_TEST_ENTRY_URL', parse_url(\Codeception\Configuration::config()['config']['test_entry_url'], PHP_URL_PATH));
    defined('YII_TEST_ENTRY_FILE') or define('YII_TEST_ENTRY_FILE', dirname(dirname(__DIR__)) . '/web/index-test.php');

    // Define our application_env variable as provided by nginx/apache
    if (!defined('APPLICATION_ENV'))
    {
        if (getenv('APPLICATION_ENV') != false)
            define('APPLICATION_ENV', getenv('APPLICATION_ENV'));
        else 
        define('APPLICATION_ENV', 'dev');
    }
    $env = require(__DIR__ . '/../../config/env.php');
    // comment out the following two lines when deployed to production
    defined('YII_DEBUG') or define('YII_DEBUG', $env['debug']);
    defined('YII_ENV') or define('YII_ENV', APPLICATION_ENV);
    require(__DIR__ . '/../../vendor/autoload.php');
    require(__DIR__ . '/../../vendor/yiisoft/yii2/Yii.php');
    $config = require(__DIR__ . '/../../config/web.php');

    $_SERVER['SCRIPT_FILENAME'] = YII_TEST_ENTRY_FILE;
    $_SERVER['SCRIPT_NAME'] = YII_TEST_ENTRY_URL;
    $_SERVER['SERVER_NAME'] = parse_url(\Codeception\Configuration::config()['config']['test_entry_url'], PHP_URL_HOST);
    $_SERVER['SERVER_PORT'] =  parse_url(\Codeception\Configuration::config()['config']['test_entry_url'], PHP_URL_PORT) ?: '80';

    Yii::setAlias('@tests', dirname(__DIR__));

    (new yii\web\Application($config));

当我运行 $ ./vendor/bin/codecept run 时。我得到了上述错误。

所以parse_url行,即第4行正在打破代码。任何人都可以帮助我解决这个问题,尝试从过去6小时左右开始解决..提前致谢

Codeception.yml

actor: Tester
#coverage:
#    #c3_url: http://localhost:8080/index-test.php/
#    enabled: true
#    #remote: true
#    #remote_config: '../tests/codeception.yml'
#    white_list:
#        include:
#            - ../models/*
#            - ../controllers/*
#            - ../commands/*
#            - ../mail/*
#    blacklist:
#        include:
#            - ../assets/*
#            - ../config/*
#            - ../runtime/*
#            - ../vendor/*
#            - ../views/*
#            - ../web/*
#            - ../tests/*
paths:
    tests: codeception
    log: codeception/_output
    data: codeception/_data
    helpers: codeception/_support
settings:
    bootstrap: _bootstrap.php
    suite_class: \PHPUnit_Framework_TestSuite
    memory_limit: 1024M
    log: true
    colors: true
config:
    # the entry script URL (with host info) for functional and acceptance tests
    # PLEASE ADJUST IT TO THE ACTUAL ENTRY SCRIPT URL
    test_entry_url: http://localhost:8080/index-test.php

functional.suite.yml

class_name: FunctionalTester
modules:
    enabled:
      - Filesystem
      - Yii2
    config:
        Yii2:
            configFile: 'codeception/config/functional.php'

1 个答案:

答案 0 :(得分:0)

defined('YII_TEST_ENTRY_URL') or define('YII_TEST_ENTRY_URL', parse_url(\Codeception\Configuration::config()['config']['test_entry_url'], PHP_URL_PATH));

将以上行更改为下面提到的代码

defined('YII_TEST_ENTRY_URL') or define('YII_TEST_ENTRY_URL', 'http://test.qsims.com/web/index-test.php');

由于某种原因,它没有检索我的网址格式codeception.yml表单,所以我在parse_url(\Codeception\Configuration::config()['config']['test_entry_url'], PHP_URL_PATH))的地方硬编了实际网址:'http://test.qsims.com/web/index-test.php'