Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix internal phpstan error #316

Merged
merged 1 commit into from Mar 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 4 additions & 4 deletions phpstan-without-extension-baseline.neon
Expand Up @@ -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

-
Expand Down
4 changes: 0 additions & 4 deletions src/Type/Prophet/ProphesizeDynamicReturnTypeExtension.php
Expand Up @@ -66,10 +66,6 @@ public function getTypeFromMethodCall(

$className = $argumentType->getValue();

if (!$returnType instanceof Type\TypeWithClassName) {
throw new ShouldNotHappenException();
}

if ('static' === $className) {
return $returnType;
}
Expand Down
19 changes: 19 additions & 0 deletions test/StaticAnalysis/Test/ObjectProphecy/ProphesizeTest.php
Expand Up @@ -16,6 +16,7 @@
use JanGregor\Prophecy\Test\StaticAnalysis\Src;
use PHPUnit\Framework;
use Prophecy\Argument;
use Prophecy\Prophet;

/**
* @internal
Expand Down Expand Up @@ -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);
Expand Down