Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/symfony/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php Symfony 4中测试的环境变量_Php_Symfony_Testing_Environment Variables - Fatal编程技术网

Php Symfony 4中测试的环境变量

Php Symfony 4中测试的环境变量,php,symfony,testing,environment-variables,Php,Symfony,Testing,Environment Variables,我在services.yaml中有一个配置 parameters: locale: 'en' uri: '%env(resolve:DEV_ENV_URI)%' 但是当我执行测试时,我使用了这个参数 public function setUp() { $this->client = static::createClient(); static::bootKernel(); $this->container = static::$kernel-

我在services.yaml中有一个配置

parameters:
   locale: 'en'
   uri: '%env(resolve:DEV_ENV_URI)%'
但是当我执行测试时,我使用了这个参数

public function setUp()
{
    $this->client = static::createClient();

    static::bootKernel();

    $this->container = static::$kernel->getContainer();

    $this->guzzle = new Client(
        [
            'base_uri' => $this->container->getParameter('uri'),
            'verify' => false
        ]
    );
}
我有以下错误:

未找到环境变量:“DEV_ENV_URI”

这是我的
.env

APP_ENV=test
DEV_ENV_URI=http://0.0.0.0:8000/
在dev环境中,请求期间一切都很好,但当我从终端运行测试时,环境不工作

也许您可以提出任何其他想法,如何解决基于测试原因建立基本URI的问题


非常感谢你的建议

我使用了老式的方法,创建parameters.yml并将其添加到gitignore中。

我认为解决这个问题的正确方法是使用PHPUnit的配置文件:

<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/6.1/phpunit.xsd"
         backupGlobals="false"
         colors="true"
         bootstrap="vendor/autoload.php"
>
    <php>
        <ini name="error_reporting" value="-1" />
        <env name="KERNEL_CLASS" value="App\Kernel" />
        <env name="APP_ENV" value="test" />
        <env name="APP_DEBUG" value="1" />
        <env name="APP_SECRET" value="s$cretf0rt3st" />
    </php>
</phpunit>