-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
/
SemicolonAfterInstructionFixerTest.php
113 lines (103 loc) · 2.61 KB
/
SemicolonAfterInstructionFixerTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
<?php
declare(strict_types=1);
/*
* This file is part of PHP CS Fixer.
*
* (c) Fabien Potencier <fabien@symfony.com>
* Dariusz Rumiński <dariusz.ruminski@gmail.com>
*
* This source file is subject to the MIT license that is bundled
* with this source code in the file LICENSE.
*/
namespace PhpCsFixer\Tests\Fixer\Semicolon;
use PhpCsFixer\Tests\Test\AbstractFixerTestCase;
/**
* @internal
*
* @covers \PhpCsFixer\Fixer\Semicolon\SemicolonAfterInstructionFixer
*/
final class SemicolonAfterInstructionFixerTest extends AbstractFixerTestCase
{
/**
* @dataProvider provideFixCases
*/
public function testFix(string $expected, ?string $input = null): void
{
$this->doTest($expected, $input);
}
public function provideFixCases(): \Generator
{
yield from [
'comment' => [
'<?php $a++;//a ?>',
'<?php $a++//a ?>',
],
'comment II' => [
'<?php $b++; /**/ ?>',
'<?php $b++ /**/ ?>',
],
'no space' => [
'<?php $b++;?>',
'<?php $b++?>',
],
[
'<?php echo 123; ?>',
'<?php echo 123 ?>',
],
[
"<?php echo 123;\n\t?>",
"<?php echo 123\n\t?>",
],
['<?php ?>'],
['<?php ; ?>'],
['<?php if($a){}'],
['<?php while($a > $b){}'],
[
'<?php if ($a == 5): ?>
A is equal to 5
<?php endif; ?>
<?php switch ($foo): ?>
<?php case 1: ?>
...
<?php endswitch; ?>',
'<?php if ($a == 5): ?>
A is equal to 5
<?php endif; ?>
<?php switch ($foo): ?>
<?php case 1: ?>
...
<?php endswitch ?>',
],
[
'<?php if ($a == 5) { ?>
A is equal to 5
<?php } ?>',
],
];
}
/**
* @dataProvider provideFixPre80Cases
* @requires PHP <8.0
*/
public function testFixPre80(string $expected, string $input = null): void
{
$this->doTest($expected, $input);
}
public function provideFixPre80Cases(): \Generator
{
yield [
'<?php $a = [1,2,3]; echo $a{1}; ?>',
'<?php $a = [1,2,3]; echo $a{1} ?>',
];
}
public function testOpenWithEcho(): void
{
if (!\ini_get('short_open_tag')) {
static::markTestSkipped('The short_open_tag option is required to be enabled.');
}
$this->doTest(
"<?= '1_'; ?> <?php ?><?= 1; ?>",
"<?= '1_' ?> <?php ?><?= 1; ?>"
);
}
}