diff --git a/features/configuration/autodiscovering_application_kernel.feature b/features/configuration/autodiscovering_application_kernel.feature index 43df648..04b8dad 100644 --- a/features/configuration/autodiscovering_application_kernel.feature +++ b/features/configuration/autodiscovering_application_kernel.feature @@ -49,7 +49,7 @@ Feature: Autodiscovering the application kernel - "@service_container" """ - Scenario: Autodiscovering kernel in Symfony 3 directory structure application + Scenario: Autodiscovering kernel in Symfony 4 directory structure application Given a kernel file "src/Kernel.php" containing: """ 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" + """ + + Scenario: Autodiscovering bootstrap file in Symfony 4 directory structure application + Given a boostrap file "config/bootstrap.php" containing: + """ + processBootstrap($container->getParameter('fob_symfony.bootstrap')); + $this->processBootstrap($this->autodiscoverBootstrap($container->getParameter('fob_symfony.bootstrap'))); } private function registerMinkDriver(ExtensionManager $extensionManager): void @@ -193,6 +193,44 @@ final class SymfonyExtension implements Extension return $config; } + /** + * @param string|bool|null $bootstrap + */ + private function autodiscoverBootstrap($bootstrap): ?string + { + if (is_string($bootstrap)) { + return $bootstrap; + } + + if ($bootstrap === false) { + return null; + } + + $autoconfigured = 0; + + if (file_exists('config/bootstrap.php')) { + $bootstrap = 'config/bootstrap.php'; + + ++$autoconfigured; + } + + if (file_exists('app/autoload.php')) { + $bootstrap = 'app/autoload.php'; + + ++$autoconfigured; + } + + if ($autoconfigured === 2) { + throw new \RuntimeException( + 'Could not autodiscover the bootstrap file. ' . + 'Please define it manually with "FriendsOfBehat\SymfonyExtension.bootstrap" configuration option. ' . + 'Setting that option to "false" disables autodiscovering.' + ); + } + + return is_string($bootstrap) ? $bootstrap : null; + } + private function processBootstrap(?string $bootstrap): void { if ($bootstrap === null) {