assertNotContains appears to be messing something up.
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 3/5
- Tiempo estimado
- 1-2 días
- Aptitud para principiantes
- 35/100
Línea de trabajo
Start with the shortened OmegaTag and testBasic examples in the issue, focusing on the interaction between assertNotContains() and the later assertCount() call. Compare the analysis with and without assertNotContains(); done when the collection is no longer inferred as NEVER and the impossibleType warning is resolved.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
I've got a weird issue that I can't seem to figure out. I think it is a bug in PHPStan, but I'm not certain.
I appreciate if you can point me in a way on how to debug this or help you figure out what is wrong.
Some context first:
- popped up after upgrading PHPStan yesterday, it was not there before. I update very often, so it was a recent change.
- Happens on both PHP8.4 and PHP8.5alpha
- It involves the PHPUnit method "assetNotContains", so I don't think I can create a playground example.
- I tried creating a small repo with an example, but I can't reproduce the error there. I'm not sure why. I used the same phpstan.neon file (just paths changed) and the contents of the classes appear identical to me (except namespaces).
Given this (a bit shortened) test class:
class OmegaTag
{
/**
* @var Collection<array-key, OmegaProduct>
*/
private Collection $products;
public function __construct()
{
$this->products = new ArrayCollection();
}
/**
* @return Collection<array-key, OmegaProduct>
*/
public function getProducts(): Collection
{
return $this->products;
}
}
This (shortened) test:
public function testBasic(): void
{
$product = new OmegaProduct();
$tag = new OmegaTag();
self::assertNotContains($product, $tag->getProducts());
self::assertCount(0, $tag->getProducts());
}
This gives me this error:
Call to static method PHPUnit\Framework\Assert::assertCount() with 0 and *NEVER* will always evaluate to false.
🪪 staticMethod.impossibleType
I'm not sure how PHPStan got to the type *NEVER*.
Observations:
- When I remove the line with the method
assertNotContains, the error goes away. - When I refactor the 2
$tag->getProducts()calls to a single variable and use that in the test, the error is still there.
It seems that assertNotContains narrows the type to never, while I think it should not do that.
Is there any direction you can point me in to find out what is wrong here?
Or is there any more info I can give if you think this is a bug?
- Lenguaje dominante
- PHP
- Estrellas
- 544
- Forks
- 58
- Merge medio
- 2 d 1 h
- PR fusionados (30 d)
- 5
Guía de contribución
No hay ninguna guía de contribución indexada para este repositorio
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de phpstan/phpstan-phpunit
-
bug
Dificultad 3/5 1-2 días Aptitud para principiantes 68/100
phpstan/phpstan-phpunit#332 · 2 comentarios ·
-
Dificultad 4/5 3-5 días Aptitud para principiantes 48/100
phpstan/phpstan-phpunit#321 ·
-
Dificultad 4/5 3-5 días Aptitud para principiantes 48/100
phpstan/phpstan-phpunit#309 ·
-
Dificultad 3/5 1-2 días Aptitud para principiantes 45/100
phpstan/phpstan-phpunit#299 · 2 comentarios ·
-
Dificultad 3/5 1-2 días Aptitud para principiantes 52/100
phpstan/phpstan-phpunit#292 · 3 comentarios ·
Todos los issues de phpstan/phpstan-phpunit
Issues similares
-
jira-created
Dificultad 2/5 1-3 horas Aptitud para principiantes 75/100
-
Dificultad 1/5 Menos de una hora Aptitud para principiantes 70/100
nunomaduro/phpinsights#745 ·
-
status/awaiting_triage
Dificultad 2/5 1-3 horas Aptitud para principiantes 75/100
-
Dificultad 1/5 Menos de una hora Aptitud para principiantes 90/100
WordPress/plugin-check#1486 ·
-
enhancement
Dificultad 2/5 1-3 horas Aptitud para principiantes 88/100
az-digital/az_quickstart#6019 ·