Completed
Pull Request — master (#112)
by Christophe
02:50
created

KeywordsDumperTest   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 263
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 1
Bugs 1 Features 0
Metric Value
c 1
b 1
f 0
dl 0
loc 263
wmc 5
lcom 1
cbo 3
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
B testExtendedVersionDumper() 0 112 1
B setUp() 0 29 1
B testEnKeywordsDumper() 0 36 1
B testRuKeywordsDumper() 0 37 1
B testRuKeywordsCustomKeywordsDumper() 0 40 1
1
<?php
2
3
namespace Tests\Behat\Gherkin\Keywords;
4
5
use Behat\Gherkin\Keywords\ArrayKeywords;
6
use Behat\Gherkin\Keywords\KeywordsDumper;
7
8
class KeywordsDumperTest extends \PHPUnit_Framework_TestCase
9
{
10
    private $keywords;
11
12
    protected function setUp()
13
    {
14
        $this->keywords = new ArrayKeywords(array(
15
           'en' => array(
16
               'feature'          => 'Feature',
17
               'background'       => 'Background',
18
               'scenario'         => 'Scenario',
19
               'scenario_outline' => 'Scenario Outline|Scenario Template',
20
               'examples'         => 'Examples|Scenarios',
21
               'given'            => 'Given',
22
               'when'             => 'When',
23
               'then'             => 'Then',
24
               'and'              => 'And',
25
               'but'              => 'But'
26
           ),
27
           'ru' => array(
28
               'feature'          => 'Функционал|Фича',
29
               'background'       => 'Предыстория|Бэкграунд',
30
               'scenario'         => 'Сценарий|История',
31
               'scenario_outline' => 'Структура сценария|Аутлайн',
32
               'examples'         => 'Значения',
33
               'given'            => 'Допустим',
34
               'when'             => 'Если|@',
35
               'then'             => 'То',
36
               'and'              => 'И',
37
               'but'              => 'Но'
38
           )
39
        ));
40
    }
41
42
    public function testEnKeywordsDumper()
43
    {
44
        $dumper = new KeywordsDumper($this->keywords);
45
46
        $dumped = $dumper->dump('en');
47
        $etalon = <<<GHERKIN
48
Feature: Internal operations
49
  In order to stay secret
50
  As a secret organization
51
  We need to be able to erase past agents' memory
52
53
  Background:
54
    Given there is agent A
55
    And there is agent B
56
57
  Scenario: Erasing agent memory
58
    Given there is agent J
59
    And there is agent K
60
    When I erase agent K's memory
61
    Then there should be agent J
62
    But there should not be agent K
63
64
  (Scenario Outline|Scenario Template): Erasing other agents' memory
65
    Given there is agent <agent1>
66
    And there is agent <agent2>
67
    When I erase agent <agent2>'s memory
68
    Then there should be agent <agent1>
69
    But there should not be agent <agent2>
70
71
    (Examples|Scenarios):
72
      | agent1 | agent2 |
73
      | D      | M      |
74
GHERKIN;
75
76
        $this->assertEquals($etalon, $dumped);
77
    }
78
79
    public function testRuKeywordsDumper()
80
    {
81
        $dumper = new KeywordsDumper($this->keywords);
82
83
        $dumped = $dumper->dump('ru');
84
        $etalon = <<<GHERKIN
85
# language: ru
86
(Функционал|Фича): Internal operations
87
  In order to stay secret
88
  As a secret organization
89
  We need to be able to erase past agents' memory
90
91
  (Предыстория|Бэкграунд):
92
    Допустим there is agent A
93
    И there is agent B
94
95
  (Сценарий|История): Erasing agent memory
96
    Допустим there is agent J
97
    И there is agent K
98
    (Если|@) I erase agent K's memory
99
    То there should be agent J
100
    Но there should not be agent K
101
102
  (Структура сценария|Аутлайн): Erasing other agents' memory
103
    Допустим there is agent <agent1>
104
    И there is agent <agent2>
105
    (Если|@) I erase agent <agent2>'s memory
106
    То there should be agent <agent1>
107
    Но there should not be agent <agent2>
108
109
    Значения:
110
      | agent1 | agent2 |
111
      | D      | M      |
112
GHERKIN;
113
114
        $this->assertEquals($etalon, $dumped);
115
    }
116
117
    public function testRuKeywordsCustomKeywordsDumper()
118
    {
119
        $dumper = new KeywordsDumper($this->keywords);
120
        $dumper->setKeywordsDumperFunction(function ($keywords) {
121
            return '<keyword>'.implode(', ', $keywords).'</keyword>';
122
        });
123
124
        $dumped = $dumper->dump('ru');
125
        $etalon = <<<GHERKIN
126
# language: ru
127
<keyword>Функционал, Фича</keyword>: Internal operations
128
  In order to stay secret
129
  As a secret organization
130
  We need to be able to erase past agents' memory
131
132
  <keyword>Предыстория, Бэкграунд</keyword>:
133
    <keyword>Допустим</keyword> there is agent A
134
    <keyword>И</keyword> there is agent B
135
136
  <keyword>Сценарий, История</keyword>: Erasing agent memory
137
    <keyword>Допустим</keyword> there is agent J
138
    <keyword>И</keyword> there is agent K
139
    <keyword>Если, @</keyword> I erase agent K's memory
140
    <keyword>То</keyword> there should be agent J
141
    <keyword>Но</keyword> there should not be agent K
142
143
  <keyword>Структура сценария, Аутлайн</keyword>: Erasing other agents' memory
144
    <keyword>Допустим</keyword> there is agent <agent1>
145
    <keyword>И</keyword> there is agent <agent2>
146
    <keyword>Если, @</keyword> I erase agent <agent2>'s memory
147
    <keyword>То</keyword> there should be agent <agent1>
148
    <keyword>Но</keyword> there should not be agent <agent2>
149
150
    <keyword>Значения</keyword>:
151
      | agent1 | agent2 |
152
      | D      | M      |
153
GHERKIN;
154
155
        $this->assertEquals($etalon, $dumped);
156
    }
157
158
    public function testExtendedVersionDumper()
159
    {
160
        $dumper = new KeywordsDumper($this->keywords);
161
162
        $dumped = $dumper->dump('ru', false);
163
        $etalon = array(
164
            <<<GHERKIN
165
# language: ru
166
Функционал: Internal operations
167
  In order to stay secret
168
  As a secret organization
169
  We need to be able to erase past agents' memory
170
171
  Предыстория:
172
    Допустим there is agent A
173
    И there is agent B
174
175
  Сценарий: Erasing agent memory
176
    Допустим there is agent J
177
    И there is agent K
178
    Если I erase agent K's memory
179
    @ I erase agent K's memory
180
    То there should be agent J
181
    Но there should not be agent K
182
183
  История: Erasing agent memory
184
    Допустим there is agent J
185
    И there is agent K
186
    Если I erase agent K's memory
187
    @ I erase agent K's memory
188
    То there should be agent J
189
    Но there should not be agent K
190
191
  Структура сценария: Erasing other agents' memory
192
    Допустим there is agent <agent1>
193
    И there is agent <agent2>
194
    Если I erase agent <agent2>'s memory
195
    @ I erase agent <agent2>'s memory
196
    То there should be agent <agent1>
197
    Но there should not be agent <agent2>
198
199
    Значения:
200
      | agent1 | agent2 |
201
      | D      | M      |
202
203
  Аутлайн: Erasing other agents' memory
204
    Допустим there is agent <agent1>
205
    И there is agent <agent2>
206
    Если I erase agent <agent2>'s memory
207
    @ I erase agent <agent2>'s memory
208
    То there should be agent <agent1>
209
    Но there should not be agent <agent2>
210
211
    Значения:
212
      | agent1 | agent2 |
213
      | D      | M      |
214
GHERKIN
215
            , <<<GHERKIN
216
# language: ru
217
Фича: Internal operations
218
  In order to stay secret
219
  As a secret organization
220
  We need to be able to erase past agents' memory
221
222
  Предыстория:
223
    Допустим there is agent A
224
    И there is agent B
225
226
  Сценарий: Erasing agent memory
227
    Допустим there is agent J
228
    И there is agent K
229
    Если I erase agent K's memory
230
    @ I erase agent K's memory
231
    То there should be agent J
232
    Но there should not be agent K
233
234
  История: Erasing agent memory
235
    Допустим there is agent J
236
    И there is agent K
237
    Если I erase agent K's memory
238
    @ I erase agent K's memory
239
    То there should be agent J
240
    Но there should not be agent K
241
242
  Структура сценария: Erasing other agents' memory
243
    Допустим there is agent <agent1>
244
    И there is agent <agent2>
245
    Если I erase agent <agent2>'s memory
246
    @ I erase agent <agent2>'s memory
247
    То there should be agent <agent1>
248
    Но there should not be agent <agent2>
249
250
    Значения:
251
      | agent1 | agent2 |
252
      | D      | M      |
253
254
  Аутлайн: Erasing other agents' memory
255
    Допустим there is agent <agent1>
256
    И there is agent <agent2>
257
    Если I erase agent <agent2>'s memory
258
    @ I erase agent <agent2>'s memory
259
    То there should be agent <agent1>
260
    Но there should not be agent <agent2>
261
262
    Значения:
263
      | agent1 | agent2 |
264
      | D      | M      |
265
GHERKIN
266
        );
267
268
        $this->assertEquals($etalon, $dumped);
269
    }
270
}
271