PHPStan includes phpstan/phpstan-phpunit, but it doesn't seem to recognize mocks.

Aperta
#285 2 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
55/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Ferma
Stack tecnologico
php
Ambito
testing

Direzione di ricerca

Start with vendor/phpstan/phpstan-phpunit/stubs/MockObject.stub and compare it with vendor/phpunit/phpunit/src/Framework/MockObject/Runtime/Interface/MockObject.php. Check how PHPStan uses the stub, then update the stub so the MockObject interface exposes the expects() method shown in the PHPUnit interface. Done means PHPStan recognizes expects() on PHPUnit mock objects.

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

Descrizione

Problem

PHPStan includes phpstan/phpstan-phpunit, but it doesn't seem to recognize mocks.

  1. phpstan-phpunit 2.0.16 ships with a stub file, MockObject.stub, which contains an empty MockObject interface without an expects() method.
  2. When PHPStan analyzes your code, it uses the stub file instead of the real PHPUnit interface.
  3. This causes PHPStan to not see the expects() method on mock objects.
    This is a bug in phpstan-phpunit 2.0.16. The stub file, MockObject.stub, must contain a definition of the expects() method.

Reason

Bug in phpstan/phpstan-phpunit version 2.0.16
The stub file /home/mihail/proj/task/vendor/phpstan/phpstan-phpunit/stubs/MockObject.stub contains an empty MockObject interface without an expects() method:
// vendor/phpstan/phpstan-phpunit/stubs/MockObject.stub

namespace PHPUnit\Framework\MockObject;
interface MockObject
{
// EMPTY - no expects() method!
}

However, the real MockObject interface in PHPUnit 11.x has an expects() method:
// vendor/phpunit/phpunit/src/Framework/MockObject/Runtime/Interface/MockObject.php

interface MockObject extends Stub
{
public function expects(InvocationOrder $invocationRule): InvocationMocker;
}

PHPStan uses the stub file instead of the real class, so it doesn't see the expects() method.

Solution

Correct the stub file in phpstan-phpunit. You need to add the expects() method to MockObject.stub.

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.