PhpStan does not consider usage of Phpunit Assert::assertNotEmpty and Assert::assertContainsOnlyInstancesOf when returning an Array
Dieses Issue hat noch niemand übernommen.
Bewertung
- Schwierigkeit
- 4/5
- Geschätzter Aufwand
- 3-5 Tage
- Anfängerfreundlichkeit
- 42/100
Rechercherichtung
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.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Beschreibung
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 :)
- Vorherrschende Sprache
- PHP
- Sterne
- 544
- Forks
- 58
- Ø Merge
- 2 T. 1 Std.
- Gemergte PRs (30 T.)
- 5
Beitragsleitfaden
Für dieses Repository ist kein Beitragsleitfaden indexiert
Erste Schritte
- Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
- Forken Sie das Repository und arbeiten Sie in einem Branch.
- Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.
Mehr aus phpstan/phpstan-phpunit
-
bug
Schwierigkeit 3/5 1-2 Tage Anfängerfreundlichkeit 68/100
phpstan/phpstan-phpunit#332 · 2 Kommentare ·
-
Schwierigkeit 4/5 3-5 Tage Anfängerfreundlichkeit 48/100
phpstan/phpstan-phpunit#321 ·
-
Schwierigkeit 4/5 3-5 Tage Anfängerfreundlichkeit 48/100
phpstan/phpstan-phpunit#309 ·
-
Schwierigkeit 3/5 1-2 Tage Anfängerfreundlichkeit 45/100
phpstan/phpstan-phpunit#299 · 2 Kommentare ·
-
Schwierigkeit 3/5 1-2 Tage Anfängerfreundlichkeit 52/100
phpstan/phpstan-phpunit#292 · 3 Kommentare ·
Alle Issues in phpstan/phpstan-phpunit
Ähnliche Issues
-
needs-triage Platform(Default)
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 86/100
-
bug No Code Attached Yet
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 72/100
joomla/joomla-cms#48501 ·
-
sync-en
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 88/100
-
sync-en
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 84/100
-
Перевод устарел
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 78/100