【发布时间】:2019-10-28 20:34:59
【问题描述】:
注意:我咨询了其他类似的问题,但他们都解决了清除缓存、在 xml 中设置 APP_ENV 和/或创建 .env.testing 的问题。
Laravel 版本:"laravel/framework": "5.8.*",
我有标准的.env 文件
APP_ENV=local
DB_CONNECTION=mysql
我已克隆标准的.env 文件并保存为.env.testing,然后更改为
APP_ENV=testing
DB_CONNECTION=mongodb
从控制台,从项目的根目录内部,我正在尝试使用
php artisan config:cache && vendor/bin/phpunit
问题在于 Laravel/PHPUnit 仍在使用 .env 文件,而不是预期的 .env.testing。这就是证据
TypeError: 传递给 Jenssegers\Mongodb\Query\Builder::__construct() 的参数 1 必须是 Jenssegers\Mongodb\Connection 的实例,给定的 Illuminate\Database\MySqlConnection 的实例,
这是实际的phpunit.xml 配置文件
<?xml version="1.0" encoding="UTF-8"?>
<phpunit backupGlobals="false"
backupStaticAttributes="false"
bootstrap="vendor/autoload.php"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false">
<testsuites>
<testsuite name="Unit">
<directory suffix="Test.php">./tests/Unit</directory>
</testsuite>
<testsuite name="Feature">
<directory suffix="Test.php">./tests/Feature</directory>
</testsuite>
</testsuites>
<filter>
<whitelist processUncoveredFilesFromWhitelist="true">
<directory suffix=".php">./app</directory>
</whitelist>
</filter>
<php>
<server name="APP_ENV" value="testing"/>
<server name="BCRYPT_ROUNDS" value="4"/>
<server name="CACHE_DRIVER" value="array"/>
<server name="MAIL_DRIVER" value="array"/>
<server name="QUEUE_CONNECTION" value="sync"/>
<server name="SESSION_DRIVER" value="array"/>
</php>
</phpunit>
所以,我请教一个调试和修复的建议
【问题讨论】:
-
你用的是哪个版本的 laravel?
-
我最迟
"laravel/framework": "5.8.*",