Skip to content
This repository
Browse code

added relative paths support

  • Loading branch information...
commit a851f457d7f3326871c0da75f5b021dbcc51cee7 1 parent 35c8746
Konstantin Kudryashov everzet authored
8 behat.yml.dist
... ... @@ -1,12 +1,12 @@
1 1 default:
2 2 paths:
3   - features: %behat.paths.base%/features
4   - bootstrap: %behat.paths.base%/features/bootstrap
  3 + features: features
  4 + bootstrap: features/bootstrap
5 5
6 6 annotations:
7 7 paths:
8   - features: %behat.paths.base%/features/annotations
  8 + features: features/annotations
9 9
10 10 closures:
11 11 paths:
12   - features: %behat.paths.base%/features/closures
  12 + features: features/closures
47 src/Behat/Behat/Console/BehatApplication.php
@@ -73,6 +73,7 @@ public function doRun(InputInterface $input, OutputInterface $output)
73 73 $container = new ContainerBuilder();
74 74 $this->loadConfiguration($container, $input);
75 75 $this->loadExtensions($container);
  76 + $this->resolveRelativePaths($container);
76 77
77 78 // add core compiler passes
78 79 $container->addCompilerPass(new ConsoleProcessorsPass());
@@ -190,6 +191,30 @@ protected function loadExtensions(ContainerBuilder $container)
190 191 }
191 192
192 193 /**
  194 + * Resolves relative behat.paths.* parameters in container.
  195 + *
  196 + * @param ContainerBuilder $container
  197 + */
  198 + protected function resolveRelativePaths(ContainerBuilder $container)
  199 + {
  200 + $basePath = $container->getParameter('behat.paths.base');
  201 + $featuresPath = $container->getParameter('behat.paths.features');
  202 + $bootstrapPath = $container->getParameter('behat.paths.bootstrap');
  203 + $parameterBag = $container->getParameterBag();
  204 + $featuresPath = $parameterBag->resolveValue($featuresPath);
  205 + $bootstrapPath = $parameterBag->resolveValue($bootstrapPath);
  206 +
  207 + if (!$this->isAbsolutePath($featuresPath)) {
  208 + $featuresPath = $basePath.DIRECTORY_SEPARATOR.$featuresPath;
  209 + $container->setParameter('behat.paths.features', $featuresPath);
  210 + }
  211 + if (!$this->isAbsolutePath($bootstrapPath)) {
  212 + $bootstrapPath = $basePath.DIRECTORY_SEPARATOR.$bootstrapPath;
  213 + $container->setParameter('behat.paths.bootstrap', $bootstrapPath);
  214 + }
  215 + }
  216 +
  217 + /**
193 218 * {@inheritdoc}
194 219 */
195 220 protected function getCommandName(InputInterface $input)
@@ -204,4 +229,26 @@ protected function getTerminalWidth()
204 229 {
205 230 return PHP_INT_MAX;
206 231 }
  232 +
  233 + /**
  234 + * Returns whether the file path is an absolute path.
  235 + *
  236 + * @param string $file A file path
  237 + *
  238 + * @return Boolean
  239 + */
  240 + private function isAbsolutePath($file)
  241 + {
  242 + if ($file[0] == '/' || $file[0] == '\\'
  243 + || (strlen($file) > 3 && ctype_alpha($file[0])
  244 + && $file[1] == ':'
  245 + && ($file[2] == '\\' || $file[2] == '/')
  246 + )
  247 + || null !== parse_url($file, PHP_URL_SCHEME)
  248 + ) {
  249 + return true;
  250 + }
  251 +
  252 + return false;
  253 + }
207 254 }
10 src/Behat/Behat/DependencyInjection/Configuration/Loader.php
@@ -104,6 +104,12 @@ protected function loadFileConfiguration($configFile, $profile)
104 104 $config = Yaml::parse($configFile);
105 105 $configs = array();
106 106
  107 + // first load default profile from current config
  108 + if (isset($config['default'])) {
  109 + $configs[] = $config['default'];
  110 + }
  111 +
  112 + // then load profiles from import
107 113 if (isset($config['imports']) && is_array($config['imports'])) {
108 114 foreach ($config['imports'] as $path) {
109 115 foreach ($this->parseImport($configPath, $path, $profile) as $importConfig) {
@@ -112,9 +118,7 @@ protected function loadFileConfiguration($configFile, $profile)
112 118 }
113 119 }
114 120
115   - if (isset($config['default'])) {
116   - $configs[] = $config['default'];
117   - }
  121 + // then load specific profile from current config
118 122 if ('default' !== $profile && isset($config[$profile])) {
119 123 $configs[] = $config[$profile];
120 124 $this->profileFound = true;
2  src/Behat/Behat/Gherkin/Loader/FeatureSuiteLoader.php
@@ -33,7 +33,7 @@ class FeatureSuiteLoader extends AbstractFileLoader
33 33 */
34 34 public function __construct($featuresPath, Gherkin $gherkin)
35 35 {
36   - $this->featuresPath = $this->findAbsolutePath($featuresPath);
  36 + $this->featuresPath = $featuresPath;
37 37 $this->gherkin = $gherkin;
38 38 }
39 39

0 comments on commit a851f45

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