1
|
|
|
<?php |
2
|
|
|
/* |
3
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
4
|
|
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
5
|
|
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
6
|
|
|
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
7
|
|
|
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
8
|
|
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
9
|
|
|
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
10
|
|
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
11
|
|
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
12
|
|
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
13
|
|
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
14
|
|
|
* |
15
|
|
|
* This software consists of voluntary contributions made by many individuals |
16
|
|
|
* and is licensed under the MIT license. |
17
|
|
|
*/ |
18
|
|
|
|
19
|
|
|
namespace Command; |
20
|
|
|
|
21
|
|
|
use Behat\Gherkin\Node\BackgroundNode; |
22
|
|
|
use Behat\Gherkin\Node\FeatureNode; |
23
|
|
|
use Behat\Gherkin\Node\StepNode; |
24
|
|
|
use Behat\Gherkin\Node\TableNode; |
25
|
|
|
use Behat\Gherkin\Parser; |
26
|
|
|
use KawaiiGherkin\Command\CheckGherkinCodeStyle; |
27
|
|
|
use Symfony\Component\Console\Application; |
28
|
|
|
use Symfony\Component\Console\Tester\CommandTester; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* Tests for {@see \KawaiiGherkin\Command\CheckGherkinCodeStyle} |
32
|
|
|
* |
33
|
|
|
* @author Jefersson Nathan <[email protected]> |
34
|
|
|
* @covers \KawaiiGherkin\Command\CheckGherkinCodeStyle |
35
|
|
|
* @group Coverage |
36
|
|
|
* @license MIT |
37
|
|
|
*/ |
38
|
|
|
final class CheckGherkinCodeStyleTest extends \PHPUnit_Framework_TestCase |
39
|
|
|
{ |
40
|
|
|
public function testShouldReturnOkIfThereIsNoFilesFound() |
41
|
|
|
{ |
42
|
|
|
$kernel = $this->getMock(\stdClass::class); |
43
|
|
|
/* @var \Behat\Gherkin\Parser|\PHPUnit_Framework_MockObject_MockObject $parser */ |
44
|
|
|
$parser = $this->getMockBuilder(Parser::class) |
45
|
|
|
->disableOriginalConstructor() |
46
|
|
|
->getMock(); |
47
|
|
|
|
48
|
|
|
$parser->expects(self::exactly(0)) |
49
|
|
|
->method('parse'); |
50
|
|
|
|
51
|
|
|
$application = new Application($kernel); |
52
|
|
|
$application->add(new CheckGherkinCodeStyle(null, $parser)); |
53
|
|
|
|
54
|
|
|
$command = $application->find('gherkin:check'); |
55
|
|
|
$commandTester = new CommandTester($command); |
56
|
|
|
$commandTester->execute( |
57
|
|
|
[ |
58
|
|
|
'directory' => __DIR__, |
59
|
|
|
] |
60
|
|
|
); |
61
|
|
|
|
62
|
|
|
self::assertRegExp('/Everything is OK!/', $commandTester->getDisplay()); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
public function testShouldReturnErrorIfThereIsFilesWithWrongStyle() |
66
|
|
|
{ |
67
|
|
|
$kernel = $this->getMock(\stdClass::class); |
68
|
|
|
|
69
|
|
|
/* @var \Behat\Gherkin\Parser|\PHPUnit_Framework_MockObject_MockObject $parser */ |
70
|
|
|
$parser = $this->getMockBuilder(Parser::class) |
71
|
|
|
->disableOriginalConstructor() |
72
|
|
|
->getMock(); |
73
|
|
|
|
74
|
|
|
/* @var \Behat\Gherkin\Node\FeatureNode|\PHPUnit_Framework_MockObject_MockObject $feature */ |
75
|
|
|
$feature = $this->getMockBuilder(FeatureNode::class) |
76
|
|
|
->disableOriginalConstructor() |
77
|
|
|
->getMock(); |
78
|
|
|
|
79
|
|
|
$feature->expects(self::once()) |
80
|
|
|
->method('hasTags') |
81
|
|
|
->willReturn(true); |
82
|
|
|
|
83
|
|
|
$feature->expects(self::once()) |
84
|
|
|
->method('getKeyword') |
85
|
|
|
->willReturn('Feature'); |
86
|
|
|
|
87
|
|
|
$feature->expects(self::once()) |
88
|
|
|
->method('getTags') |
89
|
|
|
->willReturn( |
90
|
|
|
['users', 'another-feature', 'another-tag'] |
91
|
|
|
); |
92
|
|
|
|
93
|
|
|
$feature->expects(self::once()) |
94
|
|
|
->method('getTitle') |
95
|
|
|
->willReturn( |
96
|
|
|
'User registration' |
97
|
|
|
); |
98
|
|
|
|
99
|
|
|
$feature->expects(self::once()) |
100
|
|
|
->method('hasDescription') |
101
|
|
|
->willReturn(true); |
102
|
|
|
|
103
|
|
|
$feature->expects(self::once()) |
104
|
|
|
->method('getDescription') |
105
|
|
|
->willReturn( |
106
|
|
|
"In order to order products\n" . |
107
|
|
|
"As a visitor\n" . |
108
|
|
|
"I need to be able to create an account in the store" |
109
|
|
|
); |
110
|
|
|
|
111
|
|
|
$feature->expects(self::once()) |
112
|
|
|
->method('hasBackground') |
113
|
|
|
->willReturn(true); |
114
|
|
|
|
115
|
|
|
$feature->expects(self::once()) |
116
|
|
|
->method('getBackground') |
117
|
|
|
->willReturn($this->getBackground()); |
118
|
|
|
|
119
|
|
|
$feature->expects(self::once()) |
120
|
|
|
->method('hasScenarios') |
121
|
|
|
->willReturn(false); |
122
|
|
|
|
123
|
|
|
$parser->expects(self::once()) |
124
|
|
|
->method('parse') |
125
|
|
|
->willReturn($feature); |
126
|
|
|
|
127
|
|
|
$application = new Application($kernel); |
128
|
|
|
$application->add(new CheckGherkinCodeStyle(null, $parser)); |
129
|
|
|
|
130
|
|
|
$command = $application->find('gherkin:check'); |
131
|
|
|
$commandTester = new CommandTester($command); |
132
|
|
|
$commandTester->execute( |
133
|
|
|
[ |
134
|
|
|
'directory' => __DIR__ . '/../assets/left-aligned.feature', |
135
|
|
|
] |
136
|
|
|
); |
137
|
|
|
|
138
|
|
|
self::assertRegExp('/Wrong style/', $commandTester->getDisplay()); |
139
|
|
|
self::assertNotRegExp('/I need to be able to create an account in the store/', $commandTester->getDisplay()); |
140
|
|
|
} |
141
|
|
|
|
142
|
|
|
/** |
143
|
|
|
* @return BackgroundNode|\PHPUnit_Framework_MockObject_MockObject |
144
|
|
|
*/ |
145
|
|
|
private function getBackground() |
146
|
|
|
{ |
147
|
|
|
/* @var \Behat\Gherkin\Node\BackgroundNode|\PHPUnit_Framework_MockObject_MockObject $background */ |
148
|
|
|
$background = $this->getMockBuilder(BackgroundNode::class) |
149
|
|
|
->disableOriginalConstructor() |
150
|
|
|
->getMock(); |
151
|
|
|
|
152
|
|
|
$background->expects(self::once()) |
153
|
|
|
->method('getKeyword') |
154
|
|
|
->willReturn('Background'); |
155
|
|
|
|
156
|
|
|
$background->expects(self::once()) |
157
|
|
|
->method('getTitle') |
158
|
|
|
->willReturn('Nice Background'); |
159
|
|
|
|
160
|
|
|
$background->expects(self::once()) |
161
|
|
|
->method('getSteps') |
162
|
|
|
->willReturn([ |
163
|
|
|
new StepNode('Given', 'store has default configuration', [], 1), |
164
|
|
|
new StepNode('And', 'there are following users:', [new TableNode([['email', 'password'], ['[email protected]', 'foo1sasdasdasdadsasd']])], 2) |
165
|
|
|
]); |
166
|
|
|
|
167
|
|
|
return $background; |
168
|
|
|
} |
169
|
|
|
} |
170
|
|
|
|