使用PHPUnit在Windows Git Bash中无法识别APP_ENV

With Symfony 4.2, Windows and Git Bash,

When I run this command, it's OK, my database bublemeet_test is updated :

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

In my test/ folder, I have bootstrap.php file :

<?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__
    ));
}

But when I run this command :

./bin/phpunit

I have this error :

'APP_ENV' n’est pas reconnu en tant que commande interne ou externe, un programme exécutable ou un fichier de commandes.

Why APP_ENV is not recognized when I execute the ./bin/phpunit command but is recognized when I update the database ?

Per the docs, you'll need to set the url in .env.test as below:

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

In windows passthru uses cmd not bash.

You can modify your code using same like

<?php

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