Skip to content

Commit 4635481

Browse files
authored
Merge pull request #222 from PHPCSStandards/feature/file-getmethodproperties-improve-tests
File::getMethodProperties(): improve tests
2 parents 3179ad7 + 5971a5f commit 4635481

File tree

2 files changed

+693
-325
lines changed

2 files changed

+693
-325
lines changed

tests/Core/File/GetMethodPropertiesTest.inc

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,16 +34,23 @@ class MyClass {
3434
/* testMessyNullableReturnMethod */
3535
public function myFunction() /* comment
3636
*/ :
37-
/* comment */ ? //comment
37+
/* comment */ ? // phpcs:ignore Stnd.Cat.Sniff -- For reasons.
3838
array {}
3939

4040
/* testReturnNamespace */
4141
function myFunction(): \MyNamespace\MyClass {}
4242

4343
/* testReturnMultilineNamespace */
44+
// Parse error in PHP 8.0.
4445
function myFunction(): \MyNamespace /** comment *\/ comment */
4546
\MyClass /* comment */
4647
\Foo {}
48+
49+
/* testReturnUnqualifiedName */
50+
private function myFunction(): ?MyClass {}
51+
52+
/* testReturnPartiallyQualifiedName */
53+
function myFunction(): Sub\Level\MyClass {}
4754
}
4855

4956
abstract class MyClass
@@ -157,3 +164,27 @@ function pseudoTypeTrue(): ?true {}
157164
/* testPHP82PseudoTypeFalseAndTrue */
158165
// Intentional fatal error - Type contains both true and false, bool should be used instead, but that's not the concern of the method.
159166
function pseudoTypeFalseAndTrue(): true|false {}
167+
168+
/* testNotAFunction */
169+
return true;
170+
171+
/* testPhpcsIssue1264 */
172+
function foo() : array {
173+
echo $foo;
174+
}
175+
176+
/* testArrowFunctionArrayReturnValue */
177+
$fn = fn(): array => [a($a, $b)];
178+
179+
/* testArrowFunctionReturnByRef */
180+
fn&(?string $a) : ?string => $b;
181+
182+
/* testFunctionCallFnPHPCS353-354 */
183+
$value = $obj->fn(true);
184+
185+
/* testFunctionDeclarationNestedInTernaryPHPCS2975 */
186+
return (!$a ? [ new class { public function b(): c {} } ] : []);
187+
188+
/* testArrowFunctionLiveCoding */
189+
// Intentional parse error. This has to be the last test in the file.
190+
$fn = fn

0 commit comments

Comments
 (0)