From 64661a706d5ca5b279e4180cc8cd059e4f362310 Mon Sep 17 00:00:00 2001 From: Kamil Kokot Date: Thu, 3 Nov 2016 11:34:51 +0100 Subject: [PATCH 1/4] Remove old tests --- .gitignore | 1 - .travis.yml | 2 +- README.md | 3 +-- test/behat.yml | 3 --- 4 files changed, 2 insertions(+), 7 deletions(-) delete mode 100644 test/behat.yml diff --git a/.gitignore b/.gitignore index 61c232d..de4a392 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,2 @@ /vendor - /composer.lock diff --git a/.travis.yml b/.travis.yml index 33220a3..9551e40 100644 --- a/.travis.yml +++ b/.travis.yml @@ -33,4 +33,4 @@ install: script: - composer validate --strict - - vendor/bin/behat --strict --config=test/behat.yml + - vendor/bin/behat --strict -vvv --no-interaction diff --git a/README.md b/README.md index 8bb649b..740fd17 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,6 @@ # Symfony Extension [![License](https://img.shields.io/packagist/l/friends-of-behat/symfony-extension.svg)](https://packagist.org/packages/friends-of-behat/symfony-extension) [![Version](https://img.shields.io/packagist/v/friends-of-behat/symfony-extension.svg)](https://packagist.org/packages/friends-of-behat/symfony-extension) [![Build status on Linux](https://img.shields.io/travis/FriendsOfBehat/SymfonyExtension/master.svg)](http://travis-ci.org/FriendsOfBehat/SymfonyExtension) [![Scrutinizer Quality Score](https://img.shields.io/scrutinizer/g/FriendsOfBehat/SymfonyExtension.svg)](https://scrutinizer-ci.com/g/FriendsOfBehat/SymfonyExtension/) - -[WIP] Integrates Behat with Symfony (both 2 and 3). +Integrates Behat with Symfony (both 2 and 3). Inspired by [Behat/Symfony2Extension](https://github.com/Behat/Symfony2Extension). ## Differences diff --git a/test/behat.yml b/test/behat.yml deleted file mode 100644 index ccff702..0000000 --- a/test/behat.yml +++ /dev/null @@ -1,3 +0,0 @@ -default: - extensions: - FriendsOfBehat\SymfonyExtension: ~ From d02f77a2d1d48144d912cba20a2737d0fc7048bf Mon Sep 17 00:00:00 2001 From: Kamil Kokot Date: Thu, 3 Nov 2016 11:36:50 +0100 Subject: [PATCH 2/4] Prepare Behat boilerplate --- .gitattributes | 3 +++ .gitignore | 2 ++ behat.yml.dist | 5 +++++ composer.json | 1 + 4 files changed, 11 insertions(+) create mode 100644 behat.yml.dist diff --git a/.gitattributes b/.gitattributes index fd1bf2d..3d1aaa2 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1,3 +1,6 @@ +/features export-ignore + /.gitattributes export-ignore /.gitignore export-ignore /.travis.yml export-ignore +/behat.yml.dist export-ignore diff --git a/.gitignore b/.gitignore index de4a392..5eb3730 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,4 @@ /vendor /composer.lock + +/behat.yml diff --git a/behat.yml.dist b/behat.yml.dist new file mode 100644 index 0000000..a94d08d --- /dev/null +++ b/behat.yml.dist @@ -0,0 +1,5 @@ +default: + suites: + default: + contexts: + - FriendsOfBehat\TestContext\Context\TestContext diff --git a/composer.json b/composer.json index b76a13f..92114b8 100644 --- a/composer.json +++ b/composer.json @@ -19,6 +19,7 @@ "behat/mink": "^1.7", "behat/mink-browserkit-driver": "^1.3", "behat/mink-extension": "^2.2", + "friends-of-behat/test-context": "^0.3", "symfony/framework-bundle": "^2.7|^3.0" }, "suggest": { From 8437a3b18a1fe5cc9fa274c5fa9b931defe5adab Mon Sep 17 00:00:00 2001 From: Kamil Kokot Date: Thu, 3 Nov 2016 12:54:30 +0100 Subject: [PATCH 3/4] Ensure that this extension does not crash anything --- features/not_crashing_behat.feature | 30 +++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 features/not_crashing_behat.feature diff --git a/features/not_crashing_behat.feature b/features/not_crashing_behat.feature new file mode 100644 index 0000000..4a8ed91 --- /dev/null +++ b/features/not_crashing_behat.feature @@ -0,0 +1,30 @@ +Feature: Not crashing Behat + In order to use this extension + As a Behat User + I want to have Behat up and running after enabling this extension + + Scenario: Not crashing Behat + Given a Behat configuration containing: + """ + default: + extensions: + FriendsOfBehat\SymfonyExtension: + kernel: + bootstrap: ~ + """ + And a file "app/AppKernel.php" containing: + """ + Date: Thu, 3 Nov 2016 12:54:54 +0100 Subject: [PATCH 4/4] Set up kernel file & bootstrap application if needed --- src/ServiceContainer/SymfonyExtension.php | 56 ++++++++++++++++++++++- 1 file changed, 54 insertions(+), 2 deletions(-) diff --git a/src/ServiceContainer/SymfonyExtension.php b/src/ServiceContainer/SymfonyExtension.php index ceaa0db..c51e75c 100644 --- a/src/ServiceContainer/SymfonyExtension.php +++ b/src/ServiceContainer/SymfonyExtension.php @@ -123,9 +123,11 @@ final class SymfonyExtension implements Extension $config['debug'], )); $definition->addMethodCall('boot'); + $definition->setFile($this->getKernelFile($container->getParameter('paths.base'), $config['path'])); + $container->setDefinition(self::KERNEL_ID, $definition); - $container->setParameter(self::KERNEL_ID . '.path', $config['path']); - $container->setParameter(self::KERNEL_ID . '.bootstrap', $config['bootstrap']); + + $this->requireKernelBootstrapFile($container->getParameter('paths.base'), $config['bootstrap']); } /** @@ -199,4 +201,54 @@ final class SymfonyExtension implements Extension new Reference(self::DRIVER_KERNEL_ID) )); } + + /** + * @param string $basePath + * @param string $kernelPath + * + * @return string|null + */ + private function getKernelFile($basePath, $kernelPath) + { + $possibleFiles = [ + sprintf('%s/%s', $basePath, $kernelPath), + $kernelPath, + ]; + + foreach ($possibleFiles as $possibleFile) { + if (file_exists($possibleFile)) { + return $possibleFile; + } + } + + return null; + } + + /** + * @param string $basePath + * @param string|null $bootstrapPath + * + * @throws \DomainException + */ + private function requireKernelBootstrapFile($basePath, $bootstrapPath) + { + if (null === $bootstrapPath) { + return; + } + + $possiblePaths = [ + sprintf('%s/%s', $basePath, $bootstrapPath), + $bootstrapPath, + ]; + + foreach ($possiblePaths as $possiblePath) { + if (file_exists($possiblePath)) { + require_once $possiblePath; + + return; + } + } + + throw new \DomainException('Could not load bootstrap file.'); + } }