Skip to content

Commit fd8d1f8

Browse files
committed
Test: Add tests for NoTrailingCommaInSinglelineFixer and array declarations
1 parent 837c3f3 commit fd8d1f8

File tree

3 files changed

+43
-1
lines changed

3 files changed

+43
-1
lines changed

ecs.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@
226226
SetTypeToCastFixer::class,
227227
// Array index should always be written by using square braces
228228
NormalizeIndexBraceFixer::class,
229-
// PHP single-line arrays should not have trailing comma
229+
// Values separated by a comma on a single line should not have a trailing comma.
230230
NoTrailingCommaInSinglelineFixer::class,
231231
// Multi-line arrays, arguments list and parameters list must have a trailing comma
232232
TrailingCommaInMultilineFixer::class,

tests/Integration/Fixtures/Basic.correct.php.inc

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ class Basic
1515
{
1616
// TrimArraySpacesFixer
1717
$fooBar = ['a', 'b'];
18+
// NoTrailingCommaInSinglelineFixer
19+
mb_strlen('foobar');
1820
// MbStrFunctionsFixer
1921
$bazLength = mb_strlen('baz');
2022
// LambdaNotUsedImportFixer
@@ -56,4 +58,23 @@ class Basic
5658
// TernaryToElvisOperatorFixer
5759
return ($foo ?: 'not true');
5860
}
61+
62+
public function arrayDeclarations(): void
63+
{
64+
$empty = [];
65+
66+
$singleLineArray = ['foo', 'bar', 'baz'];
67+
$singleLineArray2 = [1, 2, 3];
68+
69+
$multiLineAssociative = [
70+
'foo' => 'bar',
71+
'baz' => 'bat',
72+
];
73+
74+
$multiLineAssociative2 = [
75+
'firstKey' => 'bar',
76+
'thisIsSecondKey' => 'bat',
77+
'third' => 'bat',
78+
];
79+
}
5980
}

tests/Integration/Fixtures/Basic.wrong.php.inc

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ class Basic
99
{
1010
// TrimArraySpacesFixer
1111
$fooBar = [ 'a', 'b'];
12+
// NoTrailingCommaInSinglelineFixer
13+
mb_strlen('foobar', );
1214
// MbStrFunctionsFixer
1315
$bazLength = strlen('baz');
1416
// LambdaNotUsedImportFixer
@@ -53,4 +55,23 @@ class Basic
5355
protected int $myProperty = 666; // OrderedClassElementsFixer
5456

5557
use SomeUsefulTrait; // OrderedClassElementsFixer
58+
59+
public function arrayDeclarations(): void
60+
{
61+
$empty = array();
62+
63+
$singleLineArray = ['foo', 'bar', 'baz',];
64+
$singleLineArray2 = [1,2,3];
65+
66+
$multiLineAssociative = [
67+
'foo'=>'bar',
68+
'baz'=>'bat'
69+
];
70+
71+
$multiLineAssociative2 = [
72+
'firstKey' => 'bar',
73+
'thisIsSecondKey' => 'bat',
74+
'third' => 'bat',
75+
];
76+
}
5677
}

0 commit comments

Comments
 (0)