Skip to content

Commit

Permalink
Test: Add tests for NoTrailingCommaInSinglelineFixer and array declar…
Browse files Browse the repository at this point in the history
…ations
  • Loading branch information
OndraM committed May 6, 2024
1 parent 71ec88b commit 75c1154
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 1 deletion.
2 changes: 1 addition & 1 deletion ecs.php
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@
SetTypeToCastFixer::class,
// Array index should always be written by using square braces
NormalizeIndexBraceFixer::class,
// PHP single-line arrays should not have trailing comma
// Values separated by a comma on a single line should not have a trailing comma.
NoTrailingCommaInSinglelineFixer::class,
// Multi-line arrays, arguments list and parameters list must have a trailing comma
TrailingCommaInMultilineFixer::class,
Expand Down
21 changes: 21 additions & 0 deletions tests/Integration/Fixtures/Basic.correct.php.inc
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ class Basic
{
// TrimArraySpacesFixer
$fooBar = ['a', 'b'];
// NoTrailingCommaInSinglelineFixer
mb_strlen('foobar');
// MbStrFunctionsFixer
$bazLength = mb_strlen('baz');
// LambdaNotUsedImportFixer
Expand Down Expand Up @@ -54,4 +56,23 @@ class Basic
// TernaryToElvisOperatorFixer
return ($foo ?: 'not true');
}

public function arrayDeclarations(): void
{
$empty = [];

$singleLineArray = ['foo', 'bar', 'baz'];
$singleLineArray2 = [1, 2, 3];

$multiLineAssociative = [
'foo' => 'bar',
'baz' => 'bat',
];

$multiLineAssociative2 = [
'firstKey' => 'bar',
'thisIsSecondKey' => 'bat',
'third' => 'bat',
];
}
}
21 changes: 21 additions & 0 deletions tests/Integration/Fixtures/Basic.wrong.php.inc
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ class Basic
{
// TrimArraySpacesFixer
$fooBar = [ 'a', 'b'];
// NoTrailingCommaInSinglelineFixer
mb_strlen('foobar', );
// MbStrFunctionsFixer
$bazLength = strlen('baz');
// LambdaNotUsedImportFixer
Expand Down Expand Up @@ -51,4 +53,23 @@ class Basic
protected int $myProperty = 666; // OrderedClassElementsFixer

use SomeUsefulTrait; // OrderedClassElementsFixer

public function arrayDeclarations(): void
{
$empty = array();

$singleLineArray = ['foo', 'bar', 'baz',];
$singleLineArray2 = [1,2,3];

$multiLineAssociative = [
'foo'=>'bar',
'baz'=>'bat'
];

$multiLineAssociative2 = [
'firstKey' => 'bar',
'thisIsSecondKey' => 'bat',
'third' => 'bat',
];
}
}

0 comments on commit 75c1154

Please sign in to comment.