【问题标题】:APP_ENV is not recognized in Windows Git Bash with PHPUnitAPP_ENV 在带有 PHPUnit 的 Windows Git Bash 中无法识别
【发布时间】:2019-06-05 12:34:21
【问题描述】:

使用 Symfony 4.2、Windows 和 Git Bash,

当我运行此命令时,没关系,我的数据库bublemeet_test 已更新:

APP_ENV=test php bin/console doctrine:schema:update --force

在我的test/ 文件夹中,我有bootstrap.php 文件:

<?php

require __DIR__.'/../config/bootstrap.php';

if (isset($_ENV['APP_ENV'])) {
    passthru(sprintf(
        'APP_ENV=%s php "%s/../bin/console" cache:clear --no-warmup',
        $_ENV['APP_ENV'],
        __DIR__
    ));
}

但是当我运行这个命令时:

./bin/phpunit

我有这个错误:

'APP_ENV' n'est pas reconnu en tant que commande interne ou externe, un program executable ou un fichier de commandes。

为什么APP_ENV在我执行./bin/phpunit命令时不被识别,但在我更新数据库时被识别?

【问题讨论】:

  • 我认为 passthru 正在运行“cmd”,而不是 bash。试试bash -c "APP_ENV=bla bla bla" 之类的(注意引号)
  • 非常感谢,很好! :)

标签: php symfony phpunit


【解决方案1】:

根据docs,您需要在.env.test 中设置网址,如下所示:

# .env.test
DATABASE_URL="mysql://db_user:db_password@127.0.0.1:3306/db_name_test"

【讨论】:

    【解决方案2】:

    在 Windows 中 passthru 使用 cmd 而不是 bash

    您可以使用相同的方式修改您的代码

    <?php
    
    passthru(sprintf(
            'bash -c "APP_ENV=%s php \\"%s/../bin/console\\" cache:clear --no-warmup"',
            $_ENV['APP_ENV'],
            __DIR__
        ));
    

    【讨论】:

      猜你喜欢
      • 2016-05-24
      • 1970-01-01
      • 2019-09-20
      • 1970-01-01
      • 2013-12-03
      • 2017-05-17
      • 2016-09-12
      • 2022-08-03
      • 2014-11-28
      相关资源
      最近更新 更多