From 9c41bdbcba873022ff7efe58fa1daa2f7aee4bef Mon Sep 17 00:00:00 2001 From: Kamil Kokot Date: Mon, 31 Dec 2018 17:19:50 +0100 Subject: [PATCH] Compress scenario --- composer.json | 3 +- features/running_bare_behat_scenarios.feature | 48 +--------- tests/Behat/Context/TestContext.php | 93 ++++++++++++++++++- 3 files changed, 93 insertions(+), 51 deletions(-) diff --git a/composer.json b/composer.json index b3019d5..f359d0e 100644 --- a/composer.json +++ b/composer.json @@ -22,7 +22,8 @@ "behat/mink-extension": "^2.2", "phpstan/phpstan-shim": "^0.10", "sylius-labs/coding-standard": "^3.0", - "symfony/framework-bundle": "^3.4|^4.1" + "symfony/framework-bundle": "^3.4|^4.1", + "symfony/yaml": "^3.4|^4.1" }, "suggest": { "behat/mink-browserkit-driver": "^1.3" diff --git a/features/running_bare_behat_scenarios.feature b/features/running_bare_behat_scenarios.feature index afddca2..9febc9a 100644 --- a/features/running_bare_behat_scenarios.feature +++ b/features/running_bare_behat_scenarios.feature @@ -1,51 +1,9 @@ Feature: Running bare Behat scenarios Scenario: Running Behat with SymfonyExtension - Given a Behat configuration containing: - """ - default: - extensions: - FriendsOfBehat\SymfonyExtension: - kernel: - path: app/AppKernel.php - class: AppKernel - - Behat\MinkExtension: - base_url: "http://localhost:8080/" - default_session: symfony - sessions: - symfony: - symfony: ~ - """ - And a file "app/AppKernel.php" containing: - """ - load(function (ContainerBuilder $container): void { - $container->loadFromExtension('framework', [ - 'test' => $this->getEnvironment() === 'test', - 'secret' => 'Pigeon', - ]); - }); - } - } - """ + Given a Behat configuration with the minimal working configuration for SymfonyExtension + And a Behat configuration with the minimal working configuration for MinkExtension + And an application kernel with the minimal working configuration for SymfonyExtension And a feature file with passing scenario When I run Behat Then it should pass diff --git a/tests/Behat/Context/TestContext.php b/tests/Behat/Context/TestContext.php index 286d511..8dae841 100644 --- a/tests/Behat/Context/TestContext.php +++ b/tests/Behat/Context/TestContext.php @@ -8,6 +8,7 @@ use Behat\Behat\Context\Context; use Symfony\Component\Filesystem\Filesystem; use Symfony\Component\Process\PhpExecutableFinder; use Symfony\Component\Process\Process; +use Symfony\Component\Yaml\Yaml; final class TestContext implements Context { @@ -63,7 +64,53 @@ final class TestContext implements Context */ public function thereIsConfiguration($content): void { - $this->thereIsFile('behat.yml', $content); + $mainConfigFile = sprintf('%s/behat.yml', self::$workingDir); + $newConfigFile = sprintf('%s/behat-%s.yml', self::$workingDir, md5($content)); + + self::$filesystem->dumpFile($newConfigFile, (string) $content); + + if (!file_exists($mainConfigFile)) { + self::$filesystem->dumpFile($mainConfigFile, Yaml::dump(['imports' => []])); + } + + $mainBehatConfiguration = Yaml::parseFile($mainConfigFile); + $mainBehatConfiguration['imports'][] = $newConfigFile; + + 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$/ + */ + public function thereIsConfigurationWithMinimalWorkingConfigurationForMinkExtension(): void + { + $this->thereIsConfiguration(<<<'CON' +default: + extensions: + Behat\MinkExtension: + base_url: "http://localhost:8080/" + default_session: symfony + sessions: + symfony: + symfony: ~ +CON + ); } /** @@ -74,6 +121,42 @@ final class TestContext implements Context 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 /^a feature file containing(?: "([^"]+)"|:)$/ */ @@ -87,7 +170,7 @@ final class TestContext implements Context */ public function thereIsFeatureFileWithPassingScenario(): void { - $this->thereIsFile('features/bootstrap/FeatureContext.php', <<thereIsFile('features/bootstrap/FeatureContext.php', <<<'CON' thereIsFile('features/bootstrap/FeatureContext.php', <<thereIsFile('features/bootstrap/FeatureContext.php', <<<'CON' thereIsFile('features/bootstrap/FeatureContext.php', <<thereIsFile('features/bootstrap/FeatureContext.php', <<<'CON' thereIsFile('features/bootstrap/FeatureContext.php', <<thereIsFile('features/bootstrap/FeatureContext.php', <<<'CON'