Merge pull request #6 from pamil/behat-features

Use TestContext & Behat to perform basic tests, fix kernel file / bootstrap loading
This commit is contained in:
Mateusz Zalewski
2016-11-03 13:13:41 +01:00
committed by GitHub
9 changed files with 97 additions and 9 deletions

3
.gitattributes vendored
View File

@@ -1,3 +1,6 @@
/features export-ignore
/.gitattributes export-ignore
/.gitignore export-ignore
/.travis.yml export-ignore
/behat.yml.dist export-ignore

3
.gitignore vendored
View File

@@ -1,3 +1,4 @@
/vendor
/composer.lock
/behat.yml

View File

@@ -33,4 +33,4 @@ install:
script:
- composer validate --strict
- vendor/bin/behat --strict --config=test/behat.yml
- vendor/bin/behat --strict -vvv --no-interaction

View File

@@ -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

5
behat.yml.dist Normal file
View File

@@ -0,0 +1,5 @@
default:
suites:
default:
contexts:
- FriendsOfBehat\TestContext\Context\TestContext

View File

@@ -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": {

View File

@@ -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:
"""
<?php
use Symfony\Component\HttpKernel\Kernel;
use Symfony\Component\Config\Loader\LoaderInterface;
class AppKernel extends Kernel
{
public function registerBundles() { return []; }
public function registerContainerConfiguration(LoaderInterface $loader) {}
}
"""
And a feature file with passing scenario
When I run Behat
Then it should pass

View File

@@ -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.');
}
}

View File

@@ -1,3 +0,0 @@
default:
extensions:
FriendsOfBehat\SymfonyExtension: ~