False positives with `assertSame` on generics with compatible subtypes
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 3/5
- Thời gian dự kiến
- 1-2 ngày
- Mức phù hợp với người mới
- 35/100
Hướng nghiên cứu
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.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
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.
- Ngôn ngữ chính
- PHP
- Star
- 544
- Fork
- 58
- Merge trung bình
- 2 ngày 1 giờ
- Pull request đã merge (30 ngày)
- 5
Hướng dẫn đóng góp
Chưa lập chỉ mục được hướng dẫn đóng góp cho kho mã nguồn này
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của phpstan/phpstan-phpunit
-
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 68/100
phpstan/phpstan-phpunit#332 ·
-
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 48/100
phpstan/phpstan-phpunit#321 ·
-
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 48/100
phpstan/phpstan-phpunit#309 ·
-
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 45/100
phpstan/phpstan-phpunit#299 · 2 bình luận ·
-
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 52/100
phpstan/phpstan-phpunit#292 · 3 bình luận ·
Tất cả issue của phpstan/phpstan-phpunit
Issue tương tự
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
getgrav/grav-plugin-form#656 ·
-
customer-support needs-triage Platform(Default)
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
-
sync-en
Độ khó 1/5 1-3 giờ Mức phù hợp với người mới 88/100
-
sync-en
Độ khó 1/5 1-3 giờ Mức phù hợp với người mới 88/100
-
Перевод устарел
Độ khó 1/5 1-3 giờ Mức phù hợp với người mới 88/100