|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* This file is part of the Behat Gherkin. |
|
5
|
|
|
* (c) Konstantin Kudryashov <[email protected]> |
|
6
|
|
|
* |
|
7
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
8
|
|
|
* file that was distributed with this source code. |
|
9
|
|
|
*/ |
|
10
|
|
|
|
|
11
|
|
|
namespace Behat\Gherkin\Keywords; |
|
12
|
|
|
|
|
13
|
|
|
use Symfony\Component\Yaml\Exception\ParseException; |
|
14
|
|
|
use Symfony\Component\Yaml\Yaml; |
|
15
|
|
|
|
|
16
|
|
|
/** |
|
17
|
|
|
* Cucumber-translations reader. |
|
18
|
|
|
* |
|
19
|
|
|
* $keywords = new Behat\Gherkin\Keywords\CucumberKeywords($i18nYmlPath); |
|
20
|
|
|
* |
|
21
|
|
|
* @author Konstantin Kudryashov <[email protected]> |
|
22
|
|
|
*/ |
|
23
|
|
|
class CucumberKeywords extends ArrayKeywords |
|
24
|
|
|
{ |
|
25
|
|
|
/** |
|
26
|
|
|
* Initializes holder with yaml string OR file. |
|
27
|
|
|
* |
|
28
|
|
|
* @param string $yaml Yaml string or file path |
|
29
|
|
|
*/ |
|
30
|
5 |
|
public function __construct($yaml) |
|
31
|
|
|
{ |
|
32
|
|
|
// Handle filename explicitly for BC reasons, as Symfony Yaml 3.0 does not do it anymore |
|
33
|
5 |
|
$file = null; |
|
34
|
5 |
|
if (strpos($yaml, "\n") === false && is_file($yaml)) { |
|
35
|
5 |
|
if (false === is_readable($yaml)) { |
|
36
|
|
|
throw new ParseException(sprintf('Unable to parse "%s" as the file is not readable.', $yaml)); |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
5 |
|
$file = $yaml; |
|
40
|
5 |
|
$yaml = file_get_contents($file); |
|
41
|
5 |
|
} |
|
42
|
|
|
|
|
43
|
|
|
try { |
|
44
|
5 |
|
$content = Yaml::parse($yaml); |
|
45
|
5 |
|
} catch (ParseException $e) { |
|
46
|
|
|
if ($file) { |
|
|
|
|
|
|
47
|
|
|
$e->setParsedFile($file); |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
throw $e; |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
5 |
|
parent::__construct($content); |
|
54
|
5 |
|
} |
|
55
|
|
|
|
|
56
|
|
|
/** |
|
57
|
|
|
* Returns Feature keywords (splitted by "|"). |
|
58
|
|
|
* |
|
59
|
|
|
* @return string |
|
60
|
|
|
*/ |
|
61
|
3 |
|
public function getGivenKeywords() |
|
62
|
|
|
{ |
|
63
|
3 |
|
return $this->prepareStepString(parent::getGivenKeywords()); |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
/** |
|
67
|
|
|
* Returns When keywords (splitted by "|"). |
|
68
|
|
|
* |
|
69
|
|
|
* @return string |
|
70
|
|
|
*/ |
|
71
|
3 |
|
public function getWhenKeywords() |
|
72
|
|
|
{ |
|
73
|
3 |
|
return $this->prepareStepString(parent::getWhenKeywords()); |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
/** |
|
77
|
|
|
* Returns Then keywords (splitted by "|"). |
|
78
|
|
|
* |
|
79
|
|
|
* @return string |
|
80
|
|
|
*/ |
|
81
|
3 |
|
public function getThenKeywords() |
|
82
|
|
|
{ |
|
83
|
3 |
|
return $this->prepareStepString(parent::getThenKeywords()); |
|
84
|
|
|
} |
|
85
|
|
|
|
|
86
|
|
|
/** |
|
87
|
|
|
* Returns And keywords (splitted by "|"). |
|
88
|
|
|
* |
|
89
|
|
|
* @return string |
|
90
|
|
|
*/ |
|
91
|
3 |
|
public function getAndKeywords() |
|
92
|
|
|
{ |
|
93
|
3 |
|
return $this->prepareStepString(parent::getAndKeywords()); |
|
94
|
|
|
} |
|
95
|
|
|
|
|
96
|
|
|
/** |
|
97
|
|
|
* Returns But keywords (splitted by "|"). |
|
98
|
|
|
* |
|
99
|
|
|
* @return string |
|
100
|
|
|
*/ |
|
101
|
3 |
|
public function getButKeywords() |
|
102
|
|
|
{ |
|
103
|
3 |
|
return $this->prepareStepString(parent::getButKeywords()); |
|
104
|
|
|
} |
|
105
|
|
|
|
|
106
|
|
|
/** |
|
107
|
|
|
* Trim *| from the begining of the list. |
|
108
|
|
|
* |
|
109
|
|
|
* @param string $keywordsString Keywords string |
|
110
|
|
|
* |
|
111
|
|
|
* @return string |
|
112
|
|
|
*/ |
|
113
|
3 |
|
private function prepareStepString($keywordsString) |
|
114
|
|
|
{ |
|
115
|
3 |
|
if (0 === mb_strpos($keywordsString, '*|', 0, 'UTF-8')) { |
|
116
|
3 |
|
$keywordsString = mb_substr($keywordsString, 2, mb_strlen($keywordsString, 'utf8') - 2, 'utf8'); |
|
117
|
3 |
|
} |
|
118
|
|
|
|
|
119
|
3 |
|
return $keywordsString; |
|
120
|
|
|
} |
|
121
|
|
|
} |
|
122
|
|
|
|
In PHP, under loose comparison (like
==, or!=, orswitchconditions), values of different types might be equal.For
stringvalues, the empty string''is a special case, in particular the following results might be unexpected: