`assertTrue` seems to lose inferred type
まだ誰も着手していません。
評価
調査の方向性
Start with the reproduction in tests/MockServerTrait.php, using the listed phpstan/phpstan and phpstan/phpstan-phpunit versions, and compare the dumped types before and after self::assertTrue. Trace how the PHPUnit assertTrue call is handled, then verify that the non-null MockWebServer type is preserved and the return-type error disappears.
索引モデルが issue の本文から書いたものです。
説明
phpstan/phpstanv2.1.13phpstan/phpstan-phpunitv2.0.6
Given the following trait:
trait MockServerTrait
{
private static ?MockWebServer\MockWebServer $mockServer = null;
protected static function startMockServer(
string $host = '127.0.0.1',
int $port = 2083,
): MockWebServer\MockWebServer {
self::$mockServer?->stop();
self::$mockServer = new MockWebServer\MockWebServer($port, $host);
self::$mockServer->start();
\PHPStan\dumpType(self::$mockServer); // line 55
self::assertTrue(self::$mockServer->isRunning());
\PHPStan\dumpType(self::$mockServer); // line 57
return self::$mockServer; // line 59
}
}
When running PHPStan, I get the following errors:
------ ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Line tests/MockServerTrait.php (in context of class EliasHaeussler\CpanelRequests\Tests\MockServerAwareTestCase)
------ ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
55 Dumped type: donatj\MockWebServer\MockWebServer
✏️ tests/MockServerTrait.php:55
57 Dumped type: donatj\MockWebServer\MockWebServer|null
✏️ tests/MockServerTrait.php:57
59 Method EliasHaeussler\CpanelRequests\Tests\MockServerAwareTestCase::startMockServer() should return donatj\MockWebServer\MockWebServer but returns donatj\MockWebServer\MockWebServer|null.
🪪 return.type
✏️ tests/MockServerTrait.php:59
------ ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
When I omit the last self::assertTrue, no errors are reported anymore.
- 主要言語
- PHP
- スター
- 544
- フォーク
- 58
- 平均マージ
- 2日 1時間
- マージ済み PR(30日)
- 5
コントリビューションガイド
このリポジトリのコントリビューションガイドは索引されていません
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
phpstan/phpstan-phpunit のほかの issue
-
bug
難易度 3/5 1〜2日 初心者へのやさしさ 68/100
phpstan/phpstan-phpunit#332 · コメント 2 件 ·
-
難易度 4/5 3〜5日 初心者へのやさしさ 48/100
phpstan/phpstan-phpunit#321 ·
-
難易度 4/5 3〜5日 初心者へのやさしさ 48/100
phpstan/phpstan-phpunit#309 ·
-
難易度 3/5 1〜2日 初心者へのやさしさ 45/100
phpstan/phpstan-phpunit#299 · コメント 2 件 ·
-
難易度 3/5 1〜2日 初心者へのやさしさ 52/100
phpstan/phpstan-phpunit#292 · コメント 3 件 ·
phpstan/phpstan-phpunit の issue をすべて見る
似ている issue
-
status/awaiting_triage
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
-
難易度 1/5 1時間未満 初心者へのやさしさ 90/100
WordPress/plugin-check#1486 ·
-
enhancement
難易度 2/5 1〜3時間 初心者へのやさしさ 88/100
az-digital/az_quickstart#6019 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
grokability/snipe-it#19688 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 85/100