[Feature request] Report willReturn values incompatible with method signature

Aperta
#48 4 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
35/100
Tipo di issue
Funzionalità
Chiarezza
Abbastanza chiara
Stato di attività
Ferma
Stack tecnologico
php

Direzione di ricerca

Start with the PHP example using createMock(), method('foo'), and willReturn(123), then trace the existing PHPStan PHPUnit rules that inspect mock configurations. Confirm how the declared string return type and the configured int value should be compared; done means PHPStan reports the incompatible willReturn value with an actionable diagnostic.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

Given

class MyClass
{
    public function foo(): string {}
}

class MyOtherClassTest extends \PHPUnit\Framework\TestCase
{
    public function testFooMock()
    {
        $class = $this->createMock(MyClass::class);
        $class
            ->expects(static::once())
            ->method('foo')
            ->willReturn(123)
        ;
    }
}

PHPUnit reports:

PHPUnit 8.2.0 by Sebastian Bergmann and contributors.

W                                                                  1 /  1 (100%)

Time: 173 ms, Memory: 16.00 MB

There was 1 warning:

1) MyOtherClassTest::testFooMock
Method foo may not return value of type int

WARNINGS!
Tests:  1, Assertions:    0, Warnings: 1.

It would be awesome if PHPStan could report this errors too.

Lingua principale
PHP
Stelle
544
Fork
58
Merge medio
2g 1h
PR unite (30g)
5

Guida per i contributori

Nessuna guida per i contributori indicizzata per questo repository

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di phpstan/phpstan-phpunit

Tutte le issue di phpstan/phpstan-phpunit

Issue simili

Altre issue su PHP

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.