1 | <?php |
||
11 | class BehatVariablesContext implements Context, SnippetAcceptingContext { |
||
12 | |||
13 | protected $lastResult = []; |
||
14 | |||
15 | static protected $storage = array(); |
||
16 | |||
17 | /** |
||
18 | * Initializes context. |
||
19 | */ |
||
20 | public function __construct() { |
||
23 | |||
24 | |||
25 | |||
26 | /** |
||
27 | * @AfterStep |
||
28 | */ |
||
29 | public function afterStep(AfterStepScope $scope) { |
||
43 | |||
44 | /** |
||
45 | * @AfterFeature |
||
46 | */ |
||
47 | static public function afterFeature(AfterFeatureScope $scope) { |
||
50 | |||
51 | |||
52 | |||
53 | /** |
||
54 | * @When /^(?:I|we) save (?:it|that|those|them) into "([\w,]+)"$/ |
||
55 | */ |
||
56 | public function saveItInto($slot) { |
||
57 | if (!$this->lastResult) { |
||
58 | throw new \Exception("Can't store empty return value. Have a step method return a value."); |
||
59 | } |
||
60 | |||
61 | $slots = explode(',', $slot); |
||
62 | if (count($slots) != count($this->lastResult)) { |
||
63 | $slots = count($slots); |
||
64 | $results = count($this->lastResult); |
||
65 | throw new \Exception("Number of slots ($slots) does not match number of last results ($results)."); |
||
66 | } |
||
67 | |||
68 | $valids = array_filter($slots, [BehatVariablesArgumentTransformer::class, 'validSlotName']); |
||
69 | if ($valids !== $slots) { |
||
70 | throw new \Exception("Invalid slot name(s) in '$slot'"); |
||
71 | } |
||
72 | |||
73 | foreach ($slots as $index => $slot) { |
||
74 | $value = $this->lastResult[$index]; |
||
75 | $this->storageSet($slot, $value); |
||
76 | } |
||
77 | |||
78 | $this->lastResult = []; |
||
79 | } |
||
80 | |||
81 | |||
82 | |||
83 | /** |
||
84 | * |
||
85 | */ |
||
86 | protected function storageSet($name, $value) { |
||
94 | |||
95 | /** |
||
96 | * |
||
97 | */ |
||
98 | public function storageGet($name) { |
||
105 | |||
106 | /** |
||
107 | * |
||
108 | */ |
||
109 | static protected function storageClear() { |
||
112 | |||
113 | } |
||
114 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.