From a17ae193ce5c3c1d8e275291d368b7238857012f Mon Sep 17 00:00:00 2001 From: Richardas Kuchinskas Date: Fri, 30 Aug 2024 15:41:29 +0300 Subject: [PATCH] test: closure and callback --- .../not_explicit_nullable_types_test.go | 31 +++++++++++++++++++ .../quickfix/notExplicitNullableParam.php | 15 +++++++++ .../notExplicitNullableParam.php.fix.expected | 15 +++++++++ 3 files changed, 61 insertions(+) diff --git a/src/tests/checkers/not_explicit_nullable_types_test.go b/src/tests/checkers/not_explicit_nullable_types_test.go index ff8171c6..e48d8bfe 100644 --- a/src/tests/checkers/not_explicit_nullable_types_test.go +++ b/src/tests/checkers/not_explicit_nullable_types_test.go @@ -301,3 +301,34 @@ $closure_fn = fn(?string $a, int $b = null, ?bool $c = null) => null; test.RunAndMatch() } + +func TestClassWithFunCallback(t *testing.T) { + test := linttest.NewSuite(t) + test.AddFile(`willReturnCallback(static function(int $user_id, array $exact_statuses = [], bool $need_hidden = true, Date $finished_at = null) use ($participation_statuses_data) { + return; + }); + } +} +`) + + test.Expect = []string{ + "parameter with null default value should be explicitly nullable", + "Missing PHPDoc for \\SomeClass::willReturnCallback public method", + "Specify the type for the parameter $participation_statuses_data", + "Expression evaluated but not used", + "Variable $participation_statuses_data is unused", + "Class or interface named \\Date does not exist", + } + + test.RunAndMatch() +} diff --git a/src/tests/golden/testdata/quickfix/notExplicitNullableParam.php b/src/tests/golden/testdata/quickfix/notExplicitNullableParam.php index 2c2917a7..2cd6852d 100644 --- a/src/tests/golden/testdata/quickfix/notExplicitNullableParam.php +++ b/src/tests/golden/testdata/quickfix/notExplicitNullableParam.php @@ -17,3 +17,18 @@ function multipleArgsExample(string $a, int $b = null, bool $c = null) {} function nullableOrString(null|string $a = null) {} function mixedParam(mixed $a = null) {} + +class SomeClass { + + public function willReturnCallback($callback): self + { + return $this; + } + + private function funWithCallback(array $participation_statuses_data) { + $this + ->willReturnCallback(static function(int $user_id, array $exact_statuses = [], bool $need_hidden = true, Date $finished_at = null) use ($participation_statuses_data) { + return; + }); + } +} diff --git a/src/tests/golden/testdata/quickfix/notExplicitNullableParam.php.fix.expected b/src/tests/golden/testdata/quickfix/notExplicitNullableParam.php.fix.expected index 9a2857af..649de6a4 100644 --- a/src/tests/golden/testdata/quickfix/notExplicitNullableParam.php.fix.expected +++ b/src/tests/golden/testdata/quickfix/notExplicitNullableParam.php.fix.expected @@ -17,3 +17,18 @@ function multipleArgsExample(string $a, ?int $b = null, ?bool $c = null) {} function nullableOrString(null|string $a = null) {} function mixedParam(mixed $a = null) {} + +class SomeClass { + + public function willReturnCallback($callback): self + { + return $this; + } + + private function funWithCallback(array $participation_statuses_data) { + $this + ->willReturnCallback(static function(int $user_id, array $exact_statuses = [], bool $need_hidden = true, ?Date $finished_at = null) use ($participation_statuses_data) { + return; + }); + } +}