PhpStan does not consider usage of Phpunit Assert::assertNotEmpty and Assert::assertContainsOnlyInstancesOf when returning an Array
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Idoneità per principianti
- 42/100
Direzione di ricerca
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.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
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 :)
- Lingua principale
- PHP
- Stelle
- 544
- Fork
- 58
- Merge medio
- 2g 1h
- PR unite (30g)
- 5
Guida per i contributori
Nessuna guida per i contributori indicizzata per questo repository
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di phpstan/phpstan-phpunit
-
bug
Difficoltà 3/5 1-2 giorni Idoneità per principianti 68/100
phpstan/phpstan-phpunit#332 · 2 commenti ·
-
Difficoltà 4/5 3-5 giorni Idoneità per principianti 48/100
phpstan/phpstan-phpunit#321 ·
-
Difficoltà 4/5 3-5 giorni Idoneità per principianti 48/100
phpstan/phpstan-phpunit#309 ·
-
Difficoltà 3/5 1-2 giorni Idoneità per principianti 45/100
phpstan/phpstan-phpunit#299 · 2 commenti ·
-
Difficoltà 3/5 1-2 giorni Idoneità per principianti 52/100
phpstan/phpstan-phpunit#292 · 3 commenti ·
Tutte le issue di phpstan/phpstan-phpunit
Issue simili
-
status/awaiting_triage
Difficoltà 2/5 1-3 ore Idoneità per principianti 75/100
-
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 90/100
WordPress/plugin-check#1486 ·
-
enhancement
Difficoltà 2/5 1-3 ore Idoneità per principianti 88/100
az-digital/az_quickstart#6019 ·
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 75/100
grokability/snipe-it#19688 ·
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 85/100