|
28 | 28 | use Codeception\TestInterface;
|
29 | 29 | use Doctrine\ORM\EntityManagerInterface;
|
30 | 30 | use Exception;
|
| 31 | +use LogicException; |
31 | 32 | use ReflectionClass;
|
32 | 33 | use ReflectionException;
|
33 | 34 | use Symfony\Bundle\SecurityBundle\DataCollector\SecurityDataCollector;
|
34 | 35 | use Symfony\Component\BrowserKit\AbstractBrowser;
|
35 | 36 | use Symfony\Component\DependencyInjection\ContainerInterface;
|
| 37 | +use Symfony\Component\Dotenv\Dotenv; |
36 | 38 | use Symfony\Component\Finder\Finder;
|
37 | 39 | use Symfony\Component\HttpKernel\DataCollector\DataCollectorInterface;
|
38 | 40 | use Symfony\Component\HttpKernel\DataCollector\TimeDataCollector;
|
@@ -204,6 +206,7 @@ public function _initialize(): void
|
204 | 206 | }
|
205 | 207 |
|
206 | 208 | $this->kernel = new $this->kernelClass($this->config['environment'], $this->config['debug']);
|
| 209 | + $this->bootstrapEnvironment(); |
207 | 210 | $this->kernel->boot();
|
208 | 211 |
|
209 | 212 | if ($this->config['cache_router'] === true) {
|
@@ -459,6 +462,26 @@ protected function getInternalDomains(): array
|
459 | 462 | return array_unique($internalDomains);
|
460 | 463 | }
|
461 | 464 |
|
| 465 | + private function bootstrapEnvironment(): void |
| 466 | + { |
| 467 | + $bootstrapFile = $this->kernel->getProjectDir() . '/tests/bootstrap.php'; |
| 468 | + |
| 469 | + if (file_exists($bootstrapFile)) { |
| 470 | + require_once $bootstrapFile; |
| 471 | + } else { |
| 472 | + if (!method_exists(Dotenv::class, 'bootEnv')) { |
| 473 | + throw new LogicException( |
| 474 | + "Symfony DotEnv is missing. Try running 'composer require symfony/dotenv'\n" . |
| 475 | + "If you can't install DotEnv add your env files to the 'params' key in codeception.yml\n" . |
| 476 | + "or update your symfony/framework-bundle recipe by running:\n" . |
| 477 | + 'composer recipes:install symfony/framework-bundle --force' |
| 478 | + ); |
| 479 | + } |
| 480 | + $_ENV['APP_ENV'] = $this->config['environment']; |
| 481 | + (new Dotenv())->bootEnv('.env'); |
| 482 | + } |
| 483 | + } |
| 484 | + |
462 | 485 | /**
|
463 | 486 | * Ensures autoloader loading of additional directories.
|
464 | 487 | * It is only required for CI jobs to run correctly.
|
|
0 commit comments