【问题标题】:Why there is a folder tests in a root of yii2 framework?为什么yii2框架的根目录下有个文件夹tests?
【发布时间】:2018-08-24 02:05:28
【问题描述】:

这是基本模板。 我使用此命令生成测试文件并运行:

$ ./vendor/bin/codecept generate:test unit Example
$ ./vendor/bin/codecept run

此文件出现在文件夹 /vendor/bin/tests/unit 中。 我无法将此文件推送到 GitHub。 为什么测试文件出现在供应商文件夹中?我应该怎么做才能使测试文件保存在项目根目录的测试文件夹中?

【问题讨论】:

  • 并从根目录运行测试文件
  • 什么是路径值:测试:在 codeception.yml 文件中设置?
  • 路径:测试:测试日志:测试/_输出数据:测试/_数据助手:测试/_support
  • 我不能对你的 codeception.yml 文件有任何错误 - 它是默认的...适用于我的 Basic Yii2 模板
  • @drAnton 我已经为您发布了答案,如果有帮助请告诉我。如果是这样,请考虑标记为已接受的答案。谢谢!

标签: yii2 phpunit codeception


【解决方案1】:

您需要调试路径并解决导致此问题的配置问题。

使用的路径设置在文件的第 45 行:vendor/codeception/base/src/Codeception/Command/GenerateTest.php

您将在此处看到创建新目录的代码:

$path = $this->createDirectoryFor($config['path'], $class);

$config['path'] 的值在方法suiteSettings 中确定,文件vendor/codeception/base/src/Codeception/Configuration.php 中的第285 行

在这里你会看到这段代码,它设置了配置的路径:

    $settings['path'] = self::$dir . DIRECTORY_SEPARATOR . $config['paths']['tests']
        . DIRECTORY_SEPARATOR . $settings['path'] . DIRECTORY_SEPARATOR;

在这两行之前添加以下代码:

    echo 'self::$dir ' . print_r(self::$dir, true) . PHP_EOL;
    echo '$config[paths][tests] ' . print_r($config['paths']['tests'], true) . PHP_EOL;
    echo '$settings[path] ' . print_r($settings['path'], true) . PHP_EOL;
    exit;

现在,再次运行您的命令以执行此调试代码:

./vendor/bin/codecept generate:test unit Example

对于我的设置,它使用与您相同的命令在<system_root>/public_html/basic/tests/unit/ExampleTest.php 中生成测试,我看到以下内容:

  • self::$dir => <system_root>/public_html/basic
  • $config[paths][tests] => tests
  • $settings[path] => unit

观察 - 从您的评论中,我看到您的 codeception.yml 文件是正确的,具有各种测试子目录的默认值。

建议

$config[paths][tests] 在您的情况下似乎是错误的 - 对此进行调试并根据您的发现解决路径配置。

请注意,供应商包中有一个核心 codeception.yml,您的应用根目录中也应该有一个,即

  • <system_root>/public_html/basic/vendor/codeception/base/codeception.yml

  • <system_root>/public_html/basic/codeception.yml

后者的值优先!

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-12-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-04-29
    • 2017-05-11
    • 2023-03-11
    相关资源
    最近更新 更多