这是基本模板。 我使用此命令生成测试文件并运行:
$ ./vendor/bin/codecept generate:test unit Example
$ ./vendor/bin/codecept run
此文件出现在文件夹/vendor/bin/tests/unit 中。 我无法将此文件推送到 GitHub。 为什么测试文件出现在供应商文件夹中?我应该怎么做才能使测试文件保存在项目根目录的测试文件夹中?
您需要调试路径并解决导致此问题的配置问题。
使用的路径设置在文件的第 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;
在这 2 行之前添加以下代码:
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
后者中的值优先!