Skip to content

Commit

Permalink
Merge pull request #101 from stof/fix_cucumber_keyword
Browse files Browse the repository at this point in the history
Fix the handling of file names in CucumberKeywords
  • Loading branch information
stof committed Dec 31, 2015
2 parents 192e2c9 + cc24fcd commit b945f9b
Showing 1 changed file with 24 additions and 2 deletions.
26 changes: 24 additions & 2 deletions src/Behat/Gherkin/Keywords/CucumberKeywords.php
Expand Up @@ -10,6 +10,7 @@

namespace Behat\Gherkin\Keywords;

use Symfony\Component\Yaml\Exception\ParseException;
use Symfony\Component\Yaml\Yaml;

/**
Expand All @@ -24,11 +25,32 @@ class CucumberKeywords extends ArrayKeywords
/**
* Initializes holder with yaml string OR file.
*
* @param string $yaml Yaml string
* @param string $yaml Yaml string or file path
*/
public function __construct($yaml)
{
parent::__construct(Yaml::parse($yaml));
// Handle filename explicitly for BC reasons, as Symfony Yaml 3.0 does not do it anymore
$file = null;
if (strpos($yaml, "\n") === false && is_file($yaml)) {
if (false === is_readable($yaml)) {
throw new ParseException(sprintf('Unable to parse "%s" as the file is not readable.', $yaml));
}

$file = $yaml;
$yaml = file_get_contents($file);
}

try {
$content = Yaml::parse($yaml);
} catch (ParseException $e) {
if ($file) {
$e->setParsedFile($file);
}

throw $e;
}

parent::__construct($content);
}

/**
Expand Down

0 comments on commit b945f9b

Please sign in to comment.