PhpStan does not consider usage of Phpunit Assert::assertNotEmpty and Assert::assertContainsOnlyInstancesOf when returning an Array
維護者通常 1 天內回覆
還沒有人認領這個 Issue。
評估
研究方向
Reproduce the report with the shown PHPUnit test and its @return Post[] annotation, focusing on the assertNotEmpty() and assertContainsOnlyInstancesOf() calls before return $result. Inspect how the phpstan-phpunit extension handles these assertions and verify that the return type is accepted afterward.
由索引模型根據 Issue 內容生成。
描述
Hello,
I am building a test returning an array of entities to be used in some others tests marked with @depends.
Despite I check that my returned array is not empty an contains only instances of a specific class, phpstan keeps alerting
that my returned value does not match. Here is my code:
/**
* @return Post[]
*
* @throws \Exception
*/
public function testFindForHomePageReturnsCollectionOfPosts(): array
{
$testSubject = self::getContainer()->get(PostRepository::class);
if (!$testSubject instanceof PostRepository) {
throw new ServiceNotFoundException(PostRepository::class);
}
$result = $testSubject->findForHomePage()->toArray();
self::assertNotEmpty($result);
self::assertContainsOnlyInstancesOf(Post::class, $result);
return $result;
}
And the alert thrown by phpstan (line 34 is the return $result statement):

Context:
Symfony 6.2 KernelTestCase
phpunit/phpunit 9.5.25
symfony/phpunit-bridge 6.2.0
PhpStan 1.9.3
extensions:
- phpstan-phpunit 1.3.2
- phpstan-doctrine 1.3.18
- phpstan-symfony 1.2.15
- phpstan/phpstan-webmozart-assert 1.2.1
Thanks a lot for your help :)
- 主要語言
- PHP
- 星號
- 545
- 分支
- 58
- 平均合併
- 12 小時 32 分鐘
- 30 天內合併 PR
- 11
環境準備
這個專案沒有提供開發容器、Dockerfile 或貢獻指南,環境需要你自己搭建:先看它的 README,通用步驟見我們的新手貢獻指南。
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
phpstan/phpstan-phpunit 的其他 Issue
-
難度 4/5 3-5 天 新手友好度 48/100
phpstan/phpstan-phpunit#321 ·
維護者通常 1 天內回覆
-
難度 4/5 3-5 天 新手友好度 48/100
phpstan/phpstan-phpunit#309 ·
維護者通常 1 天內回覆
-
難度 3/5 1-2 天 新手友好度 45/100
phpstan/phpstan-phpunit#299 · 2 則留言 ·
維護者通常 1 天內回覆
-
難度 3/5 1-2 天 新手友好度 52/100
phpstan/phpstan-phpunit#292 · 3 則留言 ·
維護者通常 1 天內回覆
-
難度 4/5 3-5 天 新手友好度 20/100
phpstan/phpstan-phpunit#291 ·
維護者通常 1 天內回覆
查看 phpstan/phpstan-phpunit 的全部 Issue
相似的 Issue
-
needs-triage Platform(Default)
難度 2/5 1-3 小時 新手友好度 76/100
維護者通常 1 天內回覆
-
[Store] RstLoader detects headings inside indented code blocks可能已有人在做 @lazerg 今天認領。 未關閉Bug Status: Needs Review Store
難度 2/5 1-3 小時 新手友好度 82/100
維護者通常 1 天內回覆
-
bug repo:ckeditor
難度 2/5 1-3 小時 新手友好度 78/100
-
No Code Attached Yet
難度 2/5 1-3 小時 新手友好度 72/100
joomla/joomla-cms#48611 ·
維護者通常 1 天內回覆
-
難度 2/5 1-3 小時 新手友好度 65/100
維護者通常 1 天內回覆