From b8992e493a0e9a28a511f9091f118f0a37575c08 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20M=C3=B6ller?= Date: Wed, 8 Jan 2025 09:42:48 +0100 Subject: [PATCH] Fix: Add more test cases --- .../NoNullableReturnTypeDeclarationRule/script.php | 8 ++++++++ .../NoParameterWithNullDefaultValueRule/script.php | 4 ++-- .../script.php | 8 ++++++++ .../NoNullableReturnTypeDeclarationRule/script.php | 10 ++++++++++ .../NoParameterWithNullDefaultValueRule/script.php | 4 ++-- .../script.php | 10 ++++++++++ .../NoNullableReturnTypeDeclarationRule/script.php | 14 ++++++++++++++ .../NoParameterWithNullDefaultValueRule/script.php | 4 ++-- .../script.php | 14 ++++++++++++++ .../NoNullableReturnTypeDeclarationRuleTest.php | 4 ++++ ...arameterWithNullableTypeDeclarationRuleTest.php | 4 ++++ .../NoNullableReturnTypeDeclarationRuleTest.php | 4 ++++ ...arameterWithNullableTypeDeclarationRuleTest.php | 4 ++++ .../NoNullableReturnTypeDeclarationRuleTest.php | 4 ++++ ...arameterWithNullableTypeDeclarationRuleTest.php | 4 ++++ 15 files changed, 94 insertions(+), 6 deletions(-) diff --git a/test/Fixture/Closures/NoNullableReturnTypeDeclarationRule/script.php b/test/Fixture/Closures/NoNullableReturnTypeDeclarationRule/script.php index ca6393b8..e2cf7d12 100644 --- a/test/Fixture/Closures/NoNullableReturnTypeDeclarationRule/script.php +++ b/test/Fixture/Closures/NoNullableReturnTypeDeclarationRule/script.php @@ -19,3 +19,11 @@ $qux = function (): null|string { return 'Hello'; }; + +$quux = function (): nUlL|string { + return 'Hello'; +}; + +$quz = function (): \null|string { + return 'Hello'; +}; diff --git a/test/Fixture/Closures/NoParameterWithNullDefaultValueRule/script.php b/test/Fixture/Closures/NoParameterWithNullDefaultValueRule/script.php index 2146d8af..b847d112 100644 --- a/test/Fixture/Closures/NoParameterWithNullDefaultValueRule/script.php +++ b/test/Fixture/Closures/NoParameterWithNullDefaultValueRule/script.php @@ -19,10 +19,10 @@ return $bar; }; -$quux = function ($bar = \null) { +$quux = function ($bar = nUlL) { return $bar; }; -$quz = function ($bar = NuLl) { +$quz = function ($bar = \null) { return $bar; }; diff --git a/test/Fixture/Closures/NoParameterWithNullableTypeDeclarationRule/script.php b/test/Fixture/Closures/NoParameterWithNullableTypeDeclarationRule/script.php index 8102440e..13ec3872 100644 --- a/test/Fixture/Closures/NoParameterWithNullableTypeDeclarationRule/script.php +++ b/test/Fixture/Closures/NoParameterWithNullableTypeDeclarationRule/script.php @@ -22,3 +22,11 @@ $quux = function (null|string $bar) { return $bar; }; + +$quz = function (nUlL|string $bar) { + return $bar; +}; + +$corge = function (\null|string $bar) { + return $bar; +}; diff --git a/test/Fixture/Functions/NoNullableReturnTypeDeclarationRule/script.php b/test/Fixture/Functions/NoNullableReturnTypeDeclarationRule/script.php index c0220b1d..a7e85961 100644 --- a/test/Fixture/Functions/NoNullableReturnTypeDeclarationRule/script.php +++ b/test/Fixture/Functions/NoNullableReturnTypeDeclarationRule/script.php @@ -23,3 +23,13 @@ function quux(): null|string { return 'Hello'; } + +function quz(): nUlL|string +{ + return 'Hello'; +} + +function corge(): \null|string +{ + return 'Hello'; +} diff --git a/test/Fixture/Functions/NoParameterWithNullDefaultValueRule/script.php b/test/Fixture/Functions/NoParameterWithNullDefaultValueRule/script.php index edbcb987..8066b2c8 100644 --- a/test/Fixture/Functions/NoParameterWithNullDefaultValueRule/script.php +++ b/test/Fixture/Functions/NoParameterWithNullDefaultValueRule/script.php @@ -23,12 +23,12 @@ function qux($bar = null) return $bar; } -function quux($bar = \null) +function quux($bar = nUlL) { return $bar; } -function quz($bar = nUlL) +function quz($bar = \null) { return $bar; } diff --git a/test/Fixture/Functions/NoParameterWithNullableTypeDeclarationRule/script.php b/test/Fixture/Functions/NoParameterWithNullableTypeDeclarationRule/script.php index 725ed70f..eb839be6 100644 --- a/test/Fixture/Functions/NoParameterWithNullableTypeDeclarationRule/script.php +++ b/test/Fixture/Functions/NoParameterWithNullableTypeDeclarationRule/script.php @@ -27,3 +27,13 @@ function quux(null|string $bar) { return $bar; } + +function quz(nUlL|string $bar) +{ + return $bar; +} + +function corge(\null|string $bar) +{ + return $bar; +} diff --git a/test/Fixture/Methods/NoNullableReturnTypeDeclarationRule/script.php b/test/Fixture/Methods/NoNullableReturnTypeDeclarationRule/script.php index c9fa3dd8..430f243f 100644 --- a/test/Fixture/Methods/NoNullableReturnTypeDeclarationRule/script.php +++ b/test/Fixture/Methods/NoNullableReturnTypeDeclarationRule/script.php @@ -31,3 +31,17 @@ public function toString(): null|string return 'Hello'; } }; + +$quux = new class() { + public function toString(): nUlL|string + { + return 'Hello'; + } +}; + +$quz = new class() { + public function toString(): \null|string + { + return 'Hello'; + } +}; diff --git a/test/Fixture/Methods/NoParameterWithNullDefaultValueRule/script.php b/test/Fixture/Methods/NoParameterWithNullDefaultValueRule/script.php index e295fade..f6edf1ac 100644 --- a/test/Fixture/Methods/NoParameterWithNullDefaultValueRule/script.php +++ b/test/Fixture/Methods/NoParameterWithNullDefaultValueRule/script.php @@ -32,14 +32,14 @@ public function foo($bar = null) }; $quux = new class() { - public function foo($bar = \null) + public function foo($bar = nUlL) { return $bar; } }; $quz = new class() { - public function foo($bar = NuLl) + public function foo($bar = \null) { return $bar; } diff --git a/test/Fixture/Methods/NoParameterWithNullableTypeDeclarationRule/script.php b/test/Fixture/Methods/NoParameterWithNullableTypeDeclarationRule/script.php index 41588c85..f7f1471f 100644 --- a/test/Fixture/Methods/NoParameterWithNullableTypeDeclarationRule/script.php +++ b/test/Fixture/Methods/NoParameterWithNullableTypeDeclarationRule/script.php @@ -38,3 +38,17 @@ public function foo(null|string $bar) } }; +$quz = new class() { + public function foo(nUlL|string $bar) + { + return $bar; + } +}; + +$corge = new class() { + public function foo(\null|string $bar) + { + return $bar; + } +}; + diff --git a/test/Integration/Closures/NoNullableReturnTypeDeclarationRuleTest.php b/test/Integration/Closures/NoNullableReturnTypeDeclarationRuleTest.php index 3bb4a879..dba8e764 100644 --- a/test/Integration/Closures/NoNullableReturnTypeDeclarationRuleTest.php +++ b/test/Integration/Closures/NoNullableReturnTypeDeclarationRuleTest.php @@ -44,6 +44,10 @@ public function testNoNullableReturnTypeDeclarationRule(): void 'Closure has a nullable return type declaration.', 19, ], + [ + 'Closure has a nullable return type declaration.', + 23, + ], ], ); } diff --git a/test/Integration/Closures/NoParameterWithNullableTypeDeclarationRuleTest.php b/test/Integration/Closures/NoParameterWithNullableTypeDeclarationRuleTest.php index 52f8e04d..021580b4 100644 --- a/test/Integration/Closures/NoParameterWithNullableTypeDeclarationRuleTest.php +++ b/test/Integration/Closures/NoParameterWithNullableTypeDeclarationRuleTest.php @@ -44,6 +44,10 @@ public function testNoParameterWithNullableTypeDeclarationRule(): void 'Closure has parameter $bar with a nullable type declaration.', 22, ], + [ + 'Closure has parameter $bar with a nullable type declaration.', + 26, + ], ], ); } diff --git a/test/Integration/Functions/NoNullableReturnTypeDeclarationRuleTest.php b/test/Integration/Functions/NoNullableReturnTypeDeclarationRuleTest.php index ee88039e..e87a9561 100644 --- a/test/Integration/Functions/NoNullableReturnTypeDeclarationRuleTest.php +++ b/test/Integration/Functions/NoNullableReturnTypeDeclarationRuleTest.php @@ -44,6 +44,10 @@ public function testNoNullableReturnTypeDeclarationRule(): void 'Function Ergebnis\PHPStan\Rules\Test\Fixture\Functions\NoNullableReturnTypeDeclarationRule\quux() has a nullable return type declaration.', 22, ], + [ + 'Function Ergebnis\PHPStan\Rules\Test\Fixture\Functions\NoNullableReturnTypeDeclarationRule\quz() has a nullable return type declaration.', + 27, + ], ], ); } diff --git a/test/Integration/Functions/NoParameterWithNullableTypeDeclarationRuleTest.php b/test/Integration/Functions/NoParameterWithNullableTypeDeclarationRuleTest.php index 380eefe4..b0ba677c 100644 --- a/test/Integration/Functions/NoParameterWithNullableTypeDeclarationRuleTest.php +++ b/test/Integration/Functions/NoParameterWithNullableTypeDeclarationRuleTest.php @@ -44,6 +44,10 @@ public function testNoParameterWithNullableTypeDeclarationRule(): void 'Function Ergebnis\PHPStan\Rules\Test\Fixture\Functions\NoParameterWithNullableTypeDeclarationRule\quux() has parameter $bar with a nullable type declaration.', 26, ], + [ + 'Function Ergebnis\PHPStan\Rules\Test\Fixture\Functions\NoParameterWithNullableTypeDeclarationRule\quz() has parameter $bar with a nullable type declaration.', + 31, + ], ], ); } diff --git a/test/Integration/Methods/NoNullableReturnTypeDeclarationRuleTest.php b/test/Integration/Methods/NoNullableReturnTypeDeclarationRuleTest.php index d0cad8e6..41551844 100644 --- a/test/Integration/Methods/NoNullableReturnTypeDeclarationRuleTest.php +++ b/test/Integration/Methods/NoNullableReturnTypeDeclarationRuleTest.php @@ -72,6 +72,10 @@ public function testNoNullableReturnTypeDeclarationRule(): void 'Method toString() in anonymous class has a nullable return type declaration.', 29, ], + [ + 'Method toString() in anonymous class has a nullable return type declaration.', + 36, + ], ], ); } diff --git a/test/Integration/Methods/NoParameterWithNullableTypeDeclarationRuleTest.php b/test/Integration/Methods/NoParameterWithNullableTypeDeclarationRuleTest.php index fc7eceed..9eadd329 100644 --- a/test/Integration/Methods/NoParameterWithNullableTypeDeclarationRuleTest.php +++ b/test/Integration/Methods/NoParameterWithNullableTypeDeclarationRuleTest.php @@ -72,6 +72,10 @@ public function testNoParameterWithNullableTypeDeclarationRule(): void 'Method foo() in anonymous class has parameter $bar with a nullable type declaration.', 35, ], + [ + 'Method foo() in anonymous class has parameter $bar with a nullable type declaration.', + 42, + ], ], ); }