Skip to content

Commit 27335e0

Browse files
staabmsebastianbergmann
authored andcommitted
Support static analysis in PHPUnit\Framework\callback()
1 parent f8d0321 commit 27335e0

File tree

2 files changed

+32
-7
lines changed

2 files changed

+32
-7
lines changed

build/scripts/generate-global-assert-wrappers.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,11 @@
6464

6565
$usedClasses[] = $returnType->getName();
6666

67+
// skip, so we can later on append a signature including precise analysis types
68+
if ($method->getName() === 'callback') {
69+
continue;
70+
}
71+
6772
$constraintMethods .= \sprintf(
6873
"if (!function_exists('PHPUnit\Framework\\" . $method->getName() . "')) {\n%s\n{\n return Assert::%s(...\\func_get_args());\n}\n}\n\n",
6974
\str_replace('final public static ', '', \trim($lines[$method->getStartLine() - 1])),
@@ -105,6 +110,19 @@
105110
$buffer .= $constraintMethods;
106111

107112
$buffer .= <<<'EOT'
113+
if (!function_exists('PHPUnit\Framework\callback')) {
114+
/**
115+
* @psalm-template CallbackInput of mixed
116+
*
117+
* @psalm-param callable(CallbackInput $callback): bool $callback
118+
*
119+
* @psalm-return Callback<CallbackInput>
120+
*/
121+
function callback(callable $callback): Callback
122+
{
123+
return Assert::callback($callback);
124+
}
125+
}
108126
109127
if (!function_exists('PHPUnit\Framework\any')) {
110128
/**

src/Framework/Assert/Functions.php

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2308,13 +2308,6 @@ function isTrue(): IsTrue
23082308
}
23092309
}
23102310

2311-
if (!function_exists('PHPUnit\Framework\callback')) {
2312-
function callback(callable $callback): Callback
2313-
{
2314-
return Assert::callback(...func_get_args());
2315-
}
2316-
}
2317-
23182311
if (!function_exists('PHPUnit\Framework\isFalse')) {
23192312
function isFalse(): IsFalse
23202313
{
@@ -2567,6 +2560,20 @@ function objectEquals(object $object, string $method = 'equals'): ObjectEquals
25672560
}
25682561
}
25692562

2563+
if (!function_exists('PHPUnit\Framework\callback')) {
2564+
/**
2565+
* @psalm-template CallbackInput of mixed
2566+
*
2567+
* @psalm-param callable(CallbackInput $callback): bool $callback
2568+
*
2569+
* @psalm-return Callback<CallbackInput>
2570+
*/
2571+
function callback(callable $callback): Callback
2572+
{
2573+
return Assert::callback($callback);
2574+
}
2575+
}
2576+
25702577
if (!function_exists('PHPUnit\Framework\any')) {
25712578
/**
25722579
* Returns a matcher that matches when the method is executed

0 commit comments

Comments
 (0)