Implement bootstrap loading
This commit is contained in:
@@ -0,0 +1,56 @@
|
||||
Feature: Loading configured bootstrap file
|
||||
|
||||
Scenario: Loading configured bootstrap file
|
||||
Given a working Symfony application with SymfonyExtension configured
|
||||
And a Behat configuration containing:
|
||||
"""
|
||||
default:
|
||||
extensions:
|
||||
FriendsOfBehat\SymfonyExtension:
|
||||
bootstrap: custom/bootstrap.php
|
||||
|
||||
suites:
|
||||
default:
|
||||
contexts:
|
||||
- App\Tests\SomeContext
|
||||
"""
|
||||
And a boostrap file "custom/bootstrap.php" containing:
|
||||
"""
|
||||
<?php
|
||||
|
||||
putenv("CUSTOM_VARIABLE=lol2");
|
||||
$_SERVER['CUSTOM_VARIABLE'] = $_ENV['CUSTOM_VARIABLE'] = 'lol2';
|
||||
"""
|
||||
And a context file "tests/SomeContext.php" containing:
|
||||
"""
|
||||
<?php
|
||||
|
||||
namespace App\Tests;
|
||||
|
||||
use Behat\Behat\Context\Context;
|
||||
|
||||
final class SomeContext implements Context {
|
||||
private $parameter;
|
||||
|
||||
public function __construct(?string $parameter = null) { $this->parameter = $parameter; }
|
||||
|
||||
/** @Then the passed parameter should be :expected */
|
||||
public function parameterShouldBe(string $expected): void { assert($this->parameter === $expected); }
|
||||
}
|
||||
"""
|
||||
And a YAML services file containing:
|
||||
"""
|
||||
services:
|
||||
App\Tests\SomeContext:
|
||||
public: true
|
||||
arguments:
|
||||
- "%env(CUSTOM_VARIABLE)%"
|
||||
"""
|
||||
And a feature file containing:
|
||||
"""
|
||||
Feature:
|
||||
Scenario:
|
||||
Then the passed parameter should be "lol2"
|
||||
"""
|
||||
When I run Behat
|
||||
Then it should pass
|
||||
@@ -51,7 +51,9 @@ final class SymfonyExtension implements Extension
|
||||
public function configure(ArrayNodeDefinition $builder): void
|
||||
{
|
||||
$builder
|
||||
->addDefaultsIfNotSet()
|
||||
->children()
|
||||
->scalarNode('bootstrap')->defaultNull()->end()
|
||||
->arrayNode('kernel')
|
||||
->addDefaultsIfNotSet()
|
||||
->children()
|
||||
@@ -67,7 +69,9 @@ final class SymfonyExtension implements Extension
|
||||
|
||||
public function load(ContainerBuilder $container, array $config): void
|
||||
{
|
||||
$this->loadKernel($container, $this->processKernelConfiguration($config['kernel']));
|
||||
$container->setParameter('fob_symfony.bootstrap', $config['bootstrap']);
|
||||
|
||||
$this->loadKernel($container, $this->autodiscoverKernelConfiguration($config['kernel']));
|
||||
$this->loadDriverKernel($container);
|
||||
|
||||
$this->loadKernelRebooter($container);
|
||||
@@ -82,6 +86,7 @@ final class SymfonyExtension implements Extension
|
||||
|
||||
public function process(ContainerBuilder $container): void
|
||||
{
|
||||
$this->processBootstrap($container->getParameter('fob_symfony.bootstrap'));
|
||||
}
|
||||
|
||||
private function registerMinkDriver(ExtensionManager $extensionManager): void
|
||||
@@ -157,7 +162,7 @@ final class SymfonyExtension implements Extension
|
||||
$container->setDefinition('fob_symfony.mink.parameters', $minkParametersDefinition);
|
||||
}
|
||||
|
||||
private function processKernelConfiguration(array $config): array
|
||||
private function autodiscoverKernelConfiguration(array $config): array
|
||||
{
|
||||
if ($config['class'] !== null) {
|
||||
return $config;
|
||||
@@ -187,4 +192,13 @@ final class SymfonyExtension implements Extension
|
||||
|
||||
return $config;
|
||||
}
|
||||
|
||||
private function processBootstrap(?string $bootstrap): void
|
||||
{
|
||||
if ($bootstrap === null) {
|
||||
return;
|
||||
}
|
||||
|
||||
require_once $bootstrap;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user