False positives with `assertSame` on generics with compatible subtypes
Maintainer antworten meist innerhalb von 1 Tag
Dieses Issue hat noch niemand übernommen.
Bewertung
- Schwierigkeit
- 3/5
- Geschätzter Aufwand
- 1-2 Tage
- Anfängerfreundlichkeit
- 35/100
Rechercherichtung
Start by reproducing the reported assertSame diagnostic with the CollectionAbstractModel and CollectionPaymentMethods examples. Trace the assertSame rule's handling of generic type arguments, then add a regression test for compatible contained types. Done means valid identity assertions no longer produce a false-positive while genuinely incompatible types remain reported.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Beschreibung
I have a Collection container class that uses generics:
/**
* This class represents a list of models.
*
* @template M of AbstractModel
* @extends \SplObjectStorage<M, int>
*/
class Collection extends \SplObjectStorage
{
…
}
(with AbstractModel being the abstract base class for domain models)
Now I get error messages like this:
3069 Call to static method PHPUnit\Framework\Assert::assertSame() with
OliverKlee\Oelib\DataStructures\Collection<OliverKlee\Oelib\Model\Abs
tractModel> and
OliverKlee\Oelib\DataStructures\Collection<Tx_Seminars_Model_Organize
r> will always evaluate to false.
(Organizer is a subclass of AbstractModel, as is PaymentMethods used in the example below.)
for code that basically looks like this (simplified):
class Event
{
/**
* @return Collection<PaymentMethods>
*/
public function getPaymentMethods(): Collection;
/**
* @param Collection<PaymentMethods> $paymentMethods
*/
public function setPaymentMethods(Collection $paymentMethods): void;
}
class EvenTest
{
public function testPaymentMethodsSetsPaymentMethods(): void
{
$paymentMethods = new Collection();
$this->subject->setPaymentMethods($paymentMethods);
self::assertSame($paymentMethods, $this->subject->getPaymentMethods());
}
}
So either the check for assertSame should completely disregard the contained type within generics, or it should allow contained types that are compatible to each other.
- Vorherrschende Sprache
- PHP
- Sterne
- 545
- Forks
- 58
- Ø Merge
- 10 Std. 48 Min.
- Gemergte PRs (30 T.)
- 10
Entwicklungsumgebung
Dieses Projekt bietet weder Dev-Container noch Dockerfile noch Beitragsleitfaden – die Einrichtung liegt bei Ihnen. Beginnen Sie mit der README; die allgemeinen Schritte stehen in unserem Leitfaden für den ersten Beitrag.
Erste Schritte
- Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
- Forken Sie das Repository und arbeiten Sie in einem Branch.
- Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.
Mehr aus phpstan/phpstan-phpunit
-
Schwierigkeit 4/5 3-5 Tage Anfängerfreundlichkeit 48/100
phpstan/phpstan-phpunit#338 · 1 Reaktion ·
Maintainer antworten meist innerhalb von 1 Tag
-
Schwierigkeit 4/5 3-5 Tage Anfängerfreundlichkeit 48/100
phpstan/phpstan-phpunit#321 ·
Maintainer antworten meist innerhalb von 1 Tag
-
Schwierigkeit 4/5 3-5 Tage Anfängerfreundlichkeit 48/100
phpstan/phpstan-phpunit#309 ·
Maintainer antworten meist innerhalb von 1 Tag
-
Schwierigkeit 3/5 1-2 Tage Anfängerfreundlichkeit 45/100
phpstan/phpstan-phpunit#299 · 2 Kommentare ·
Maintainer antworten meist innerhalb von 1 Tag
-
Schwierigkeit 3/5 1-2 Tage Anfängerfreundlichkeit 52/100
phpstan/phpstan-phpunit#292 · 3 Kommentare ·
Maintainer antworten meist innerhalb von 1 Tag
Alle Issues in phpstan/phpstan-phpunit
Ähnliche Issues
-
Daemon delete dialog: "Remove all ExApps" checkbox and `removeExApps` parameter have no effectOffen
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 85/100
Maintainer antworten meist innerhalb von 3 Tagen
-
Schwierigkeit 1/5 Unter einer Stunde Anfängerfreundlichkeit 90/100
Maintainer antworten meist innerhalb von 1 Tag
-
[Sync EN] Fix session read handler docs: false reports a failure, not a missing session (#5902)Offensync-en
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 78/100
Maintainer antworten meist innerhalb von 1 Tag
-
[Sync EN] Fix session read handler docs: false reports a failure, not a missing session (#5902)Offensync-en
Schwierigkeit 2/5 1-2 Tage Anfängerfreundlichkeit 84/100
Maintainer antworten meist innerhalb von 2 Tagen
-
feature-request needs-triage
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 72/100
aws/aws-sdk-php#3365 ·
Maintainer antworten meist innerhalb von 1 Tag