StepTest::testCanFormatStepsToTheRight()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 35

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 35
rs 9.36
c 0
b 0
f 0
cc 1
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\PyStringNode;
22
use Behat\Gherkin\Node\ScenarioNode;
23
use Behat\Gherkin\Node\StepNode;
24
use Behat\Gherkin\Node\TableNode;
25
use KawaiiGherkin\Formatter\Step;
26
use PHPUnit\Framework\TestCase;
27
28
/**
29
 * Tests for {@see \KawaiiGherkin\Formatter\Step}
30
 *
31
 * @author Jefersson Nathan <[email protected]>
32
 * @covers \KawaiiGherkin\Formatter\Step
33
 * @group Coverage
34
 * @license MIT
35
 */
36
final class StepTest extends TestCase
37
{
38
    /**
39
     * @var Step
40
     */
41
    private $formatter;
42
43
    /**
44
     * {@inheritDoc}
45
     */
46
    public function setUp()
47
    {
48
        $this->formatter = new Step();
49
    }
50
51
    public function testCanFormatStepsToTheRight()
52
    {
53
        $expected = <<<EOS
54
        Given I am a Java programmer
55
          And I am not Kawaii
56
         When I start to contribute to a php project:
57
            | project                  |
58
            | malukenho/kawaii-gherkin |
59
         Then I start to love php
60
         When I go to a php events
61
         Then I start to become a Kawaii guy
62
63
EOS;
64
65
        $tableNode  = new TableNode([
66
            ['project'],
67
            ['malukenho/kawaii-gherkin'],
68
        ]);
69
        $scenario = new ScenarioNode(
70
            ' Not all people who program php are becoming kawaii ',
71
            [' kawaii ', ' kawaii-bug-12 '],
72
            [
73
                new StepNode('Given', '       I am a Java programmer ', [], 1, 'Given'),
74
                new StepNode('And', '  I am not Kawaii ', [], 2, 'And'),
75
                new StepNode('When', '  I start to contribute to a php project: ', [$tableNode], 3, 'And'),
76
                new StepNode('Then', '  I start to love php ', [], 4, 'And'),
77
                new StepNode('When', ' I go to a php events ', [], 5, 'And'),
78
                new StepNode('Then', 'I start to become a Kawaii guy ', [], 5, 'And'),
79
            ],
80
            'Scenario',
81
            1
82
        );
83
84
        self::assertSame($expected, $this->formatter->format($scenario->getSteps()));
85
    }
86
87
    public function testCanFormatStepsToTheLeft()
88
    {
89
        $this->formatter = new Step(Step::ALIGN_TO_LEFT);
90
91
        $expected = <<<EOS
92
        Given I am a Java programmer
93
        And I am not Kawaii
94
        When I start to contribute to a php project:
95
            | project                  |
96
            | malukenho/kawaii-gherkin |
97
        Then I start to love php
98
        When I go to a php events
99
        Then I start to become a Kawaii guy
100
101
EOS;
102
103
        $tableNode  = new TableNode([
104
            ['project'],
105
            ['malukenho/kawaii-gherkin'],
106
        ]);
107
        $scenario = new ScenarioNode(
108
            ' Not all people who program php are becoming kawaii ',
109
            [' kawaii ', ' kawaii-bug-12 '],
110
            [
111
                new StepNode('Given', '       I am a Java programmer ', [], 1, 'Given'),
112
                new StepNode('And', '  I am not Kawaii ', [], 2, 'And'),
113
                new StepNode('When', '  I start to contribute to a php project: ', [$tableNode], 3, 'And'),
114
                new StepNode('Then', '  I start to love php ', [], 4, 'And'),
115
                new StepNode('When', ' I go to a php events ', [], 5, 'And'),
116
                new StepNode('Then', 'I start to become a Kawaii guy ', [], 5, 'And'),
117
            ],
118
            'Scenario',
119
            1
120
        );
121
122
        self::assertSame($expected, $this->formatter->format($scenario->getSteps()));
123
    }
124
125
    public function testCanFormatStepsWithPyString()
126
    {
127
        $this->formatter = new Step(Step::ALIGN_TO_LEFT);
128
129
        $expected = <<<EOS
130
        Given I am a Java programmer
131
        And I am not Kawaii
132
        When I start to contribute to a php project:
133
        """
134
          This is a pyString
135
          Multi-line :D
136
137
          Meh... kawaii hu!?
138
        """
139
        Then I start to love php
140
        When I go to a php events
141
        Then I start to become a Kawaii guy
142
143
EOS;
144
145
        $tableNode  = new PyStringNode(
146
            [
147
                'This is a pyString',
148
                'Multi-line :D',
149
                '',
150
                'Meh... kawaii hu!?',
151
            ],
152
            1
153
        );
154
        $scenario = new ScenarioNode(
155
            ' Not all people who program php are becoming kawaii ',
156
            [' kawaii ', ' kawaii-bug-12 '],
157
            [
158
                new StepNode('Given', '       I am a Java programmer ', [], 1, 'Given'),
159
                new StepNode('And', '  I am not Kawaii ', [], 2, 'And'),
160
                new StepNode('When', '  I start to contribute to a php project: ', [$tableNode], 3, 'And'),
161
                new StepNode('Then', '  I start to love php ', [], 4, 'And'),
162
                new StepNode('When', ' I go to a php events ', [], 5, 'And'),
163
                new StepNode('Then', 'I start to become a Kawaii guy ', [], 5, 'And'),
164
            ],
165
            'Scenario',
166
            1
167
        );
168
169
        self::assertSame($expected, $this->formatter->format($scenario->getSteps()));
170
    }
171
}
172