【问题标题】:function test, [PHPUnit Framework_Exception]: Undefined index: config功能测试,[PHPUnit Framework_Exception]:未定义索引:config
【发布时间】:2016-06-22 08:21:34
【问题描述】:

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

[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 运行。我收到上述错误。

所以 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'

【问题讨论】:

  • 请将您的 codeception.yml 文件添加到您的问题中,其中可能缺少配置部分。
  • 我添加了 codeception.yml 文件@Naktibalda
  • 是 Codeception.yml 还是 codeception.yml ? Codeception 只读取 codeception.yml
  • 它是 codeception.yml,对不起我的错。这里只是一个类型错误,在代码中它的 codeception.yml
  • 我无法重现您的问题,它对我有用。

标签: codeception yii2-basic-app


【解决方案1】:
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');

由于某种原因,它没有检索我的 url 表单 codeception.yml 表单,所以我将 url 硬编码为 parse_url(\Codeception\Configuration::config()['config']['test_entry_url'], PHP_URL_PATH))to 实际 url:'http://test.qsims.com/web/index-test.php'

【讨论】:

    猜你喜欢
    • 2013-07-08
    • 2023-03-16
    • 1970-01-01
    • 2013-07-19
    • 2015-06-08
    • 1970-01-01
    • 2016-08-10
    • 2014-03-02
    • 2014-06-09
    相关资源
    最近更新 更多