Code Duplication    Length = 129-136 lines in 3 locations

tests/unit/Whitespace/BlankLineBeforeCatchBlockFixerTest.php 1 location

@@ 23-158 (lines=136) @@
20
/**
21
 * @internal
22
 */
23
final class BlankLineBeforeCatchBlockFixerTest extends AbstractFixerTestCase
24
{
25
    /**
26
     * @param string      $expected
27
     * @param null|string $input
28
     *
29
     * @dataProvider provideFixCases
30
     */
31
    public function testFix($expected, $input = null)
32
    {
33
        $this->doTest($expected, $input);
34
    }
35
36
    public function provideFixCases()
37
    {
38
        return [
39
            [
40
                '<?php
41
try {
42
    foo();
43
44
} catch (\Exception $b) {
45
    bar();
46
47
} finally {
48
    baz();
49
}',
50
            ],
51
            [
52
                '<?php
53
try {
54
    foo();
55
56
} catch (\Exception $b) {
57
    bar();
58
59
} finally {
60
    baz();
61
}',
62
                '<?php
63
try {
64
    foo();
65
} catch (\Exception $b) {
66
    bar();
67
} finally {
68
    baz();
69
}',
70
            ],
71
            [
72
                '<?php
73
    try {
74
        foo();
75
76
    } catch (\Exception $b) {
77
        bar();
78
79
    } finally {
80
        baz();
81
    }',
82
                '<?php
83
    try {
84
        foo();
85
    } catch (\Exception $b) {
86
        bar();
87
    } finally {
88
        baz();
89
    }',
90
            ],
91
            [
92
                '<?php
93
try {
94
    foo();
95
96
/* Lorem ipsum */} catch (\Exception $b) {
97
    bar();
98
99
} finally {
100
    baz();
101
}',
102
                '<?php
103
try {
104
    foo();
105
/* Lorem ipsum */} catch (\Exception $b) {
106
    bar();
107
} finally {
108
    baz();
109
}',
110
            ],
111
            [
112
                '<?php try {foo();} catch (\Exception $b) {bar();} finally {baz();}',
113
            ],
114
        ];
115
    }
116
117
    /**
118
     * @test
119
     */
120
    public function shouldHaveTheRightPriority()
121
    {
122
        $this->assertEquals(-26, $this->createFixer()->getPriority());
123
    }
124
125
    /**
126
     * @test
127
     */
128
    public function shouldHaveAFixerDefinition()
129
    {
130
        $this->assertEquals(
131
            new FixerDefinition(
132
                'An empty line feed must precede any catch or finally codeblock.',
133
                [
134
                    new CodeSample(
135
                        '<?php
136
try {
137
    foo();
138
139
} catch (\Exception $b) {
140
    bar();
141
142
} finally {
143
    baz();
144
}
145
'
146
                    ),
147
                ]
148
            ),
149
            $this->createFixer()->getDefinition()
150
        );
151
    }
152
153
    protected function createFixer()
154
    {
155
        return new BlankLineBeforeCatchBlockFixer();
156
    }
157
158
}
159

tests/unit/Whitespace/BlankLineBeforeElseBlockFixerTest.php 1 location

@@ 23-158 (lines=136) @@
20
/**
21
 * @internal
22
 */
23
final class BlankLineBeforeElseBlockFixerTest extends AbstractFixerTestCase
24
{
25
    /**
26
     * @param string      $expected
27
     * @param null|string $input
28
     *
29
     * @dataProvider provideFixCases
30
     */
31
    public function testFix($expected, $input = null)
32
    {
33
        $this->doTest($expected, $input);
34
    }
35
36
    public function provideFixCases()
37
    {
38
        return [
39
            [
40
                '<?php
41
if ($a) {
42
    foo();
43
44
} elseif ($b) {
45
    bar();
46
47
} else {
48
    baz();
49
}',
50
            ],
51
            [
52
                '<?php
53
if ($a) {
54
    foo();
55
56
} elseif ($b) {
57
    bar();
58
59
} else {
60
    baz();
61
}',
62
                '<?php
63
if ($a) {
64
    foo();
65
} elseif ($b) {
66
    bar();
67
} else {
68
    baz();
69
}',
70
            ],
71
            [
72
                '<?php
73
    if ($a) {
74
        foo();
75
76
    } elseif ($b) {
77
        bar();
78
79
    } else {
80
        baz();
81
    }',
82
                '<?php
83
    if ($a) {
84
        foo();
85
    } elseif ($b) {
86
        bar();
87
    } else {
88
        baz();
89
    }',
90
            ],
91
            [
92
                '<?php
93
if ($a) {
94
    foo();
95
96
/* Lorem ipsum */} elseif ($b) {
97
    bar();
98
99
} else {
100
    baz();
101
}',
102
                '<?php
103
if ($a) {
104
    foo();
105
/* Lorem ipsum */} elseif ($b) {
106
    bar();
107
} else {
108
    baz();
109
}',
110
            ],
111
            [
112
                '<?php if ($a) {foo();} elseif ($b) {bar();} else {baz();}',
113
            ],
114
        ];
115
    }
116
117
    /**
118
     * @test
119
     */
120
    public function shouldHaveAFixerDefinition()
121
    {
122
        $this->assertEquals(
123
            new FixerDefinition(
124
                'An empty line feed must precede any else or elseif codeblock.',
125
                [
126
                    new CodeSample(
127
                        '<?php
128
if ($a) {
129
    foo();
130
131
} elseif ($b) {
132
    bar();
133
134
} else {
135
    baz();
136
}
137
'
138
                    ),
139
                ]
140
            ),
141
            $this->createFixer()->getDefinition()
142
        );
143
    }
144
145
    /**
146
     * @test
147
     */
148
    public function shouldHaveTheRightPriority()
149
    {
150
        $this->assertEquals(-26, $this->createFixer()->getPriority());
151
    }
152
153
    protected function createFixer()
154
    {
155
        return new BlankLineBeforeElseBlockFixer();
156
    }
157
158
}
159

