From c74a5d682d4b11bb523d9cd302beea514fb0b5e5 Mon Sep 17 00:00:00 2001 From: sayuprc Date: Thu, 4 Sep 2025 21:37:59 +0900 Subject: [PATCH 1/3] Fix `RedisCluster::multi()` return type --- resources/functionMap.php | 2 +- .../PHPStan/Rules/Debug/DumpTypeRuleTest.php | 14 ++++++++++++++ tests/PHPStan/Rules/Debug/data/bug-13392.php | 19 +++++++++++++++++++ 3 files changed, 34 insertions(+), 1 deletion(-) create mode 100644 tests/PHPStan/Rules/Debug/data/bug-13392.php diff --git a/resources/functionMap.php b/resources/functionMap.php index d878c044d8..917169b68b 100644 --- a/resources/functionMap.php +++ b/resources/functionMap.php @@ -8896,7 +8896,7 @@ 'RedisCluster::mget' => ['array', 'array'=>'array'], 'RedisCluster::mset' => ['bool', 'array'=>'array'], 'RedisCluster::msetnx' => ['int', 'array'=>'array'], -'RedisCluster::multi' => ['Redis', 'mode='=>'int'], +'RedisCluster::multi' => ['__benevolent', 'mode='=>'int'], 'RedisCluster::object' => ['string', 'string='=>'string', 'key='=>'string'], 'RedisCluster::persist' => ['bool', 'key'=>'string'], 'RedisCluster::pExpire' => ['bool', 'key'=>'string', 'ttl'=>'int'], diff --git a/tests/PHPStan/Rules/Debug/DumpTypeRuleTest.php b/tests/PHPStan/Rules/Debug/DumpTypeRuleTest.php index fb4c489dea..aad8d65b7d 100644 --- a/tests/PHPStan/Rules/Debug/DumpTypeRuleTest.php +++ b/tests/PHPStan/Rules/Debug/DumpTypeRuleTest.php @@ -102,4 +102,18 @@ public function testBug11179NoNamespace(): void ]); } + public function testBug13392(): void + { + $this->analyse([__DIR__ . '/data/bug-13392.php'], [ + [ + 'Dumped type: RedisCluster', + 15, + ], + [ + 'Dumped type: (bool|RedisCluster)', + 18, + ], + ]); + } + } diff --git a/tests/PHPStan/Rules/Debug/data/bug-13392.php b/tests/PHPStan/Rules/Debug/data/bug-13392.php new file mode 100644 index 0000000000..781929aded --- /dev/null +++ b/tests/PHPStan/Rules/Debug/data/bug-13392.php @@ -0,0 +1,19 @@ +get(); + \PHPStan\dumpType($redisCluster); + + $transaction = $redisCluster->multi(); + \PHPStan\dumpType($transaction); +} From ec5642d52e5cb37053647b6a41b0ead08f30a42a Mon Sep 17 00:00:00 2001 From: sayuprc Date: Thu, 4 Sep 2025 23:13:57 +0900 Subject: [PATCH 2/3] Update test placement and contents --- tests/PHPStan/Analyser/AnalyserIntegrationTest.php | 6 ++++++ .../Debug/data => Analyser/nsrt}/bug-13392.php | 6 ++++-- tests/PHPStan/Rules/Debug/DumpTypeRuleTest.php | 14 -------------- 3 files changed, 10 insertions(+), 16 deletions(-) rename tests/PHPStan/{Rules/Debug/data => Analyser/nsrt}/bug-13392.php (64%) diff --git a/tests/PHPStan/Analyser/AnalyserIntegrationTest.php b/tests/PHPStan/Analyser/AnalyserIntegrationTest.php index f6d7dceff2..0c358928b4 100644 --- a/tests/PHPStan/Analyser/AnalyserIntegrationTest.php +++ b/tests/PHPStan/Analyser/AnalyserIntegrationTest.php @@ -1524,6 +1524,12 @@ public function testBug13310(): void $this->assertNoErrors($errors); } + public function testBug13392(): void + { + $errors = $this->runAnalyse(__DIR__ . '/nsrt/bug-13392.php'); + $this->assertNoErrors($errors); + } + /** * @param string[]|null $allAnalysedFiles * @return Error[] diff --git a/tests/PHPStan/Rules/Debug/data/bug-13392.php b/tests/PHPStan/Analyser/nsrt/bug-13392.php similarity index 64% rename from tests/PHPStan/Rules/Debug/data/bug-13392.php rename to tests/PHPStan/Analyser/nsrt/bug-13392.php index 781929aded..6637a89832 100644 --- a/tests/PHPStan/Rules/Debug/data/bug-13392.php +++ b/tests/PHPStan/Analyser/nsrt/bug-13392.php @@ -4,6 +4,8 @@ use RedisCluster; +use function PHPStan\Testing\assertType; + interface Client { public function get(): RedisCluster; @@ -12,8 +14,8 @@ public function get(): RedisCluster; function func(Client $client): void { $redisCluster = $client->get(); - \PHPStan\dumpType($redisCluster); + assertType('RedisCluster',$redisCluster); $transaction = $redisCluster->multi(); - \PHPStan\dumpType($transaction); + assertType('(bool|RedisCluster)',$transaction); } diff --git a/tests/PHPStan/Rules/Debug/DumpTypeRuleTest.php b/tests/PHPStan/Rules/Debug/DumpTypeRuleTest.php index aad8d65b7d..fb4c489dea 100644 --- a/tests/PHPStan/Rules/Debug/DumpTypeRuleTest.php +++ b/tests/PHPStan/Rules/Debug/DumpTypeRuleTest.php @@ -102,18 +102,4 @@ public function testBug11179NoNamespace(): void ]); } - public function testBug13392(): void - { - $this->analyse([__DIR__ . '/data/bug-13392.php'], [ - [ - 'Dumped type: RedisCluster', - 15, - ], - [ - 'Dumped type: (bool|RedisCluster)', - 18, - ], - ]); - } - } From 119d21e1ac8e3485631105d888ce67ff63456894 Mon Sep 17 00:00:00 2001 From: sayuprc Date: Thu, 4 Sep 2025 23:33:49 +0900 Subject: [PATCH 3/3] Remove unnecessary test cases --- tests/PHPStan/Analyser/AnalyserIntegrationTest.php | 6 ------ 1 file changed, 6 deletions(-) diff --git a/tests/PHPStan/Analyser/AnalyserIntegrationTest.php b/tests/PHPStan/Analyser/AnalyserIntegrationTest.php index 0c358928b4..f6d7dceff2 100644 --- a/tests/PHPStan/Analyser/AnalyserIntegrationTest.php +++ b/tests/PHPStan/Analyser/AnalyserIntegrationTest.php @@ -1524,12 +1524,6 @@ public function testBug13310(): void $this->assertNoErrors($errors); } - public function testBug13392(): void - { - $errors = $this->runAnalyse(__DIR__ . '/nsrt/bug-13392.php'); - $this->assertNoErrors($errors); - } - /** * @param string[]|null $allAnalysedFiles * @return Error[]