Missing mock type information for Mockery\Expectation::getMock()
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 5/5
- Thời gian dự kiến
- Hơn một tuần
- Mức phù hợp với người mới
- 30/100
Hướng nghiên cứu
Start at the Mockery::mock(), MockInterface::shouldReceive(), and Expectation::getMock() entry points described in the issue, then trace how this extension represents their return types. Done means the mocked type is preserved through the fluent chain so the shown getMock() example is accepted by PHPStan; the payload names no repository files or tests to run.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Mockery::mock() returns a Mockery\MockInterface. MockInterface::shouldReceive() et al returns an Mockery\Expectation, which in turn has a getMock() method to return the MockInterface the Expectation belongs to.
The problem is that phpstan says the return type of Expectation::getMock() is Mockery\MockInterface with no type information on what was originally mocked. So for example
interface A {
foo(): void
}
function getMock(): A
{
return Mockery::mock(A::class)
->shouldReceive('foo')
->getMock();
}
will cause the following phpstan error: Function getMock() should return A but returns Mockery\MockInterface.
Of course the code in getMock() can be rewritten to not be fluent so that the return value of Mockery::mock() is returned instead, however in many cases I mock objects inline in some other expression and when I do that it's really helpful to be able to use the fluent way of writing the expectations.
Is it possible to change the type of the return value of Mockery\Expectation::getMock() to include the type information of the original mock? With generics I guess it should be something like Mockery::mock(T): MockInterface<T>, MockInterface<T>::shouldReceive(): Expectation<T> and Expectation<T>::getMock(): MockInterface<T>.
- Ngôn ngữ chính
- PHP
- Star
- 109
- Fork
- 25
- Merge trung bình
- 1 giờ 41 phút
- Pull request đã merge (30 ngày)
- 1
Chuẩn bị môi trường
Dự án này không cung cấp dev container, Dockerfile hay hướng dẫn đóng góp, nên bạn cần tự thiết lập môi trường: hãy bắt đầu từ README và xem hướng dẫn đóng góp lần đầu của chúng tôi để biết các bước chung.
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-mockery
-
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 45/100
phpstan/phpstan-mockery#78 ·
-
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 35/100
phpstan/phpstan-mockery#77 · 1 reaction ·
-
Dependency DashboardĐang mở
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 10/100
phpstan/phpstan-mockery#46 ·
-
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 35/100
phpstan/phpstan-mockery#34 · 1 bình luận ·
-
Call to protected method xxx()Đang mở
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 28/100
phpstan/phpstan-mockery#18 · 1 bình luận · 6 reaction ·
Tất cả issue của phpstan/phpstan-mockery
Issue tương tự
-
Infrastructure: actions Module: zmscitizenapi Module: zmsentities php Type: Bug unit tests
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 88/100
it-at-m/eappointment#3480 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
CI: composer install fails — league/flysystem 1.x blocked by security advisory GHSA-cxf4-7mrp-vvprĐang mởdevops type: bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 84/100
Maintainer thường phản hồi trong vòng 1 ngày
-
needs approval
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 88/100
Maintainer thường phản hồi trong vòng 3 ngày
-
product / avatars product / self-hosted product / storage
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
appwrite/appwrite#13985 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
Maintainer thường phản hồi trong vòng 1 ngày