Duplicate types for PHPUnit data providers

Abierto
#136 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 1 día

@alies-dev ya está trabajando en esto.

Desde el 9/11/2026.

  • #225 de @alies-dev — abierto

Evaluación

Dificultad
4/5
Tiempo estimado
3-5 días
Aptitud para principiantes
25/100
Tipo de issue
Error
Claridad
Bastante claro
Estado de actividad
Estancado
Stack tecnológico
php
Área
testing

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

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de psalm/psalm-plugin-phpunit

Todos los issues de psalm/psalm-plugin-phpunit

Issues similares

Más issues de Testing & QA

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.