Skip to content

File::getMethodProperties(): improve tests #222

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 2, 2024
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
33 changes: 32 additions & 1 deletion tests/Core/File/GetMethodPropertiesTest.inc
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,23 @@ class MyClass {
/* testMessyNullableReturnMethod */
public function myFunction() /* comment
*/ :
/* comment */ ? //comment
/* comment */ ? // phpcs:ignore Stnd.Cat.Sniff -- For reasons.
array {}

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

/* testReturnMultilineNamespace */
// Parse error in PHP 8.0.
function myFunction(): \MyNamespace /** comment *\/ comment */
\MyClass /* comment */
\Foo {}

/* testReturnUnqualifiedName */
private function myFunction(): ?MyClass {}

/* testReturnPartiallyQualifiedName */
function myFunction(): Sub\Level\MyClass {}
}

abstract class MyClass
Expand Down Expand Up @@ -157,3 +164,27 @@ function pseudoTypeTrue(): ?true {}
/* testPHP82PseudoTypeFalseAndTrue */
// Intentional fatal error - Type contains both true and false, bool should be used instead, but that's not the concern of the method.
function pseudoTypeFalseAndTrue(): true|false {}

/* testNotAFunction */
return true;

/* testPhpcsIssue1264 */
function foo() : array {
echo $foo;
}

/* testArrowFunctionArrayReturnValue */
$fn = fn(): array => [a($a, $b)];

/* testArrowFunctionReturnByRef */
fn&(?string $a) : ?string => $b;

/* testFunctionCallFnPHPCS353-354 */
$value = $obj->fn(true);

/* testFunctionDeclarationNestedInTernaryPHPCS2975 */
return (!$a ? [ new class { public function b(): c {} } ] : []);

/* testArrowFunctionLiveCoding */
// Intentional parse error. This has to be the last test in the file.
$fn = fn
Loading