Skip to content

Commit 8e3c875

Browse files
committed
Load environment variables using Symfony Dotenv in bootstrap file
1 parent e94c9a8 commit 8e3c875

2 files changed

Lines changed: 8 additions & 4 deletions

File tree

phpunit.xml.dist

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,6 @@
1010
<php>
1111
<ini name="error_reporting" value="-1"/>
1212
<server name="KERNEL_CLASS" value="PhpList\Core\Core\ApplicationKernel"/>
13+
<server name="APP_ENV" value="test" force="true"/>
1314
</php>
1415
</phpunit>

tests/bootstrap.php

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,12 @@
22

33
declare(strict_types=1);
44

5-
// Start output buffering so that headers_sent() returns false during tests.
6-
// This prevents Symfony's NativeSessionStorage from throwing "headers already sent"
7-
// errors caused by PHPUnit's Printer writing to STDOUT before session start.
5+
use Symfony\Component\Dotenv\Dotenv;
6+
87
ob_start();
98

10-
require_once __DIR__ . '/../vendor/autoload.php';
9+
require dirname(__DIR__) . '/vendor/autoload.php';
10+
11+
if (method_exists(Dotenv::class, 'bootEnv')) {
12+
(new Dotenv())->bootEnv(dirname(__DIR__) . '/.env');
13+
}

0 commit comments

Comments
 (0)