Laravel にテストケース用の適切な .env ファイルをロードさせるのに問題があります。私はphpunit.xmlに次の変数を設定してPHPUnitを使用しています:
<?xml version="1.0" encoding="UTF-8"?>
<phpunit backupGlobals="false"
backupStaticAttributes="false"
bootstrap="bootstrap/autoload.php"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false">
<testsuites>
<testsuite name="Application Test Suite">
<directory suffix="Test.php">./tests</directory>
</testsuite>
</testsuites>
<filter>
<whitelist processUncoveredFilesFromWhitelist="true">
<directory suffix=".php">./app</directory>
<exclude>
<file>./app/Http/routes.php</file>
</exclude>
</whitelist>
</filter>
<php>
<env name="APP_ENV" value="testing"/>
<env name="DB_CONNECTION" value="sqlite"/>
<env name="CACHE_DRIVER" value="array"/>
<env name="SESSION_DRIVER" value="array"/>
<env name="QUEUE_DRIVER" value="sync"/>
</php>
</phpunit>
私の .env.testing ファイルには次のものがあります。
APP_ENV=testing
DB_CONNECTION=sqlite
そして、config/database.phpの下に彼の接続を設定しました:
'sqlite' => [
'driver' => 'sqlite',
'database' => ':memory:',
'prefix' => ''
]
.env.testing ファイルをロードしていないだけです。TestCase.php でこれを行う場合:
dd(env('APP_ENV'));
私はまだ.envファイルから「開発」を取得しています
私も使用してみました:
$app->loadEnvironmentFrom('.env.testing');
ここのスレッドで提案されているように
誰が何が間違っている可能性があるか考えていますか?