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:
3
.gitattributes
vendored
3
.gitattributes
vendored
@@ -1,3 +1,6 @@
|
|||||||
|
/features export-ignore
|
||||||
|
|
||||||
/.gitattributes export-ignore
|
/.gitattributes export-ignore
|
||||||
/.gitignore export-ignore
|
/.gitignore export-ignore
|
||||||
/.travis.yml export-ignore
|
/.travis.yml export-ignore
|
||||||
|
/behat.yml.dist export-ignore
|
||||||
|
|||||||
3
.gitignore
vendored
3
.gitignore
vendored
@@ -1,3 +1,4 @@
|
|||||||
/vendor
|
/vendor
|
||||||
|
|
||||||
/composer.lock
|
/composer.lock
|
||||||
|
|
||||||
|
/behat.yml
|
||||||
|
|||||||
@@ -33,4 +33,4 @@ install:
|
|||||||
script:
|
script:
|
||||||
- composer validate --strict
|
- composer validate --strict
|
||||||
|
|
||||||
- vendor/bin/behat --strict --config=test/behat.yml
|
- vendor/bin/behat --strict -vvv --no-interaction
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
# Symfony Extension [](https://packagist.org/packages/friends-of-behat/symfony-extension) [](https://packagist.org/packages/friends-of-behat/symfony-extension) [](http://travis-ci.org/FriendsOfBehat/SymfonyExtension) [](https://scrutinizer-ci.com/g/FriendsOfBehat/SymfonyExtension/)
|
# Symfony Extension [](https://packagist.org/packages/friends-of-behat/symfony-extension) [](https://packagist.org/packages/friends-of-behat/symfony-extension) [](http://travis-ci.org/FriendsOfBehat/SymfonyExtension) [](https://scrutinizer-ci.com/g/FriendsOfBehat/SymfonyExtension/)
|
||||||
|
|
||||||
|
Integrates Behat with Symfony (both 2 and 3).
|
||||||
[WIP] Integrates Behat with Symfony (both 2 and 3).
|
|
||||||
Inspired by [Behat/Symfony2Extension](https://github.com/Behat/Symfony2Extension).
|
Inspired by [Behat/Symfony2Extension](https://github.com/Behat/Symfony2Extension).
|
||||||
|
|
||||||
## Differences
|
## Differences
|
||||||
|
|||||||
5
behat.yml.dist
Normal file
5
behat.yml.dist
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
default:
|
||||||
|
suites:
|
||||||
|
default:
|
||||||
|
contexts:
|
||||||
|
- FriendsOfBehat\TestContext\Context\TestContext
|
||||||
@@ -19,6 +19,7 @@
|
|||||||
"behat/mink": "^1.7",
|
"behat/mink": "^1.7",
|
||||||
"behat/mink-browserkit-driver": "^1.3",
|
"behat/mink-browserkit-driver": "^1.3",
|
||||||
"behat/mink-extension": "^2.2",
|
"behat/mink-extension": "^2.2",
|
||||||
|
"friends-of-behat/test-context": "^0.3",
|
||||||
"symfony/framework-bundle": "^2.7|^3.0"
|
"symfony/framework-bundle": "^2.7|^3.0"
|
||||||
},
|
},
|
||||||
"suggest": {
|
"suggest": {
|
||||||
|
|||||||
30
features/not_crashing_behat.feature
Normal file
30
features/not_crashing_behat.feature
Normal 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
|
||||||
@@ -123,9 +123,11 @@ final class SymfonyExtension implements Extension
|
|||||||
$config['debug'],
|
$config['debug'],
|
||||||
));
|
));
|
||||||
$definition->addMethodCall('boot');
|
$definition->addMethodCall('boot');
|
||||||
|
$definition->setFile($this->getKernelFile($container->getParameter('paths.base'), $config['path']));
|
||||||
|
|
||||||
$container->setDefinition(self::KERNEL_ID, $definition);
|
$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)
|
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.');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,3 +0,0 @@
|
|||||||
default:
|
|
||||||
extensions:
|
|
||||||
FriendsOfBehat\SymfonyExtension: ~
|
|
||||||
Reference in New Issue
Block a user