Completed
Pull Request — master (#1)
by Jefersson
03:34 queued 39s
created

testShouldReturnVoidIfThereIsNoStepOnScenario()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 17
Code Lines 9

Duplication

Lines 0
Ratio 0 %
Metric Value
dl 0
loc 17
rs 9.4285
cc 1
eloc 9
nc 1
nop 0
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 KawaiiGherkinTest\Formatter;
20
21
use Behat\Gherkin\Node\ExampleTableNode;
22
use Behat\Gherkin\Node\OutlineNode;
23
use Behat\Gherkin\Node\ScenarioNode;
24
use Behat\Gherkin\Node\StepNode;
25
use Behat\Gherkin\Node\TableNode;
26
use KawaiiGherkin\Formatter\Scenario;
27
28
/**
29
 * Tests for {@see \KawaiiGherkin\Formatter\Scenario}
30
 *
31
 * @author Jefersson Nathan <[email protected]>
32
 * @covers \KawaiiGherkin\Formatter\Scenario
33
 * @group Coverage
34
 * @license MIT
35
*/
36
final class ScenarioTest extends \PHPUnit_Framework_TestCase
37
{
38
    /**
39
     * @var Scenario
40
     */
41
    private $formatter;
42
43
    /**
44
     * {@inheritDoc}
45
     */
46
    public function setUp()
47
    {
48
        $this->formatter = new Scenario();
49
    }
50
51
    public function testCanFormatFeatureDescription()
52
    {
53
        $expected = <<<EOS
54
    @kawaii @kawaii-bug-12
55
    Scenario: Not all people who program php are becoming kawaii
56
        Given I am a Java programmer
57
          And I am not Kawaii
58
         When I start to contribute to a php project:
59
            | project                  |
60
            | malukenho/kawaii-gherkin |
61
         Then I start to love php
62
         When I go to a php events
63
         Then I start to become a Kawaii guy
64
65
EOS;
66
67
        $tableNode  = new TableNode([
68
            ['project'],
69
            ['malukenho/kawaii-gherkin'],
70
        ]);
71
        $scenario = new ScenarioNode(
72
            ' Not all people who program php are becoming kawaii ',
73
            [' kawaii ', ' kawaii-bug-12 '],
74
            [
75
                new StepNode('Given', '       I am a Java programmer ', [], 1, 'Given'),
76
                new StepNode('And', '  I am not Kawaii ', [], 2, 'And'),
77
                new StepNode('When', '  I start to contribute to a php project: ', [$tableNode], 3, 'And'),
78
                new StepNode('Then', '  I start to love php ', [], 4, 'And'),
79
                new StepNode('When', ' I go to a php events ', [], 5, 'And'),
80
                new StepNode('Then', 'I start to become a Kawaii guy ', [], 5, 'And'),
81
            ],
82
            'Scenario',
83
            1
84
        );
85
86
        self::assertSame($expected, $this->formatter->format([$scenario]));
87
    }
88
89
    public function testCanFormatScenarioWithoutTags()
90
    {
91
        $expected = <<<EOS
92
    Scenario: Not all people who program php are becoming kawaii
93
        Given I am a Java programmer
94
          And I am not Kawaii
95
96
EOS;
97
98
        $scenario = new ScenarioNode(
99
            ' Not all people who program php are becoming kawaii ',
100
            [],
101
            [
102
                new StepNode('Given', '       I am a Java programmer ', [], 1, 'Given'),
103
                new StepNode('And', '  I am not Kawaii ', [], 2, 'And'),
104
            ],
105
            'Scenario',
106
            1
107
        );
108
109
        self::assertSame($expected, $this->formatter->format([$scenario]));
110
    }
111
112
    public function testCanFormatMultiLineDescription()
113
    {
114
        $expected = <<<EOS
115
    Scenario: Not all people who program php
116
            are becoming kawaii
117
            person
118
            :'(
119
        Given I am a Java programmer
120
          And I am not Kawaii
121
122
EOS;
123
124
        $scenario = new ScenarioNode(
125
            " Not all people who program php \n        are becoming kawaii \n person \n :'(",
126
            [],
127
            [
128
                new StepNode('Given', '       I am a Java programmer ', [], 1, 'Given'),
129
                new StepNode('And', '  I am not Kawaii ', [], 2, 'And'),
130
            ],
131
            'Scenario',
132
            1
133
        );
134
135
        self::assertSame($expected, $this->formatter->format([$scenario]));
136
    }
137
138
    public function testShouldReturnVoidIfThereIsNoStepOnScenario()
139
    {
140
        $expected = <<<EOS
141
    Scenario: This scenario has no steps
142
143
EOS;
144
145
        $scenario = new ScenarioNode(
146
            "This scenario has no steps",
147
            [],
148
            [],
149
            'Scenario',
150
            1
151
        );
152
153
        self::assertSame($expected, $this->formatter->format([$scenario]));
154
    }
155
156
157
    public function testShouldCallExampleFormatterWhenExamplesIsProvided()
158
    {
159
        $expected = <<<EOS
160
    Scenario: Working a lot
161
         When I am working for <number> hours
162
         Then I have to be upset
163
164
        Examples:
165
          | number |
166
          | 10     |
167
          | 12     |
168
169
EOS;
170
171
        $scenario = new OutlineNode(
172
            "Working a lot",
173
            [],
174
            [
175
                new StepNode('When', 'I am working for <number> hours', [], 1, 'When'),
176
                new StepNode('Then', 'I have to be upset', [], 2, 'Then'),
177
            ],
178
            new ExampleTableNode([['number'], ['10'], ['12']], 'Examples'),
179
            'Scenario',
180
            1
181
        );
182
183
        self::assertSame($expected, $this->formatter->format([$scenario]));
184
    }
185
}
186