Duplicate types for PHPUnit data providers
Los mantenedores suelen responder en 1 día
Evaluación
- Dificultad
- 4/5
- Tiempo estimado
- 3-5 días
- Aptitud para principiantes
- 25/100
Línea de trabajo
Start by reading the PHPUnit plugin code that handles @dataProvider annotations and the associated tests; the issue does not name specific files or test entry points. Reproduce the reported MixedAssignment with Psalm at error level 1, then check whether the provider's documented return type reaches the test parameter. Done means the behavior is understood and the issue's question about whether the parameter type must be duplicated is answered; an open linked pull request already indicates work is underway.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
I have a question regarding the need to duplicate the types specified in @return in a data provider. Given the following test:
<?php declare(strict_types=1);
namespace MyNamespace;
use PHPUnit\Framework\TestCase;
class SomeTest extends TestCase
{
/**
* @return array<string,array{data:array<string,string>}>
*/
public static function getData(): array
{
return [
'some data' => [
'data' => [
'foo' => 'bar',
'bar' => 'foo',
],
],
];
}
/**
* @dataProvider getData
*/
public function testSomething(array $data): void
{
foreach ($data as $key => $value) {
// do some assertions
}
}
}
If I run psalm with an errorLevel set to 1 on this code I get the following error:
ERROR: MixedAssignment - tests/SomeTest.php:28:35 - Unable to determine the type that $value is being assigned to (see https://psalm.dev/032)
foreach ($data as $key => $value) {
I thought psalm might get this information from the @return docblock in the data provider. Do I need to duplicate the type for array $data as $param array< ... > $data on the testSomething method, or am I missing something?
- Lenguaje dominante
- Gherkin
- Estrellas
- 79
- Forks
- 38
- Merge medio
- 6 h 52 min
- PR fusionados (30 d)
- 28
Preparar el entorno
Este proyecto no incluye contenedor de desarrollo, Dockerfile ni guía de contribución, así que la configuración corre por tu cuenta: empieza por su README y consulta nuestra guía para la primera contribución para los pasos generales.
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 psalm/psalm-plugin-phpunit
-
enhancement
Dificultad 2/5 1-3 horas Aptitud para principiantes 67/100
psalm/psalm-plugin-phpunit#222 ·
Los mantenedores suelen responder en 1 día
-
enhancement
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
psalm/psalm-plugin-phpunit#220 ·
Los mantenedores suelen responder en 1 día
-
bug
Dificultad 2/5 1-3 horas Aptitud para principiantes 74/100
psalm/psalm-plugin-phpunit#219 ·
Los mantenedores suelen responder en 1 día
-
enhancement
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
psalm/psalm-plugin-phpunit#216 ·
Los mantenedores suelen responder en 1 día
-
enhancement
Dificultad 3/5 1-2 días Aptitud para principiantes 57/100
psalm/psalm-plugin-phpunit#223 ·
Los mantenedores suelen responder en 1 día
Todos los issues de psalm/psalm-plugin-phpunit
Issues similares
-
area: test kind: bug preview-effort: small priority: low
Dificultad 2/5 1-3 horas Aptitud para principiantes 65/100
Los mantenedores suelen responder en 1 día
-
ai-driven-fuzzing bug claude Minor
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
Los mantenedores suelen responder en 2 días
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 76/100
Los mantenedores suelen responder en 1 día
-
Dificultad 1/5 1-3 horas Aptitud para principiantes 85/100
hibernate/hibernate-reactive#4485 ·
Los mantenedores suelen responder en 1 día
-
auto-generated hub missing-coverage team/hub
Dificultad 2/5 1-3 horas Aptitud para principiantes 67/100
camunda/api-test-generator#770 ·
Los mantenedores suelen responder en 1 día