Codeception\Exception\InjectionException :服务 di 未定义,无法从测试访问

Z.R*_*gui 3 php phpunit codeception

测试开始于 \xe4\xb8\x8b\xe5\x8d\x885:45 ...

\n
/usr/local/bin/php -dxdebug.remote_enable=1 -dxdebug.remote_mode=req -dxdebug.remote_port=9001 -dxdebug.remote_host=127.0.0.1 /var/www/example/vendor/phpunit/phpunit/phpunit --no-configuration --filter "/(::testMerlinTemplate)( .*)?$/" tests\\jobs\\SettlementJobTest /var/www/example/tests/unit/jobs/SettlementJobTest.php --teamcity\nPHPUnit 7.1.4 by Sebastian Bergmann and contributors.\n\n\nCodeception\\Exception\\InjectionException : Service di is not defined and can't be accessed from a test\n /var/www/example/vendor/codeception/base/src/Codeception/Test/Metadata.php:191\n /var/www/example/vendor/codeception/base/src/Codeception/Test/Unit.php:47\n
Run Code Online (Sandbox Code Playgroud)\n

Lii*_*iva 5

您正在尝试使用 phpunit 运行 Codeception 单元测试,di(依赖注入)服务在后者中不可用。您应该使用 Codeception CLI 运行测试,例如:

codecept run /var/www/example/tests/unit/jobs/SettlementJobTest.php
Run Code Online (Sandbox Code Playgroud)