The symfony local:server:start defaults to the dev environment and doesn’t respect the test configuration.
The best approach is to either use php -S with APP_ENV=test, Panther’s internal web server, or configure public/index.php to detect test and adjust accordingly.
Solution 1 - php -S:
APP_ENV=test php -S 127.0.0.1:8000 -t public
Solution 2 - Use Symfony Panther:
1- Use Symfony CLI with --no-tls and proxy:
When using Symfony Panther, instead of relying on the Symfony CLI, use Panther’s internal server:
$client = PantherTestCase::createPantherClient(['server' => ['APP_ENV' => 'test']]);
2- Or Functional Testing with Panther:
Panther automatically uses the test environment if properly set up, so make sure:
- The
.env.test file exists with the correct settings.
- In
phpunit.xml.dist: <env name="APP_ENV" value="test"/>
Learn more about symfony/panther
Solution is 3 - Update index.php:
Edit public/index.php to use the test environment if needed:
if ($_SERVER['APP_ENV'] === 'test') {
$_SERVER['APP_DEBUG'] = false;
putenv('APP_ENV=test');
}
Then, when starting:
APP_ENV=test symfony local:server:start --no-tls
APP_ENV=test symfony local:server:start