diff --git a/features/configuration/loading_kernel_based_on_configurtion.feature b/features/configuration/loading_kernel_based_on_configurtion.feature new file mode 100644 index 0000000..219c74f --- /dev/null +++ b/features/configuration/loading_kernel_based_on_configurtion.feature @@ -0,0 +1,97 @@ +Feature: Loading kernel based on configuration + + Background: + Given a standard Symfony autoloader configured + And a feature file containing: + """ + Feature: + Scenario: + Then the passed service should be an instance of "\Psr\Container\ContainerInterface" + """ + And a Behat configuration containing: + """ + default: + suites: + default: + contexts: + - App\Tests\SomeContext + """ + And a context file "tests/SomeContext.php" containing: + """ + service = $service; } + + /** @Then the passed service should be an instance of :expected */ + public function serviceShouldBe(string $expected): void + { + assert(is_object($this->service)); + assert($this->service instanceof $expected); + } + } + """ + And a services file "config/services.yaml" containing: + """ + services: + App\Tests\SomeContext: + public: true + arguments: + - "@service_container" + """ + + Scenario: Loading kernel by its classname + Given a Behat configuration containing: + """ + default: + extensions: + FriendsOfBehat\SymfonyExtension: + kernel: + class: App\Custom\Kernel + """ + And a kernel file "src/Custom/Kernel.php" containing: + """ + loadFromExtension('framework', [ + 'test' => $this->getEnvironment() === 'test', + 'secret' => 'Pigeon', + ]); + + $loader->load(__DIR__ . '/../../config/services.yaml'); + } + + protected function configureRoutes(RouteCollectionBuilder $routes): void {} + } + """ + When I run Behat + Then it should pass diff --git a/tests/Behat/Context/TestContext.php b/tests/Behat/Context/TestContext.php index 1398c1f..0857bdf 100644 --- a/tests/Behat/Context/TestContext.php +++ b/tests/Behat/Context/TestContext.php @@ -51,6 +51,25 @@ final class TestContext implements Context self::$filesystem->remove(self::$workingDir); } + /** + * @Given a standard Symfony autoloader configured + */ + public function standardSymfonyAutoloaderConfigured(): void + { + $this->thereIsFile('vendor/autoload.php', sprintf(<<<'CON' +addPsr4('App\\', __DIR__ . '/../src/'); +$loader->addPsr4('App\\Tests\\', __DIR__ . '/../tests/'); + +return $loader; +CON + , __DIR__ . '/../../../vendor/autoload.php')); + } + /** * @Given a working Symfony application with SymfonyExtension configured */ @@ -65,18 +84,7 @@ default: CON ); - $this->thereIsFile('vendor/autoload.php', sprintf(<<<'CON' -addPsr4('App\\', __DIR__ . '/../src/'); -$loader->addPsr4('App\\Tests\\', __DIR__ . '/../tests/'); - -return $loader; -CON - , __DIR__ . '/../../../vendor/autoload.php')); + $this->standardSymfonyAutoloaderConfigured(); $this->thereIsFile('src/Kernel.php', <<<'CON'