From 0f145e1bbd915bdb11545ef7a10fa7f47b568932 Mon Sep 17 00:00:00 2001 From: Jurica Separovic Date: Thu, 4 Jan 2024 12:07:39 +0100 Subject: [PATCH] Remove unused check --- phpstan-without-extension-baseline.neon | 8 ++++---- .../ProphesizeDynamicReturnTypeExtension.php | 4 ---- .../Test/ObjectProphecy/ProphesizeTest.php | 19 +++++++++++++++++++ 3 files changed, 23 insertions(+), 8 deletions(-) diff --git a/phpstan-without-extension-baseline.neon b/phpstan-without-extension-baseline.neon index 9466479..a66a215 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: 1 + count: 2 path: test/StaticAnalysis/Test/ObjectProphecy/ProphesizeTest.php - message: "#^Call to an undefined method Prophecy\\\\Prophecy\\\\ObjectProphecy\\:\\:getFoo\\(\\)\\.$#" - count: 1 + count: 2 path: test/StaticAnalysis/Test/ObjectProphecy/ProphesizeTest.php - message: "#^Call to an undefined method object\\:\\:doubleTheNumber\\(\\)\\.$#" - count: 1 + count: 2 path: test/StaticAnalysis/Test/ObjectProphecy/ProphesizeTest.php - message: "#^Call to an undefined method object\\:\\:getFoo\\(\\)\\.$#" - count: 1 + count: 2 path: test/StaticAnalysis/Test/ObjectProphecy/ProphesizeTest.php - diff --git a/src/Type/Prophet/ProphesizeDynamicReturnTypeExtension.php b/src/Type/Prophet/ProphesizeDynamicReturnTypeExtension.php index a33d879..a9a30c8 100644 --- a/src/Type/Prophet/ProphesizeDynamicReturnTypeExtension.php +++ b/src/Type/Prophet/ProphesizeDynamicReturnTypeExtension.php @@ -66,10 +66,6 @@ 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 edcc659..559d799 100644 --- a/test/StaticAnalysis/Test/ObjectProphecy/ProphesizeTest.php +++ b/test/StaticAnalysis/Test/ObjectProphecy/ProphesizeTest.php @@ -16,6 +16,7 @@ use JanGregor\Prophecy\Test\StaticAnalysis\Src; use PHPUnit\Framework; use Prophecy\Argument; +use Prophecy\Prophet; /** * @internal @@ -83,6 +84,24 @@ 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);