diff --git a/features/injecting_parameters_into_context.feature b/features/injecting_parameters_into_context.feature index a1d1086..a18e2f6 100644 --- a/features/injecting_parameters_into_context.feature +++ b/features/injecting_parameters_into_context.feature @@ -1,6 +1,7 @@ Feature: Injecting parameters into context Background: + Given a working Symfony application with SymfonyExtension configured Given a context file "features/bootstrap/FeatureContext.php" containing: """ registerSymfonyDriverFactory($extensionManager); + /** @var MinkExtension|null $minkExtension */ + $minkExtension = $extensionManager->getExtension('mink'); + if (null === $minkExtension) { + return; + } + + $minkExtension->registerDriverFactory(new SymfonyDriverFactory('symfony', new Reference(self::DRIVER_KERNEL_ID))); + $this->minkExtensionFound = true; } public function configure(ArrayNodeDefinition $builder): void @@ -75,8 +85,10 @@ final class SymfonyExtension implements Extension $this->loadEnvironmentHandler($container); - $this->loadMinkDefaultSession($container); - $this->loadMinkParameters($container); + if ($this->minkExtensionFound) { + $this->loadMinkDefaultSession($container); + $this->loadMinkParameters($container); + } } public function process(ContainerBuilder $container): void @@ -166,15 +178,4 @@ final class SymfonyExtension implements Extension $container->setDefinition('fob_symfony.mink.parameters', $minkParametersDefinition); } - - private function registerSymfonyDriverFactory(ExtensionManager $extensionManager): void - { - /** @var MinkExtension|null $minkExtension */ - $minkExtension = $extensionManager->getExtension('mink'); - if (null === $minkExtension) { - return; - } - - $minkExtension->registerDriverFactory(new SymfonyDriverFactory('symfony', new Reference(self::DRIVER_KERNEL_ID))); - } } diff --git a/tests/Behat/Context/TestContext.php b/tests/Behat/Context/TestContext.php index 4e72daf..b1a1cbb 100644 --- a/tests/Behat/Context/TestContext.php +++ b/tests/Behat/Context/TestContext.php @@ -59,13 +59,77 @@ final class TestContext implements Context self::$filesystem->remove(self::$workingDir); } + /** + * @Given a working Symfony application with SymfonyExtension configured + */ + public function workingSymfonyApplicationWithExtension(): void + { + $this->thereIsConfiguration(<<<'CON' +default: + extensions: + FriendsOfBehat\SymfonyExtension: + kernel: + class: App\Kernel +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->thereIsFile('src/Kernel.php', <<<'CON' +load(function (ContainerBuilder $container): void { + $container->loadFromExtension('framework', [ + 'test' => $this->getEnvironment() === 'test', + 'secret' => 'Pigeon', + ]); + }); + + $loader->load(__DIR__ . '/../config/services.yaml'); + } +} +CON + ); + + $this->thereIsFile('config/services.yaml', ''); + } + /** * @Given /^a Behat configuration containing(?: "([^"]+)"|:)$/ */ public function thereIsConfiguration($content): void { $mainConfigFile = sprintf('%s/behat.yml', self::$workingDir); - $newConfigFile = sprintf('%s/behat-%s.yml', self::$workingDir, md5($content)); + $newConfigFile = sprintf('%s/behat-%s.yml', self::$workingDir, md5((string) $content)); self::$filesystem->dumpFile($newConfigFile, (string) $content); @@ -79,21 +143,6 @@ final class TestContext implements Context self::$filesystem->dumpFile($mainConfigFile, Yaml::dump($mainBehatConfiguration)); } - /** - * @Given /^a Behat configuration with the minimal working configuration for SymfonyExtension$/ - */ - public function thereIsConfigurationWithMinimalWorkingConfigurationForSymfonyExtension(): void - { - $this->thereIsConfiguration(<<<'CON' -default: - extensions: - FriendsOfBehat\SymfonyExtension: - kernel: - path: app/AppKernel.php - class: AppKernel -CON - ); - } /** * @Given /^a Behat configuration with the minimal working configuration for MinkExtension$/ @@ -121,84 +170,6 @@ CON self::$filesystem->dumpFile(self::$workingDir . '/' . $file, (string) $content); } - /** - * @Given /^an application kernel with the minimal working configuration for SymfonyExtension$/ - */ - public function thereIsKernelWithMinimalWorkingConfiguration(): void - { - $this->thereIsFile('app/AppKernel.php', <<<'CON' -load(function (ContainerBuilder $container): void { - $container->loadFromExtension('framework', [ - 'test' => $this->getEnvironment() === 'test', - 'secret' => 'Pigeon', - ]); - }); - } -} -CON - ); - } - - /** - * @Given /^an application kernel injecting a parameter into the FeatureContext class$/ - */ - public function thereIsKernelInjectingParameterIntoFeatureContextClass(): void - { - $this->thereIsFile('app/AppKernel.php', <<<'CON' -load(function (ContainerBuilder $container): void { - $container->loadFromExtension('framework', [ - 'test' => $this->getEnvironment() === 'test', - 'secret' => 'Pigeon', - ]); - - $contextDefinition = new Definition(FeatureContext::class, [new Parameter('kernel.environment')]); - $contextDefinition->setAutoconfigured(true); - $container->setDefinition(FeatureContext::class, $contextDefinition); - }); - } -} -CON - ); - } - /** * @Given /^a feature file containing(?: "([^"]+)"|:)$/ */ @@ -207,110 +178,6 @@ CON $this->thereIsFile(sprintf('features/%s.feature', md5(uniqid('', true))), $content); } - /** - * @Given /^a feature file with passing scenario$/ - */ - public function thereIsFeatureFileWithPassingScenario(): void - { - $this->thereIsFile('features/bootstrap/FeatureContext.php', <<<'CON' -thereIsFeatureFile(<<thereIsFile('features/bootstrap/FeatureContext.php', <<<'CON' -thereIsFeatureFile(<<thereIsFile('features/bootstrap/FeatureContext.php', <<<'CON' -thereIsFeatureFile(<<thereIsFile('features/bootstrap/FeatureContext.php', <<<'CON' -thereIsFeatureFile(<<