Skip to content

Commit

Permalink
Fix findAbsolutePath issues
Browse files Browse the repository at this point in the history
  • Loading branch information
uuf6429 committed Jan 31, 2025
1 parent 79688b6 commit 6969a49
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/Behat/Gherkin/Loader/AbstractFileLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ protected function findRelativePath($path)
*
* @param string $path Relative path
*
* @return string
* @return false|string
*/
protected function findAbsolutePath($path)
{
Expand Down
6 changes: 5 additions & 1 deletion src/Behat/Gherkin/Loader/DirectoryLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ public function __construct(Gherkin $gherkin)
public function supports($resource)
{
return is_string($resource)
&& is_dir($this->findAbsolutePath($resource));
&& ($path = $this->findAbsolutePath($resource)) !== false
&& is_dir($path);
}

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

$iterator = new RecursiveIteratorIterator(
new RecursiveDirectoryIterator($path, RecursiveDirectoryIterator::SKIP_DOTS)
Expand Down
8 changes: 6 additions & 2 deletions src/Behat/Gherkin/Loader/GherkinFileLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,9 @@ public function setCache(CacheInterface $cache)
public function supports($resource)
{
return is_string($resource)
&& is_file($absolute = $this->findAbsolutePath($resource))
&& pathinfo($absolute, PATHINFO_EXTENSION) === 'feature';
&& ($path = $this->findAbsolutePath($resource)) !== false
&& is_file($path)
&& pathinfo($path, PATHINFO_EXTENSION) === 'feature';
}

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

if ($this->cache) {
if ($this->cache->isFresh($path, filemtime($path))) {
Expand Down
8 changes: 6 additions & 2 deletions src/Behat/Gherkin/Loader/YamlFileLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,9 @@ public function __construct()
public function supports($resource)
{
return is_string($resource)
&& is_file($absolute = $this->findAbsolutePath($resource))
&& pathinfo($absolute, PATHINFO_EXTENSION) === 'yml';
&& ($path = $this->findAbsolutePath($resource)) !== false
&& is_file($path)
&& pathinfo($path, PATHINFO_EXTENSION) === 'yml';
}

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

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

0 comments on commit 6969a49

Please sign in to comment.