Hacktoberfest 2026: los issues que los mantenedores marcaron para octubre, abiertos y aptos para principiantes. Explorar issues de Hacktoberfest

Feature request: Validate `with` and `willReturn` types on mocks

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

Nadie ha tomado este issue todavía.

Evaluación

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

Línea de trabajo

Start with the PHPStan/PHPUnit integration and the example in the issue, since no files or tests are named. Done means detecting mismatched parameter types passed to with and an incompatible return value supplied to willReturn, with coverage demonstrating both reports.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

Given the following example, i'd expect PHPStan to report the following issues:

  • The parameter types in with don't match the function signature
  • The return value does not match the function signature.

This would be usefull for projects with a large test suite, where you do a refactor of a method that is used in a lot of places. It would allow to fix these issues before running the entire test suite to get the errors from PHPUnit.

class T1 {
    public function myMethod(int $a, string $b): int {
        return 3;
    }
}

class T1Test extends TestCase {
    public function testStuff(): void {
        $mock = $this->createMock(T1::class);

        $mock->expects($this->once())
            ->method('myMethod')
            ->with(
                new \stdClass(),
                new \stdClass(),
            )->willReturn(true);
    }
}
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

  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 phpstan/phpstan-phpunit

Todos los issues de phpstan/phpstan-phpunit

Issues similares

Más issues de PHP

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.