内腔PHPUNIT未使用.env.testing

内腔PHPUNIT未使用.env.testing,php,laravel,phpunit,lumen,Php,Laravel,Phpunit,Lumen,我的流明测试有问题。我的phpunit.xml如下: <?xml version="1.0" encoding="UTF-8"?> <phpunit backupGlobals="false" backupStaticAttributes="false" bootstrap="vendor/autoload.php" colors="true" convertErrorsToExceptions="true

我的流明测试有问题。我的
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="Application Test Suite">
            <directory suffix="Test.php">./tests</directory>
        </testsuite>
    </testsuites>
    <filter>
        <whitelist processUncoveredFilesFromWhitelist="true">
            <directory suffix=".php">./app</directory>
        </whitelist>
    </filter>
    <php>
        <env name="APP_ENV" value="testing"/>
        <env name="CACHE_DRIVER" value="array"/>
        <env name="QUEUE_CONNECTION" value="sync"/>
    </php>
</phpunit>

有什么想法吗?

对于我的Lumen项目,我编辑了
app.php
,并使用它来加载环境文件,而不是默认代码:

use Dotenv\Dotenv;
use Illuminate\Support\Env;

// ... //

(new class(
    dirname(__DIR__),
    [
        '.env',
        '.env.' . env('APP_ENV'),
    ])
    extends Laravel\Lumen\Bootstrap\LoadEnvironmentVariables {
        protected function createDotenv()
        {
            return Dotenv::create(
                Env::getRepository(),
                $this->filePath,
                $this->fileName,
                false // disable the short circuit
            );
        }
    }
)->bootstrap();
.env
将首先加载,然后
.env.
将添加并覆盖它

代码并不像我想的那么简单,它依赖于内腔内部的知识,但它是我能想到的最好的解决方案


我的第一次尝试看起来像下面的代码,但由于我在上面覆盖了
shortCircuit
参数,它只加载找到的第一个文件

(new Laravel\Lumen\Bootstrap\LoadEnvironmentVariables(
    dirname(__DIR__),
    [
        '.env.' . env('APP_ENV'),
        '.env',
    ]
))->bootstrap();

对于我的Lumen项目,我编辑了
app.php
,并使用它来加载环境文件,而不是默认代码:

use Dotenv\Dotenv;
use Illuminate\Support\Env;

// ... //

(new class(
    dirname(__DIR__),
    [
        '.env',
        '.env.' . env('APP_ENV'),
    ])
    extends Laravel\Lumen\Bootstrap\LoadEnvironmentVariables {
        protected function createDotenv()
        {
            return Dotenv::create(
                Env::getRepository(),
                $this->filePath,
                $this->fileName,
                false // disable the short circuit
            );
        }
    }
)->bootstrap();
.env
将首先加载,然后
.env.
将添加并覆盖它

代码并不像我想的那么简单,它依赖于内腔内部的知识,但它是我能想到的最好的解决方案


我的第一次尝试看起来像下面的代码,但由于我在上面覆盖了
shortCircuit
参数,它只加载找到的第一个文件

(new Laravel\Lumen\Bootstrap\LoadEnvironmentVariables(
    dirname(__DIR__),
    [
        '.env.' . env('APP_ENV'),
        '.env',
    ]
))->bootstrap();

您使用的流明版本是什么?@Rwd im使用流明6这是否回答了您的问题?(参见Bogdan的回答)您使用的流明版本是什么?@Rwd im使用流明6这是否回答了您的问题?(见博格丹的回答)