diff --git a/src/Behat/Gherkin/Keywords/CucumberKeywords.php b/src/Behat/Gherkin/Keywords/CucumberKeywords.php index 045918c4..2a543967 100644 --- a/src/Behat/Gherkin/Keywords/CucumberKeywords.php +++ b/src/Behat/Gherkin/Keywords/CucumberKeywords.php @@ -10,6 +10,7 @@ namespace Behat\Gherkin\Keywords; +use Symfony\Component\Yaml\Exception\ParseException; use Symfony\Component\Yaml\Yaml; /** @@ -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); } /**