PhpStan does not consider usage of Phpunit Assert::assertNotEmpty and Assert::assertContainsOnlyInstancesOf when returning an Array
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 4/5
- Thời gian dự kiến
- 3-5 ngày
- Mức phù hợp với người mới
- 42/100
Hướng nghiên cứu
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.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
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 :)
- Ngôn ngữ chính
- PHP
- Star
- 544
- Fork
- 58
- Merge trung bình
- 2 ngày 1 giờ
- Pull request đã merge (30 ngày)
- 5
Hướng dẫn đóng góp
Chưa lập chỉ mục được hướng dẫn đóng góp cho kho mã nguồn này
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của phpstan/phpstan-phpunit
-
bug
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 68/100
phpstan/phpstan-phpunit#332 · 2 bình luận ·
-
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 48/100
phpstan/phpstan-phpunit#321 ·
-
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 48/100
phpstan/phpstan-phpunit#309 ·
-
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 45/100
phpstan/phpstan-phpunit#299 · 2 bình luận ·
-
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 52/100
phpstan/phpstan-phpunit#292 · 3 bình luận ·
Tất cả issue của phpstan/phpstan-phpunit
Issue tương tự
-
[Chore] Keep one viget-block-generator skill and replicate it, instead of four tracked copies Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 70/100
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
-
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 85/100
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
hector-jewell/food-delivery-system-for-restaurant-using-php#1311 ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 65/100
Sylius/SyliusGridBundle#501 ·