From d31e56a20ac910c4c1016dc8730356baff4ecd5f Mon Sep 17 00:00:00 2001 From: Samuel ROZE Date: Mon, 5 Jun 2017 19:11:30 +0100 Subject: [PATCH 1/7] Add the Behat recipe --- behat/symfony2-extension/2.1/behat.yml.dist | 13 ++++++ .../2.1/features/bootstrap/FeatureContext.php | 40 +++++++++++++++++++ .../2.1/features/bootstrap/bootstrap.php | 10 +++++ .../2.1/features/demo.feature | 8 ++++ behat/symfony2-extension/2.1/manifest.json | 7 ++++ behat/symfony2-extension/2.1/post-install.txt | 2 + 6 files changed, 80 insertions(+) create mode 100644 behat/symfony2-extension/2.1/behat.yml.dist create mode 100644 behat/symfony2-extension/2.1/features/bootstrap/FeatureContext.php create mode 100644 behat/symfony2-extension/2.1/features/bootstrap/bootstrap.php create mode 100644 behat/symfony2-extension/2.1/features/demo.feature create mode 100644 behat/symfony2-extension/2.1/manifest.json create mode 100644 behat/symfony2-extension/2.1/post-install.txt diff --git a/behat/symfony2-extension/2.1/behat.yml.dist b/behat/symfony2-extension/2.1/behat.yml.dist new file mode 100644 index 00000000..49f422b4 --- /dev/null +++ b/behat/symfony2-extension/2.1/behat.yml.dist @@ -0,0 +1,13 @@ +default: + suites: + default: + contexts: + - FeatureContext: + kernel: '@kernel' + + extensions: + Behat\Symfony2Extension: + kernel: + bootstrap: features/bootstrap/bootstrap.php + path: src/Kernel.php + class: App\Kernel diff --git a/behat/symfony2-extension/2.1/features/bootstrap/FeatureContext.php b/behat/symfony2-extension/2.1/features/bootstrap/FeatureContext.php new file mode 100644 index 00000000..0835b5c7 --- /dev/null +++ b/behat/symfony2-extension/2.1/features/bootstrap/FeatureContext.php @@ -0,0 +1,40 @@ +kernel = $kernel; + } + + /** + * @When this is a demo scenario that sends a request to :path + */ + public function thisIsADemoScenarioThatSendsARequestTo(string $path) + { + $this->response = $this->kernel->handle(Request::create($path, 'GET')); + } + + /** + * @Then the response should be received + */ + public function theResponseShouldBeReceived() + { + assert($this->response !== null); + } +} diff --git a/behat/symfony2-extension/2.1/features/bootstrap/bootstrap.php b/behat/symfony2-extension/2.1/features/bootstrap/bootstrap.php new file mode 100644 index 00000000..a330c8a4 --- /dev/null +++ b/behat/symfony2-extension/2.1/features/bootstrap/bootstrap.php @@ -0,0 +1,10 @@ +load(__DIR__.'/../../.env'); +} diff --git a/behat/symfony2-extension/2.1/features/demo.feature b/behat/symfony2-extension/2.1/features/demo.feature new file mode 100644 index 00000000..99a20383 --- /dev/null +++ b/behat/symfony2-extension/2.1/features/demo.feature @@ -0,0 +1,8 @@ +Feature: + In order to proves that the Behat Symfony extension is correctly installed + As a user + I want to have a demo scenario + + Scenario: It receives a response from Symfony's kernel + When this is a demo scenario that sends a request to "/" + Then the response should be received diff --git a/behat/symfony2-extension/2.1/manifest.json b/behat/symfony2-extension/2.1/manifest.json new file mode 100644 index 00000000..a99c2a75 --- /dev/null +++ b/behat/symfony2-extension/2.1/manifest.json @@ -0,0 +1,7 @@ +{ + "copy-from-recipe": { + "behat.yml.dist": "behat.yml.dist", + "features/": "features/" + }, + "aliases": ["behat"] +} diff --git a/behat/symfony2-extension/2.1/post-install.txt b/behat/symfony2-extension/2.1/post-install.txt new file mode 100644 index 00000000..174c1204 --- /dev/null +++ b/behat/symfony2-extension/2.1/post-install.txt @@ -0,0 +1,2 @@ + Next for Behat/SymfonyExtension + Run vendor/bin/behat to run the demo tests. From 47dcdf198a05a88a3cc88e42df47878d7e0ffb27 Mon Sep 17 00:00:00 2001 From: Samuel ROZE Date: Wed, 7 Jun 2017 09:25:31 +0100 Subject: [PATCH 2/7] Rename the `@When` step --- .../2.1/features/bootstrap/FeatureContext.php | 4 ++-- behat/symfony2-extension/2.1/features/demo.feature | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/behat/symfony2-extension/2.1/features/bootstrap/FeatureContext.php b/behat/symfony2-extension/2.1/features/bootstrap/FeatureContext.php index 0835b5c7..3fbc2517 100644 --- a/behat/symfony2-extension/2.1/features/bootstrap/FeatureContext.php +++ b/behat/symfony2-extension/2.1/features/bootstrap/FeatureContext.php @@ -23,9 +23,9 @@ class FeatureContext implements Context } /** - * @When this is a demo scenario that sends a request to :path + * @When a demo scenario sends a request to :path */ - public function thisIsADemoScenarioThatSendsARequestTo(string $path) + public function aDemoScenarioSendsARequestTo(string $path) { $this->response = $this->kernel->handle(Request::create($path, 'GET')); } diff --git a/behat/symfony2-extension/2.1/features/demo.feature b/behat/symfony2-extension/2.1/features/demo.feature index 99a20383..31bf16dd 100644 --- a/behat/symfony2-extension/2.1/features/demo.feature +++ b/behat/symfony2-extension/2.1/features/demo.feature @@ -1,8 +1,8 @@ Feature: - In order to proves that the Behat Symfony extension is correctly installed + In order to prove that the Behat Symfony extension is correctly installed As a user I want to have a demo scenario Scenario: It receives a response from Symfony's kernel - When this is a demo scenario that sends a request to "/" + When a demo scenario sends a request to "/" Then the response should be received From 23b397fd5ff82ddd75b0e06d538fe8a60e72f890 Mon Sep 17 00:00:00 2001 From: Samuel ROZE Date: Wed, 7 Jun 2017 09:26:13 +0100 Subject: [PATCH 3/7] Remove the `path` of the kernel as autoloadable --- behat/symfony2-extension/2.1/behat.yml.dist | 1 - 1 file changed, 1 deletion(-) diff --git a/behat/symfony2-extension/2.1/behat.yml.dist b/behat/symfony2-extension/2.1/behat.yml.dist index 49f422b4..b4de76f6 100644 --- a/behat/symfony2-extension/2.1/behat.yml.dist +++ b/behat/symfony2-extension/2.1/behat.yml.dist @@ -9,5 +9,4 @@ default: Behat\Symfony2Extension: kernel: bootstrap: features/bootstrap/bootstrap.php - path: src/Kernel.php class: App\Kernel From 20b53655dd187d0e36a624e6552a015cff9e4d67 Mon Sep 17 00:00:00 2001 From: Samuel ROZE Date: Wed, 7 Jun 2017 10:14:19 +0100 Subject: [PATCH 4/7] Add comments mentionning these scenarios as demonstration and refering to Behat's website --- .../2.1/features/bootstrap/FeatureContext.php | 6 ++++++ behat/symfony2-extension/2.1/features/demo.feature | 4 ++++ 2 files changed, 10 insertions(+) diff --git a/behat/symfony2-extension/2.1/features/bootstrap/FeatureContext.php b/behat/symfony2-extension/2.1/features/bootstrap/FeatureContext.php index 3fbc2517..23e3386a 100644 --- a/behat/symfony2-extension/2.1/features/bootstrap/FeatureContext.php +++ b/behat/symfony2-extension/2.1/features/bootstrap/FeatureContext.php @@ -5,6 +5,12 @@ use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpKernel\KernelInterface; +/** + * This context class contains the definitions of the steps used by the demo + * feature file. Learn how to get started with Behat and BDD on Behat's website. + * + * @see http://behat.org/en/latest/quick_start.html + */ class FeatureContext implements Context { /** diff --git a/behat/symfony2-extension/2.1/features/demo.feature b/behat/symfony2-extension/2.1/features/demo.feature index 31bf16dd..295db96e 100644 --- a/behat/symfony2-extension/2.1/features/demo.feature +++ b/behat/symfony2-extension/2.1/features/demo.feature @@ -1,3 +1,7 @@ +# This file contains a user story for demonstration only. +# Learn how to get started with Behat and BDD on Behat's website: +# http://behat.org/en/latest/quick_start.html + Feature: In order to prove that the Behat Symfony extension is correctly installed As a user From 7d28af71d83a78972b55fdd67b3e176b8e3f3de9 Mon Sep 17 00:00:00 2001 From: Samuel ROZE Date: Wed, 7 Jun 2017 10:15:19 +0100 Subject: [PATCH 5/7] Add `behat.yml` to `gitignore` --- behat/symfony2-extension/2.1/manifest.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/behat/symfony2-extension/2.1/manifest.json b/behat/symfony2-extension/2.1/manifest.json index a99c2a75..73d92320 100644 --- a/behat/symfony2-extension/2.1/manifest.json +++ b/behat/symfony2-extension/2.1/manifest.json @@ -3,5 +3,6 @@ "behat.yml.dist": "behat.yml.dist", "features/": "features/" }, - "aliases": ["behat"] + "aliases": ["behat"], + "gitignore": ["behat.yml"] } From 36565deb4e004340e85fbbf985dbe5528410071f Mon Sep 17 00:00:00 2001 From: Samuel ROZE Date: Thu, 22 Jun 2017 10:09:39 +0100 Subject: [PATCH 6/7] Remove the `require` on autoload, as it's already loaded by Behat before --- behat/symfony2-extension/2.1/features/bootstrap/bootstrap.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/behat/symfony2-extension/2.1/features/bootstrap/bootstrap.php b/behat/symfony2-extension/2.1/features/bootstrap/bootstrap.php index a330c8a4..f76e1d95 100644 --- a/behat/symfony2-extension/2.1/features/bootstrap/bootstrap.php +++ b/behat/symfony2-extension/2.1/features/bootstrap/bootstrap.php @@ -2,8 +2,6 @@ use Symfony\Component\Dotenv\Dotenv; -require __DIR__.'/../../vendor/autoload.php'; - // The check is to ensure we don't use .env in production if (!getenv('APP_ENV')) { (new Dotenv())->load(__DIR__.'/../../.env'); From fe2e6dd61fed6ae5074474f98b0bea0cddf9614a Mon Sep 17 00:00:00 2001 From: Samuel ROZE Date: Thu, 22 Jun 2017 10:49:55 +0100 Subject: [PATCH 7/7] Throw an exception instead of using `assert` --- .../2.1/features/bootstrap/FeatureContext.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/behat/symfony2-extension/2.1/features/bootstrap/FeatureContext.php b/behat/symfony2-extension/2.1/features/bootstrap/FeatureContext.php index 23e3386a..bfb1459a 100644 --- a/behat/symfony2-extension/2.1/features/bootstrap/FeatureContext.php +++ b/behat/symfony2-extension/2.1/features/bootstrap/FeatureContext.php @@ -41,6 +41,8 @@ class FeatureContext implements Context */ public function theResponseShouldBeReceived() { - assert($this->response !== null); + if ($this->response === null) { + throw new \RuntimeException('No response received'); + } } }