Skip to content

Commit 7f433fb

Browse files
committed
Require bootstrap.php if exists
1 parent 36e08c9 commit 7f433fb

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
"symfony/config": "^5.4 | ^6.4 | ^7.0",
3333
"symfony/dependency-injection": "^5.4 | ^6.4 | ^7.0",
3434
"symfony/dom-crawler": "^5.4 | ^6.4 | ^7.0",
35+
"symfony/dotenv": "^5.4 | ^6.4 | ^7.0",
3536
"symfony/error-handler": "^5.4 | ^6.4 | ^7.0",
3637
"symfony/filesystem": "^5.4 | ^6.4 | ^7.0",
3738
"symfony/form": "^5.4 | ^6.4 | ^7.0",

src/Codeception/Module/Symfony.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,13 @@
2828
use Codeception\TestInterface;
2929
use Doctrine\ORM\EntityManagerInterface;
3030
use Exception;
31+
use LogicException;
3132
use ReflectionClass;
3233
use ReflectionException;
3334
use Symfony\Bundle\SecurityBundle\DataCollector\SecurityDataCollector;
3435
use Symfony\Component\BrowserKit\AbstractBrowser;
3536
use Symfony\Component\DependencyInjection\ContainerInterface;
37+
use Symfony\Component\Dotenv\Dotenv;
3638
use Symfony\Component\Finder\Finder;
3739
use Symfony\Component\HttpKernel\DataCollector\DataCollectorInterface;
3840
use Symfony\Component\HttpKernel\DataCollector\TimeDataCollector;
@@ -204,6 +206,7 @@ public function _initialize(): void
204206
}
205207

206208
$this->kernel = new $this->kernelClass($this->config['environment'], $this->config['debug']);
209+
$this->bootstrapEnvironment();
207210
$this->kernel->boot();
208211

209212
if ($this->config['cache_router'] === true) {
@@ -459,6 +462,25 @@ protected function getInternalDomains(): array
459462
return array_unique($internalDomains);
460463
}
461464

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+
(new Dotenv())->bootEnv('.env');
481+
}
482+
}
483+
462484
/**
463485
* Ensures autoloader loading of additional directories.
464486
* It is only required for CI jobs to run correctly.

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy