From 1000bb69291f895023b6ce9aa1cabb9c5d129348 Mon Sep 17 00:00:00 2001 From: Feek Date: Sun, 24 May 2020 11:29:41 -0700 Subject: [PATCH 1/2] fix: Argument::that allows params --- stubs/Prophecy.phpstub | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stubs/Prophecy.phpstub b/stubs/Prophecy.phpstub index 6f5a668..7c7e25e 100644 --- a/stubs/Prophecy.phpstub +++ b/stubs/Prophecy.phpstub @@ -17,7 +17,7 @@ namespace Prophecy { use Prophecy\Argument\Token; class Argument { - /** @param callable():bool $callback */ + /** @param callable(mixed...):bool $callback */ public static function that(callable $callback): Token\CallbackToken {} /** @param mixed ...$tokens */ From cd2ebfae14873c09f999a413b971f771e32f215d Mon Sep 17 00:00:00 2001 From: Feek Date: Sun, 24 May 2020 13:06:31 -0700 Subject: [PATCH 2/2] test: test cases for Argument::that --- tests/acceptance/Prophecy.feature | 92 +++++++++++++++++++++++++++++++ 1 file changed, 92 insertions(+) create mode 100644 tests/acceptance/Prophecy.feature diff --git a/tests/acceptance/Prophecy.feature b/tests/acceptance/Prophecy.feature new file mode 100644 index 0000000..1a1858e --- /dev/null +++ b/tests/acceptance/Prophecy.feature @@ -0,0 +1,92 @@ +Feature: Prophecy + In order to utilize Prophecy in my test cases + As a Psalm user + I need Psalm to typecheck my prophecies + + Background: + Given I have the following config + """ + + + + + + + + + + + """ + And I have the following code preamble + """ + 0; + }); + } + } + """ + When I run Psalm + Then I see no errors + + Scenario: Argument::that() accepts callable with multiple parameters + Given I have the following code + """ + class MyTestCase extends TestCase + { + /** @return void */ + public function testSomething() { + $argument = Argument::that(function (int $i, int $j, int $k) { + return ($i + $j + $k) > 0; + }); + } + } + """ + When I run Psalm + Then I see no errors + + Scenario: Argument::that() only accepts callable with boolean return type + Given I have the following code + """ + class MyTestCase extends TestCase + { + /** @return void */ + public function testSomething() { + $argument = Argument::that(function (): string { + return 'hello'; + }); + } + } + """ + When I run Psalm + Then I see these errors + | InvalidScalarArgument | Argument 1 of Prophecy\Argument::that expects callable(mixed...):bool, Closure():string(hello) provided |