Hacktoberfest 2026: as issues que os mantenedores marcaram para outubro, abertas e boas para iniciantes. Ver issues do Hacktoberfest

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

Aberta
#321 0 comentários 0 reações 0 responsáveis Ver no GitHub

Ninguém assumiu esta issue ainda.

Avaliação

Dificuldade
4/5
Tempo estimado
3-5 dias
Facilidade para iniciantes
48/100
Tipo de issue
Funcionalidade
Clareza
Razoavelmente clara
Status de atividade
Pouca atividade
Stack de tecnologia
php
Domínio
testing

Direção de pesquisa

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.

Escrita pelo modelo de indexação a partir do texto da issue.

Descrição

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);
    }
}
Linguagem predominante
PHP
Estrelas
544
Forks
58
Merge médio
2d 1h
PRs com merge (30d)
5

Guia de contribuição

Nenhum guia de contribuição indexado para este repositório

Primeiros passos

  1. Leia a issue inteira e depois o guia de contribuição do projeto.
  2. Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
  3. Faça um fork do repositório e trabalhe em uma branch.
  4. Abra um pull request que referencie o número da issue.

Mais de phpstan/phpstan-phpunit

Todas as issues de phpstan/phpstan-phpunit

Issues semelhantes

Mais issues de PHP

Receba novas issues na sua caixa de entrada

Um resumo curto de issues do GitHub para quem está começando.