Skip to content

Commit

Permalink
Merge pull request #6 from pamil/behat-features
Browse files Browse the repository at this point in the history
Use TestContext & Behat to perform basic tests, fix kernel file / bootstrap loading
  • Loading branch information
Zales0123 authored Nov 3, 2016
2 parents d7f39e3 + f98a7a1 commit 1c5906c
Show file tree
Hide file tree
Showing 9 changed files with 97 additions and 9 deletions.
3 changes: 3 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
/features export-ignore

/.gitattributes export-ignore
/.gitignore export-ignore
/.travis.yml export-ignore
/behat.yml.dist export-ignore
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/vendor

/composer.lock

/behat.yml
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,4 @@ install:
script:
- composer validate --strict

- vendor/bin/behat --strict --config=test/behat.yml
- vendor/bin/behat --strict -vvv --no-interaction
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
5 changes: 5 additions & 0 deletions behat.yml.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
default:
suites:
default:
contexts:
- FriendsOfBehat\TestContext\Context\TestContext
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
30 changes: 30 additions & 0 deletions features/not_crashing_behat.feature
Original file line number Diff line number Diff line change
@@ -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
56 changes: 54 additions & 2 deletions src/ServiceContainer/SymfonyExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -123,9 +123,11 @@ private function loadKernel(ContainerBuilder $container, array $config)
$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']);
}

/**
Expand Down Expand Up @@ -199,4 +201,54 @@ private function registerSymfonyDriverFactory(ExtensionManager $extensionManager
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.');
}
}
3 changes: 0 additions & 3 deletions test/behat.yml

This file was deleted.

0 comments on commit 1c5906c

Please sign in to comment.