|
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;
|
|
84 | 86 | * * `cache_router`: 'false' - Enable router caching between tests in order to [increase performance](http://lakion.com/blog/how-did-we-speed-up-sylius-behat-suite-with-blackfire)
|
85 | 87 | * * `rebootable_client`: 'true' - Reboot client's kernel before each request
|
86 | 88 | * * `guard`: 'false' - Enable custom authentication system with guard (only for Symfony 5.4)
|
| 89 | + * * `bootstrap`: 'false' - Enable the test environment setup with the tests/bootstrap.php file if it exists or with Symfony DotEnv otherwise. If false, it does nothing. |
87 | 90 | * * `authenticator`: 'false' - Reboot client's kernel before each request (only for Symfony 6.0 or higher)
|
88 | 91 | *
|
89 | 92 | * #### Sample `Functional.suite.yml`
|
@@ -167,6 +170,7 @@ class Symfony extends Framework implements DoctrineProvider, PartedModule
|
167 | 170 | 'em_service' => 'doctrine.orm.entity_manager',
|
168 | 171 | 'rebootable_client' => true,
|
169 | 172 | 'authenticator' => false,
|
| 173 | + 'bootstrap' => false, |
170 | 174 | 'guard' => false
|
171 | 175 | ];
|
172 | 176 |
|
@@ -204,6 +208,9 @@ public function _initialize(): void
|
204 | 208 | }
|
205 | 209 |
|
206 | 210 | $this->kernel = new $this->kernelClass($this->config['environment'], $this->config['debug']);
|
| 211 | + if($this->config['bootstrap']) { |
| 212 | + $this->bootstrapEnvironment(); |
| 213 | + } |
207 | 214 | $this->kernel->boot();
|
208 | 215 |
|
209 | 216 | if ($this->config['cache_router'] === true) {
|
@@ -459,6 +466,26 @@ protected function getInternalDomains(): array
|
459 | 466 | return array_unique($internalDomains);
|
460 | 467 | }
|
461 | 468 |
|
| 469 | + private function bootstrapEnvironment(): void |
| 470 | + { |
| 471 | + $bootstrapFile = $this->kernel->getProjectDir() . '/tests/bootstrap.php'; |
| 472 | + |
| 473 | + if (file_exists($bootstrapFile)) { |
| 474 | + require_once $bootstrapFile; |
| 475 | + } else { |
| 476 | + if (!method_exists(Dotenv::class, 'bootEnv')) { |
| 477 | + throw new LogicException( |
| 478 | + "Symfony DotEnv is missing. Try running 'composer require symfony/dotenv'\n" . |
| 479 | + "If you can't install DotEnv add your env files to the 'params' key in codeception.yml\n" . |
| 480 | + "or update your symfony/framework-bundle recipe by running:\n" . |
| 481 | + 'composer recipes:install symfony/framework-bundle --force' |
| 482 | + ); |
| 483 | + } |
| 484 | + $_ENV['APP_ENV'] = $this->config['environment']; |
| 485 | + (new Dotenv())->bootEnv('.env'); |
| 486 | + } |
| 487 | + } |
| 488 | + |
462 | 489 | /**
|
463 | 490 | * Ensures autoloader loading of additional directories.
|
464 | 491 | * It is only required for CI jobs to run correctly.
|
|
0 commit comments