From 35c8172a5a7811f8d6453212a75011cceb688e63 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20M=C3=B6ller?= Date: Mon, 4 Mar 2024 09:08:23 +0100 Subject: [PATCH] Revert "Fix internal phpstan error" --- phpstan-without-extension-baseline.neon | 8 ++++---- .../ProphesizeDynamicReturnTypeExtension.php | 4 ++++ .../Test/ObjectProphecy/ProphesizeTest.php | 19 ------------------- 3 files changed, 8 insertions(+), 23 deletions(-) diff --git a/phpstan-without-extension-baseline.neon b/phpstan-without-extension-baseline.neon index a66a215..9466479 100644 --- a/phpstan-without-extension-baseline.neon +++ b/phpstan-without-extension-baseline.neon @@ -22,22 +22,22 @@ parameters: - message: "#^Call to an undefined method Prophecy\\\\Prophecy\\\\ObjectProphecy\\:\\:doubleTheNumber\\(\\)\\.$#" - count: 2 + count: 1 path: test/StaticAnalysis/Test/ObjectProphecy/ProphesizeTest.php - message: "#^Call to an undefined method Prophecy\\\\Prophecy\\\\ObjectProphecy\\:\\:getFoo\\(\\)\\.$#" - count: 2 + count: 1 path: test/StaticAnalysis/Test/ObjectProphecy/ProphesizeTest.php - message: "#^Call to an undefined method object\\:\\:doubleTheNumber\\(\\)\\.$#" - count: 2 + count: 1 path: test/StaticAnalysis/Test/ObjectProphecy/ProphesizeTest.php - message: "#^Call to an undefined method object\\:\\:getFoo\\(\\)\\.$#" - count: 2 + count: 1 path: test/StaticAnalysis/Test/ObjectProphecy/ProphesizeTest.php - diff --git a/src/Type/Prophet/ProphesizeDynamicReturnTypeExtension.php b/src/Type/Prophet/ProphesizeDynamicReturnTypeExtension.php index cbcf12b..36204d3 100644 --- a/src/Type/Prophet/ProphesizeDynamicReturnTypeExtension.php +++ b/src/Type/Prophet/ProphesizeDynamicReturnTypeExtension.php @@ -65,6 +65,10 @@ public function getTypeFromMethodCall( $className = $argumentType->getValue(); + if (!$returnType instanceof Type\TypeWithClassName) { + throw new ShouldNotHappenException(); + } + if ('static' === $className) { return $returnType; } diff --git a/test/StaticAnalysis/Test/ObjectProphecy/ProphesizeTest.php b/test/StaticAnalysis/Test/ObjectProphecy/ProphesizeTest.php index 559d799..edcc659 100644 --- a/test/StaticAnalysis/Test/ObjectProphecy/ProphesizeTest.php +++ b/test/StaticAnalysis/Test/ObjectProphecy/ProphesizeTest.php @@ -16,7 +16,6 @@ use JanGregor\Prophecy\Test\StaticAnalysis\Src; use PHPUnit\Framework; use Prophecy\Argument; -use Prophecy\Prophet; /** * @internal @@ -84,24 +83,6 @@ public function testCreateProphecyInHelperMethod(): void self::assertEquals(5, $testDouble->doubleTheNumber(2)); } - public function testCreateProphecyInline(): void - { - $prophecy = (new Prophet())->prophesize(Src\BaseModel::class); - - $prophecy - ->getFoo() - ->willReturn('bar'); - - $prophecy - ->doubleTheNumber(Argument::is(2)) - ->willReturn(5); - - $testDouble = $prophecy->reveal(); - - self::assertEquals('bar', $testDouble->getFoo()); - self::assertEquals(5, $testDouble->doubleTheNumber(2)); - } - private function createProphecy() { return $this->prophesize(Src\BaseModel::class);