diff --git a/composer.json b/composer.json index 4005e25..b80aa74 100755 --- a/composer.json +++ b/composer.json @@ -25,7 +25,8 @@ "codeception/codeception": "^4.0.3", "composer/semver": "^1.4 || ^2.0 || ^3.0", "squizlabs/php_codesniffer": "^3.3.1", - "weirdan/codeception-psalm-module": "^0.7.1" + "weirdan/codeception-psalm-module": "^0.7.1", + "weirdan/prophecy-shim": "^1.0 || ^2.0" }, "extra": { "psalm": { diff --git a/stubs/Prophecy.phpstub b/stubs/Prophecy.phpstub index 7c7e25e..35fe49d 100644 --- a/stubs/Prophecy.phpstub +++ b/stubs/Prophecy.phpstub @@ -24,3 +24,16 @@ namespace Prophecy { public static function allOf(...$tokens): Token\LogicalAndToken {} } } + +namespace Prophecy\PhpUnit { + use Prophecy\Prophecy\ObjectProphecy; + trait ProphecyTrait + { + /** + * @template T + * @param class-string $classOrInterface + * @return ObjectProphecy + */ + protected function prophesize($classOrInterface): ObjectProphecy {} + } +} diff --git a/stubs/TestCase.phpstub b/stubs/TestCase.phpstub index b910c9d..40ab79a 100644 --- a/stubs/TestCase.phpstub +++ b/stubs/TestCase.phpstub @@ -47,7 +47,7 @@ abstract class TestCase extends Assert implements Test, SelfDescribing * @param class-string $classOrInterface * @return ObjectProphecy */ - public function prophesize($classOrInterface): ObjectProphecy {} + protected function prophesize($classOrInterface): ObjectProphecy {} /** * @param class-string<\Throwable> $exception diff --git a/tests/acceptance/Prophecy.feature b/tests/acceptance/Prophecy.feature index 1a1858e..98bcd9e 100644 --- a/tests/acceptance/Prophecy.feature +++ b/tests/acceptance/Prophecy.feature @@ -89,4 +89,22 @@ Feature: Prophecy """ When I run Psalm Then I see these errors + | Type | Message | | InvalidScalarArgument | Argument 1 of Prophecy\Argument::that expects callable(mixed...):bool, Closure():string(hello) provided | + And I see no other errors + + Scenario: prophesize() provided by ProphecyTrait is generic + Given I have the following code + """ + use Prophecy\PhpUnit\ProphecyTrait; + class SUT { public function getString(): string { return "zzz"; } } + class MyTestCase extends TestCase + { + use ProphecyTrait; + public function testSomething(): void { + $this->prophesize(SUT::class)->reveal()->getString(); + } + } + """ + When I run Psalm + Then I see no errors