Skip to content
Browse files

added relative paths support

  • Loading branch information...
1 parent 35c8746 commit a851f457d7f3326871c0da75f5b021dbcc51cee7 @everzet everzet committed May 9, 2012
View
8 behat.yml.dist
@@ -1,12 +1,12 @@
default:
paths:
- features: %behat.paths.base%/features
- bootstrap: %behat.paths.base%/features/bootstrap
+ features: features
+ bootstrap: features/bootstrap
annotations:
paths:
- features: %behat.paths.base%/features/annotations
+ features: features/annotations
closures:
paths:
- features: %behat.paths.base%/features/closures
+ features: features/closures
View
47 src/Behat/Behat/Console/BehatApplication.php
@@ -73,6 +73,7 @@ public function doRun(InputInterface $input, OutputInterface $output)
$container = new ContainerBuilder();
$this->loadConfiguration($container, $input);
$this->loadExtensions($container);
+ $this->resolveRelativePaths($container);
// add core compiler passes
$container->addCompilerPass(new ConsoleProcessorsPass());
@@ -190,6 +191,30 @@ protected function loadExtensions(ContainerBuilder $container)
}
/**
+ * Resolves relative behat.paths.* parameters in container.
+ *
+ * @param ContainerBuilder $container
+ */
+ protected function resolveRelativePaths(ContainerBuilder $container)
+ {
+ $basePath = $container->getParameter('behat.paths.base');
+ $featuresPath = $container->getParameter('behat.paths.features');
+ $bootstrapPath = $container->getParameter('behat.paths.bootstrap');
+ $parameterBag = $container->getParameterBag();
+ $featuresPath = $parameterBag->resolveValue($featuresPath);
+ $bootstrapPath = $parameterBag->resolveValue($bootstrapPath);
+
+ if (!$this->isAbsolutePath($featuresPath)) {
+ $featuresPath = $basePath.DIRECTORY_SEPARATOR.$featuresPath;
+ $container->setParameter('behat.paths.features', $featuresPath);
+ }
+ if (!$this->isAbsolutePath($bootstrapPath)) {
+ $bootstrapPath = $basePath.DIRECTORY_SEPARATOR.$bootstrapPath;
+ $container->setParameter('behat.paths.bootstrap', $bootstrapPath);
+ }
+ }
+
+ /**
* {@inheritdoc}
*/
protected function getCommandName(InputInterface $input)
@@ -204,4 +229,26 @@ protected function getTerminalWidth()
{
return PHP_INT_MAX;
}
+
+ /**
+ * Returns whether the file path is an absolute path.
+ *
+ * @param string $file A file path
+ *
+ * @return Boolean
+ */
+ private function isAbsolutePath($file)
+ {
+ if ($file[0] == '/' || $file[0] == '\\'
+ || (strlen($file) > 3 && ctype_alpha($file[0])
+ && $file[1] == ':'
+ && ($file[2] == '\\' || $file[2] == '/')
+ )
+ || null !== parse_url($file, PHP_URL_SCHEME)
+ ) {
+ return true;
+ }
+
+ return false;
+ }
}
View
10 src/Behat/Behat/DependencyInjection/Configuration/Loader.php
@@ -104,6 +104,12 @@ protected function loadFileConfiguration($configFile, $profile)
$config = Yaml::parse($configFile);
$configs = array();
+ // first load default profile from current config
+ if (isset($config['default'])) {
+ $configs[] = $config['default'];
+ }
+
+ // then load profiles from import
if (isset($config['imports']) && is_array($config['imports'])) {
foreach ($config['imports'] as $path) {
foreach ($this->parseImport($configPath, $path, $profile) as $importConfig) {
@@ -112,9 +118,7 @@ protected function loadFileConfiguration($configFile, $profile)
}
}
- if (isset($config['default'])) {
- $configs[] = $config['default'];
- }
+ // then load specific profile from current config
if ('default' !== $profile && isset($config[$profile])) {
$configs[] = $config[$profile];
$this->profileFound = true;
View
2 src/Behat/Behat/Gherkin/Loader/FeatureSuiteLoader.php
@@ -33,7 +33,7 @@ class FeatureSuiteLoader extends AbstractFileLoader
*/
public function __construct($featuresPath, Gherkin $gherkin)
{
- $this->featuresPath = $this->findAbsolutePath($featuresPath);
+ $this->featuresPath = $featuresPath;
$this->gherkin = $gherkin;
}

0 comments on commit a851f45

Please sign in to comment.
Something went wrong with that request. Please try again.