tests/unit/Whitespace/BlankLineBeforeDocCommentFixerTest.php 1 location

@@ 23-151 (lines=129) @@
20
/**
21
 * @internal
22
 */
23
final class BlankLineBeforeDocCommentFixerTest extends AbstractFixerTestCase
24
{
25
    /**
26
     * @param string      $expected
27
     * @param null|string $input
28
     *
29
     * @dataProvider provideFixCases
30
     */
31
    public function testFix($expected, $input = null)
32
    {
33
        $this->doTest($expected, $input);
34
    }
35
36
    public function provideFixCases()
37
    {
38
        return [
39
            [
40
                '<?php
41
/** @var string $foo */
42
$foo = "Lorem ipsum";
43
44
/** @var string $bar */
45
$bar = "dolor sit";
46
47
/** @var string $baz */
48
$baz = "amet";
49
',
50
            ],
51
            [
52
                '<?php
53
/** @var string $foo */
54
$foo = "Lorem ipsum";
55
56
/** @var string $bar */
57
$bar = "dolor sit";
58
59
/** @var string $baz */
60
$baz = "amet";
61
',
62
                '<?php
63
/** @var string $foo */
64
$foo = "Lorem ipsum";
65
/** @var string $bar */
66
$bar = "dolor sit";
67
/** @var string $baz */
68
$baz = "amet";
69
',
70
            ],
71
            [
72
                '<?php
73
    /** @var string $foo */
74
    $foo = "Lorem ipsum";
75
76
    /** @var string $bar */
77
    $bar = "dolor sit";
78
79
    /** @var string $baz */
80
    $baz = "amet";
81
    ',
82
                '<?php
83
    /** @var string $foo */
84
    $foo = "Lorem ipsum";
85
    /** @var string $bar */
86
    $bar = "dolor sit";
87
    /** @var string $baz */
88
    $baz = "amet";
89
    ',
90
            ],
91
            [
92
                '<?php
93
function foo() {
94
    /** @var string $foo */
95
    $foo = "Lorem ipsum";
96
97
    /** @var string $bar */
98
    $bar = "dolor sit";
99
}
100
',
101
                '<?php
102
function foo() {
103
    /** @var string $foo */
104
    $foo = "Lorem ipsum";
105
    /** @var string $bar */
106
    $bar = "dolor sit";
107
}
108
',
109
            ],
110
        ];
111
    }
112
113
    /**
114
     * @test
115
     */
116
    public function shouldHaveAFixerDefinition()
117
    {
118
        $this->assertEquals(
119
            new FixerDefinition(
120
                'An empty line feed must precede any doc-comment.',
121
                [
122
                    new CodeSample(
123
                        '<?php
124
125
/** @var string $foo */
126
$foo = "Lorem ipsum";
127
128
/** @var string $bar */
129
$bar = "dolor sit amet";
130
'
131
                    ),
132
                ]
133
            ),
134
            $this->createFixer()->getDefinition()
135
        );
136
    }
137
138
    /**
139
     * @test
140
     */
141
    public function shouldHaveTheRightPriority()
142
    {
143
        $this->assertEquals(-26, $this->createFixer()->getPriority());
144
    }
145
146
    protected function createFixer()
147
    {
148
        return new BlankLineBeforeDocCommentFixer();
149
    }
150
151
}
152