Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions blink/internal/fixer/rules/add_missing_param_name_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import "testing"

// TestAddMissingParamName adds the positional variable name to a type-only @param.
func TestAddMissingParamName(t *testing.T) {
t.Parallel()
src := "<?php\nclass A {\n /**\n * @param string\n */\n function f($name) {}\n}\n"
want := "<?php\nclass A {\n /**\n * @param string $name\n */\n function f($name) {}\n}\n"
got, changed := apply(t, AddMissingParamName{}, src)
Expand All @@ -16,6 +17,7 @@ func TestAddMissingParamName(t *testing.T) {
// TestAddMissingParamNameMultiLineArrayShape leaves a @param whose multi-line
// array-shape type already carries its name after the closing brace untouched.
func TestAddMissingParamNameMultiLineArrayShape(t *testing.T) {
t.Parallel()
src := "<?php\nclass A {\n /**\n * @param array{\n * timed: list<array{category: array{label: string}, lines: list<string>}>,\n * timeless: list<array{category: array{label: string}, lines: list<string>}>\n * } $messages\n */\n function f(array $messages) {}\n}\n"
if got, changed := apply(t, AddMissingParamName{}, src); changed || got != src {
t.Fatalf("multi-line array-shape param with name must be left alone: changed=%v got=%q", changed, got)
Expand Down
1 change: 1 addition & 0 deletions blink/internal/fixer/rules/array_indentation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package rules
import "testing"

func TestArrayIndentation(t *testing.T) {
t.Parallel()
f := ArrayIndentation{}

// nested array under-indented: each level indented exactly once
Expand Down
1 change: 1 addition & 0 deletions blink/internal/fixer/rules/array_list_item_newline_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package rules
import "testing"

func TestArrayListItemNewline(t *testing.T) {
t.Parallel()
f := ArrayListItemNewline{}

// associative single-line array -> one item per line, trailing comma, [] on own lines
Expand Down
1 change: 1 addition & 0 deletions blink/internal/fixer/rules/array_notation_config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package rules
import "testing"

func TestArrayNotationConfigCases(t *testing.T) {
t.Parallel()
cases := []struct {
name string
rule fixerRule
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package rules
import "testing"

func TestArrayOpenerAndCloserNewline(t *testing.T) {
t.Parallel()
f := ArrayOpenerAndCloserNewline{}

// associative array: "[" and "]" go on their own lines, items untouched
Expand Down
9 changes: 9 additions & 0 deletions blink/internal/fixer/rules/batch10_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package rules
import "testing"

func TestTrailingCommaInMultiline(t *testing.T) {
t.Parallel()
got, changed := apply(t, TrailingCommaInMultiline{}, "<?php $a = [\n 1,\n 2\n];")
if want := "<?php $a = [\n 1,\n 2,\n];"; !changed || got != want {
t.Fatalf("changed=%v got=%q want=%q", changed, got, want)
Expand All @@ -21,6 +22,7 @@ func TestTrailingCommaInMultiline(t *testing.T) {
}

func TestNoTrailingCommaInSingleline(t *testing.T) {
t.Parallel()
got, changed := apply(t, NoTrailingCommaInSingleline{}, "<?php $a = [1, 2,]; foo(1,);")
if want := "<?php $a = [1, 2]; foo(1);"; !changed || got != want {
t.Fatalf("changed=%v got=%q want=%q", changed, got, want)
Expand All @@ -32,6 +34,7 @@ func TestNoTrailingCommaInSingleline(t *testing.T) {
}

func TestNoSpacesAroundOffset(t *testing.T) {
t.Parallel()
got, changed := apply(t, NoSpacesAroundOffset{}, "<?php echo $a[ 0 ][ 'k' ];")
if want := "<?php echo $a[0]['k'];"; !changed || got != want {
t.Fatalf("changed=%v got=%q want=%q", changed, got, want)
Expand All @@ -43,13 +46,15 @@ func TestNoSpacesAroundOffset(t *testing.T) {
}

func TestObjectOperatorWithoutWhitespace(t *testing.T) {
t.Parallel()
got, changed := apply(t, ObjectOperatorWithoutWhitespace{}, "<?php $a -> b -> c();")
if want := "<?php $a->b->c();"; !changed || got != want {
t.Fatalf("changed=%v got=%q want=%q", changed, got, want)
}
}

func TestNativeFunctionCasing(t *testing.T) {
t.Parallel()
got, changed := apply(t, NativeFunctionCasing{}, "<?php echo STRLEN($x) . Count($y);")
if want := "<?php echo strlen($x) . count($y);"; !changed || got != want {
t.Fatalf("changed=%v got=%q want=%q", changed, got, want)
Expand All @@ -61,6 +66,7 @@ func TestNativeFunctionCasing(t *testing.T) {
}

func TestIntegerLiteralCase(t *testing.T) {
t.Parallel()
got, changed := apply(t, IntegerLiteralCase{}, "<?php $a = 0XFF; $b = 0B101;")
if want := "<?php $a = 0xFF; $b = 0b101;"; !changed || got != want {
t.Fatalf("changed=%v got=%q want=%q", changed, got, want)
Expand All @@ -71,6 +77,7 @@ func TestIntegerLiteralCase(t *testing.T) {
}

func TestNoEmptyComment(t *testing.T) {
t.Parallel()
got, changed := apply(t, NoEmptyComment{}, "<?php //\n$a = 1; /* */")
if want := "<?php \n$a = 1; "; !changed || got != want {
t.Fatalf("changed=%v got=%q want=%q", changed, got, want)
Expand All @@ -82,6 +89,7 @@ func TestNoEmptyComment(t *testing.T) {
}

func TestSingleLineCommentSpacing(t *testing.T) {
t.Parallel()
got, changed := apply(t, SingleLineCommentSpacing{}, "<?php //foo\n#bar")
if want := "<?php // foo\n# bar"; !changed || got != want {
t.Fatalf("changed=%v got=%q want=%q", changed, got, want)
Expand All @@ -92,6 +100,7 @@ func TestSingleLineCommentSpacing(t *testing.T) {
}

func TestNoUnusedImports(t *testing.T) {
t.Parallel()
got, changed := apply(t, NoUnusedImports{}, "<?php\nuse App\\Used;\nuse App\\Unused;\n\n$x = new Used();\n")
if want := "<?php\nuse App\\Used;\n\n$x = new Used();\n"; !changed || got != want {
t.Fatalf("changed=%v got=%q want=%q", changed, got, want)
Expand Down
5 changes: 5 additions & 0 deletions blink/internal/fixer/rules/batchA_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package rules
import "testing"

func TestLinebreakAfterOpeningTag(t *testing.T) {
t.Parallel()
got, changed := apply(t, LinebreakAfterOpeningTag{}, "<?php $a = 1;\necho $a;\n")
if want := "<?php\n$a = 1;\necho $a;\n"; !changed || got != want {
t.Fatalf("changed=%v got=%q want=%q", changed, got, want)
Expand All @@ -18,6 +19,7 @@ func TestLinebreakAfterOpeningTag(t *testing.T) {
}

func TestNullableTypeDeclaration(t *testing.T) {
t.Parallel()
got, changed := apply(t, NullableTypeDeclaration{}, "<?php function a(int|null $x): string|null {}")
if want := "<?php function a(?int $x): ?string {}"; !changed || got != want {
t.Fatalf("changed=%v got=%q want=%q", changed, got, want)
Expand All @@ -38,6 +40,7 @@ func TestNullableTypeDeclaration(t *testing.T) {
}

func TestOrderedTypes(t *testing.T) {
t.Parallel()
got, changed := apply(t, OrderedTypes{}, "<?php function a(): B|A {}")
if want := "<?php function a(): A|B {}"; !changed || got != want {
t.Fatalf("return: changed=%v got=%q want=%q", changed, got, want)
Expand All @@ -59,6 +62,7 @@ func TestOrderedTypes(t *testing.T) {
}

func TestOrderedTypesConfig(t *testing.T) {
t.Parallel()
// sort_algorithm=none keeps source order; null_adjustment=always_last moves null last
cfg := map[string]any{"sort_algorithm": "none", "null_adjustment": "always_last"}
keep := OrderedTypes{}.WithConfig(cfg).(fixerRule)
Expand All @@ -72,6 +76,7 @@ func TestOrderedTypesConfig(t *testing.T) {
}

func TestMethodChainingIndentation(t *testing.T) {
t.Parallel()
got, changed := apply(t, MethodChainingIndentation{}, "<?php\n$x = $obj->foo()\n->bar()\n ->baz();\n")
if want := "<?php\n$x = $obj->foo()\n ->bar()\n ->baz();\n"; !changed || got != want {
t.Fatalf("changed=%v got=%q want=%q", changed, got, want)
Expand Down
1 change: 1 addition & 0 deletions blink/internal/fixer/rules/batchD_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package rules
import "testing"

func TestSimplifiedNullReturn(t *testing.T) {
t.Parallel()
// no return type -> simplified
got, changed := apply(t, SimplifiedNullReturn{}, "<?php function a() {\n return null;\n}")
if want := "<?php function a() {\n return;\n}"; !changed || got != want {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package rules
import "testing"

func TestBinaryOperatorSpacesConfigCases(t *testing.T) {
t.Parallel()
cases := []struct {
name string
rule fixerRule
Expand Down
1 change: 1 addition & 0 deletions blink/internal/fixer/rules/blank_lines_config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package rules
import "testing"

func TestNoExtraBlankLinesConfig(t *testing.T) {
t.Parallel()
// default: collapse runs of blank lines only
got, changed := apply(t, NoExtraBlankLines{}, "<?php\n$a = 1;\n\n\n\n$b = 2;\n")
if want := "<?php\n$a = 1;\n\n$b = 2;\n"; !changed || got != want {
Expand Down
1 change: 1 addition & 0 deletions blink/internal/fixer/rules/braces_position_config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package rules
import "testing"

func TestBracesPositionConfig(t *testing.T) {
t.Parallel()
// default: a class body brace moves to the next line
got, changed := apply(t, BracesPosition{}, "<?php\nclass A {\n public $x;\n}\n")
if want := "<?php\nclass A\n{\n public $x;\n}\n"; !changed || got != want {
Expand Down
6 changes: 6 additions & 0 deletions blink/internal/fixer/rules/braces_position_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ func firstBrace(s *tokens.Stream) int {
}

func TestBracesPositionClassAndFunction(t *testing.T) {
t.Parallel()
got, changed := apply(t, BracesPosition{}, "<?php class A {\n public function run() {\n return 1;\n }\n}")
want := "<?php class A\n{\n public function run()\n {\n return 1;\n }\n}"
if !changed || got != want {
Expand All @@ -31,6 +32,7 @@ func TestBracesPositionClassAndFunction(t *testing.T) {
}

func TestBracesPositionControl(t *testing.T) {
t.Parallel()
got, changed := apply(t, BracesPosition{}, "<?php if ($a)\n{\n}\nwhile ($b){\n}")
want := "<?php if ($a) {\n}\nwhile ($b) {\n}"
if !changed || got != want {
Expand All @@ -39,19 +41,22 @@ func TestBracesPositionControl(t *testing.T) {
}

func TestBracesPositionClosureLeftAlone(t *testing.T) {
t.Parallel()
if _, changed := apply(t, BracesPosition{}, "<?php $f = function () {\n};"); changed {
t.Fatal("closure brace must not move")
}
}

func TestBracesPositionDynamicAccessLeftAlone(t *testing.T) {
t.Parallel()
// "->{$prop}" is dynamic access, not a control block: no space inserted
if _, changed := apply(t, BracesPosition{}, "<?php if ($this->{$prop} != $v) {\n}"); changed {
t.Fatal("dynamic property access brace must not get a space")
}
}

func TestClassifyBrace(t *testing.T) {
t.Parallel()
cases := []struct {
src string
want braceKind
Expand Down Expand Up @@ -80,6 +85,7 @@ func TestClassifyBrace(t *testing.T) {

// a trait adaptation block "use T { ... }" is not a class/function body
func TestClassifyTraitBlockIsOther(t *testing.T) {
t.Parallel()
s := lexStream("<?php class A { use T { m as n; } }")
// the SECOND "{" is the trait adaptation block
var braces []int
Expand Down
1 change: 1 addition & 0 deletions blink/internal/fixer/rules/casing_config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package rules
import "testing"

func TestConstantCaseConfig(t *testing.T) {
t.Parallel()
got, changed := apply(t, ConstantCase{}, "<?php $a = TRUE; $b = Null;")
if want := "<?php $a = true; $b = null;"; !changed || got != want {
t.Fatalf("default: changed=%v got=%q want=%q", changed, got, want)
Expand Down
1 change: 1 addition & 0 deletions blink/internal/fixer/rules/cast_spaces_config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package rules
import "testing"

func TestCastSpacesConfigCases(t *testing.T) {
t.Parallel()
cases := []struct {
name string
rule fixerRule
Expand Down
2 changes: 2 additions & 0 deletions blink/internal/fixer/rules/class_definition_config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package rules
import "testing"

func TestClassDefinitionSingleLine(t *testing.T) {
t.Parallel()
src := "<?php\nclass Foo\nextends Bar\n{\n}\n"

// default: a multiline header is left untouched
Expand All @@ -19,6 +20,7 @@ func TestClassDefinitionSingleLine(t *testing.T) {
}

func TestClassDefinitionSpaceBeforeParenthesis(t *testing.T) {
t.Parallel()
src := "<?php $x = new class() {};"

// default: anonymous class left untouched
Expand Down
1 change: 1 addition & 0 deletions blink/internal/fixer/rules/class_elements_config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package rules
import "testing"

func TestSingleClassElementPerStatementElements(t *testing.T) {
t.Parallel()
src := "<?php\nclass C\n{\n const A = 1, B = 2;\n public $a, $b;\n}\n"

// default: both const and property multi-declarations are split
Expand Down
5 changes: 5 additions & 0 deletions blink/internal/fixer/rules/class_members_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package rules
import "testing"

func TestVisibilityRequired(t *testing.T) {
t.Parallel()
got, changed := apply(t, VisibilityRequired{}, "<?php class A {\n function run() {}\n const X = 1;\n static $s;\n var $old;\n public $ok;\n}")
want := "<?php class A {\n public function run() {}\n public const X = 1;\n public static $s;\n public $old;\n public $ok;\n}"
if !changed || got != want {
Expand All @@ -15,6 +16,7 @@ func TestVisibilityRequired(t *testing.T) {
}

func TestVisibilityRequiredTypedProperty(t *testing.T) {
t.Parallel()
got, changed := apply(t, VisibilityRequired{}, "<?php class A {\n int $count;\n ?string $name;\n}")
want := "<?php class A {\n public int $count;\n public ?string $name;\n}"
if !changed || got != want {
Expand All @@ -23,6 +25,7 @@ func TestVisibilityRequiredTypedProperty(t *testing.T) {
}

func TestVisibilityRequiredSkipsTraitAndEnumCase(t *testing.T) {
t.Parallel()
if _, changed := apply(t, VisibilityRequired{}, "<?php class A {\n use SomeTrait;\n}"); changed {
t.Fatal("trait use must not get visibility")
}
Expand All @@ -32,6 +35,7 @@ func TestVisibilityRequiredSkipsTraitAndEnumCase(t *testing.T) {
}

func TestVisibilityRequiredIgnoresPromotedParams(t *testing.T) {
t.Parallel()
// constructor property promotion lives inside (), not the class body
src := "<?php class A {\n public function __construct(private int $x) {}\n}"
if _, changed := apply(t, VisibilityRequired{}, src); changed {
Expand All @@ -40,6 +44,7 @@ func TestVisibilityRequiredIgnoresPromotedParams(t *testing.T) {
}

func TestSingleTraitInsertPerStatement(t *testing.T) {
t.Parallel()
got, changed := apply(t, SingleTraitInsertPerStatement{}, "<?php class A {\n use TraitB, TraitC;\n}")
want := "<?php class A {\n use TraitB;\n use TraitC;\n}"
if !changed || got != want {
Expand Down
9 changes: 9 additions & 0 deletions blink/internal/fixer/rules/class_notation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package rules
import "testing"

func TestClassDefinitionNormalizesSpaces(t *testing.T) {
t.Parallel()
got, changed := apply(t, ClassDefinition{}, "<?php class A extends B implements C {}")
want := "<?php class A extends B implements C {}"
if !changed || got != want {
Expand All @@ -11,6 +12,7 @@ func TestClassDefinitionNormalizesSpaces(t *testing.T) {
}

func TestClassDefinitionLeavesCorrectHeader(t *testing.T) {
t.Parallel()
src := "<?php class A extends B implements C {}"
got, changed := apply(t, ClassDefinition{}, src)
if changed || got != src {
Expand All @@ -19,6 +21,7 @@ func TestClassDefinitionLeavesCorrectHeader(t *testing.T) {
}

func TestClassDefinitionKeepsNewlines(t *testing.T) {
t.Parallel()
// a multiline implements list keeps its layout
src := "<?php class A implements\n B,\n C\n{}"
got, changed := apply(t, ClassDefinition{}, src)
Expand All @@ -28,12 +31,14 @@ func TestClassDefinitionKeepsNewlines(t *testing.T) {
}

func TestClassDefinitionIgnoresClassConstant(t *testing.T) {
t.Parallel()
if _, changed := apply(t, ClassDefinition{}, "<?php $x = Foo::class;"); changed {
t.Fatal("::class must not be treated as a class header")
}
}

func TestOrderedClassElementsSimple(t *testing.T) {
t.Parallel()
src := "<?php class A {\n" +
" public function run() {}\n" +
" public $prop;\n" +
Expand All @@ -57,6 +62,7 @@ func TestOrderedClassElementsSimple(t *testing.T) {
}

func TestOrderedClassElementsOrderUseTraitOnly(t *testing.T) {
t.Parallel()
// order ["use_trait"] groups trait uses first and leaves every other member
// in its source order (const stays after the property here)
src := "<?php class A {\n" +
Expand All @@ -82,6 +88,7 @@ func TestOrderedClassElementsOrderUseTraitOnly(t *testing.T) {
}

func TestOrderedClassElementsAlreadyOrdered(t *testing.T) {
t.Parallel()
src := "<?php class A {\n" +
" const X = 1;\n" +
" public $prop;\n" +
Expand All @@ -94,6 +101,7 @@ func TestOrderedClassElementsAlreadyOrdered(t *testing.T) {
}

func TestOrderedClassElementsSkipsCommentsAndAttributes(t *testing.T) {
t.Parallel()
// a doc comment between members is trivia we do not move; skip the class
docSrc := "<?php class A {\n" +
" public function run() {}\n" +
Expand All @@ -115,6 +123,7 @@ func TestOrderedClassElementsSkipsCommentsAndAttributes(t *testing.T) {
}

func TestOrderedClassElementsSkipsEnumCases(t *testing.T) {
t.Parallel()
src := "<?php enum Suit {\n" +
" public function label() {}\n" +
" case Hearts;\n" +
Expand Down
1 change: 1 addition & 0 deletions blink/internal/fixer/rules/comments2_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package rules
import "testing"

func TestNoEmptyCommentBlock(t *testing.T) {
t.Parallel()
// empty // line inside a non-empty // block is preserved (PHP leaves it as-is)
block := "<?php\n// Native #[Route] attributes declared directly on bundle controllers.\n" +
"// Paths already carry their full prefix (e.g. /s, /api), so they are added\n" +
Expand Down
Loading
Loading