Skip to content

Commit 6969a49

Browse files
committed
Fix findAbsolutePath issues
1 parent 79688b6 commit 6969a49

File tree

4 files changed

+18
-6
lines changed

4 files changed

+18
-6
lines changed

src/Behat/Gherkin/Loader/AbstractFileLoader.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ protected function findRelativePath($path)
5050
*
5151
* @param string $path Relative path
5252
*
53-
* @return string
53+
* @return false|string
5454
*/
5555
protected function findAbsolutePath($path)
5656
{

src/Behat/Gherkin/Loader/DirectoryLoader.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,8 @@ public function __construct(Gherkin $gherkin)
4444
public function supports($resource)
4545
{
4646
return is_string($resource)
47-
&& is_dir($this->findAbsolutePath($resource));
47+
&& ($path = $this->findAbsolutePath($resource)) !== false
48+
&& is_dir($path);
4849
}
4950

5051
/**
@@ -57,6 +58,9 @@ public function supports($resource)
5758
public function load($resource)
5859
{
5960
$path = $this->findAbsolutePath($resource);
61+
if ($path === false) {
62+
throw new \LogicException("Unable to locate absolute path of supported resource: $resource");
63+
}
6064

6165
$iterator = new RecursiveIteratorIterator(
6266
new RecursiveDirectoryIterator($path, RecursiveDirectoryIterator::SKIP_DOTS)

src/Behat/Gherkin/Loader/GherkinFileLoader.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,9 @@ public function setCache(CacheInterface $cache)
5656
public function supports($resource)
5757
{
5858
return is_string($resource)
59-
&& is_file($absolute = $this->findAbsolutePath($resource))
60-
&& pathinfo($absolute, PATHINFO_EXTENSION) === 'feature';
59+
&& ($path = $this->findAbsolutePath($resource)) !== false
60+
&& is_file($path)
61+
&& pathinfo($path, PATHINFO_EXTENSION) === 'feature';
6162
}
6263

6364
/**
@@ -70,6 +71,9 @@ public function supports($resource)
7071
public function load($resource)
7172
{
7273
$path = $this->findAbsolutePath($resource);
74+
if ($path === false) {
75+
throw new \LogicException("Unable to locate absolute path of supported resource: $resource");
76+
}
7377

7478
if ($this->cache) {
7579
if ($this->cache->isFresh($path, filemtime($path))) {

src/Behat/Gherkin/Loader/YamlFileLoader.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,9 @@ public function __construct()
3737
public function supports($resource)
3838
{
3939
return is_string($resource)
40-
&& is_file($absolute = $this->findAbsolutePath($resource))
41-
&& pathinfo($absolute, PATHINFO_EXTENSION) === 'yml';
40+
&& ($path = $this->findAbsolutePath($resource)) !== false
41+
&& is_file($path)
42+
&& pathinfo($path, PATHINFO_EXTENSION) === 'yml';
4243
}
4344

4445
/**
@@ -51,6 +52,9 @@ public function supports($resource)
5152
public function load($resource)
5253
{
5354
$path = $this->findAbsolutePath($resource);
55+
if ($path === false) {
56+
throw new \LogicException("Unable to locate absolute path of supported resource: $resource");
57+
}
5458
$hash = Yaml::parse(file_get_contents($path));
5559

5660
$features = $this->loader->load($hash);

0 commit comments

Comments
 (0)