[Bug]: [mutate] Enum case values are never mutation-tested
Maintainer thường phản hồi trong vòng 5 ngày
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 4/5
- Thời gian dự kiến
- 3-5 ngày
- Mức phù hợp với người mới
- 25/100
Hướng nghiên cứu
The report identifies four issues in pestphp/pest-plugin-mutate and links a branch with fixtures and tests for each. Read the plugin's mutation generation and coverage handling, then review the linked fixtures and tests to see how each case is reproduced. Done means the maintainers agree on an approach and the reported enum mutations and shared-root coverage paths behave as intended.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
What Happened
The value of a string-backed enum case is never effectively mutation-tested, even when tests check it. Changing 'paid' in the example below would break the test, but --mutate never reports it. There are four independent reasons, all in pestphp/pest-plugin-mutate:
- The mutator is dropped. The mutator for non-empty strings,
NotEmptyStringToEmpty, is not in a default set. When it is requested explicitly,MutationGenerator::filterMutators()drops it, because it only keeps mutators found inMutatorMap, which is built from the default sets. So no mutation is created at all. mutates()and--classignore enums.MutationGenerator::doesNotContainClassToMutate()matches onlyclassandtrait, somutates(Status::class)creates no mutation for an enum.- The case declarations have no line coverage. The mutation is then reported as uncovered, without running any test. With
--covered-only, the enum file is skipped entirely. - Separately, on Linux and macOS, when the covered files share only
/, every mutation is reported as uncovered (basePathof--coverage-phpis empty and the paths stay relative).
How to Reproduce
enum Status: string
{
case Paid = 'paid';
}
it('stores the paid status', function () {
expect(Status::Paid->value)->toBe('paid');
});
Run pest --mutate --mutator=StringNotEmptyStringToEmpty: no mutation is created for 'paid'. With mutates(Status::class) in the test file, no mutation is created either.
Sample Repository
https://github.com/mechgw/pest-plugin-mutate/compare/5.x...fix/enum-case-mutations (fixtures and tests for every case)
Pest Version
5.3.2 (pest-plugin-mutate 5.0.2)
PHP Version
8.4.21
Operation System
Linux, Windows
Notes
I would like to fix this in a series of small pull requests to pestphp/pest-plugin-mutate, each one useful on its own:
- pestphp/pest-plugin-mutate#48: keep the mutators requested outside the default sets (point 1). This is a general fix: it applies to any such mutator, not only to enums.
- pestphp/pest-plugin-mutate#49: restore the coverage paths when the covered files share only
/(point 4). Not related to enums; I found it while running the tests on Linux. - pestphp/pest-plugin-mutate#50: let
mutates()and--classselect enums (point 2). It changes the same regular expression as pestphp/pest-plugin-mutate#22; the two changes do not contradict each other, and I will rebase #50 on top of #22 if #22 is merged first. - last: verify the mutations of enum case values (point 3).
The last part is the largest, so I would rather hear your opinion before opening it. The approach is:
- for a mutated case value, the plugin runs the tests whose code references the case (
Status::Paid,self::Paid,static::Paid, andfrom(),tryFrom(),cases()as a reference to every case), including the hooks and the helper functions of the same test file. If those tests do not detect the mutation, it falls back to all the tests originally selected; - the result comes from the JUnit report of that run: a failing test means tested, a passing run means untested, and a missing report or an unknown exit code is reported as uncovered with the reason printed, never as tested;
- with
--covered-only, a case value is mutated only when the selected tests reference it. Cases referenced only from helpers in other files or from closures stored in variables are skipped, and this limitation is covered by a test; - in parallel runs, the workers record the tests they execute, so the plugin knows which tests were actually selected.
The complete change, with tests on Linux and Windows, is on the branch linked above. It is a large diff, so please read it only as a preview. I will split it and adapt it to whatever direction you prefer.
Would you accept this approach, or would you rather solve point 3 differently?
- Ngôn ngữ chính
- PHP
- Star
- 11.8k
- Fork
- 559
- Merge trung bình
- 5 ngày 23 giờ
- Pull request đã merge (30 ngày)
- 24
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Có mẫu pull request
- Đọc hướng dẫn đóng góp
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 pestphp/pest
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
Maintainer thường phản hồi trong vòng 5 ngày
-
[Bug]: --mutate hides unreadable files, so mutants behind a failed read can never be killedCó thể làm lại được Pull request cho issue này đã bị đóng mà không được merge. Đang mởbug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 88/100
Maintainer thường phản hồi trong vòng 5 ngày
-
[Bug]: [mutate] Windows: @pest-mutate-ignore comments land on line 1 in files with LF line endingsCó thể đã có người làm @webdevsamran đã nhận 57 ngày trước. Đang mởbug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
Maintainer thường phản hồi trong vòng 5 ngày
-
bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 80/100
Maintainer thường phản hồi trong vòng 5 ngày
-
[pest-plugin-browser] Page::waitForLoadState() never sends its message — waitForEvent() is a silent no-opCó thể đã có người làm @asllanmaciel đã nhận 70 ngày trước. Đang mởbug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 85/100
pestphp/pest#1892 · 2 bình luận ·
Maintainer thường phản hồi trong vòng 5 ngày
Issue tương tự
-
Group 2 - Data Storage | Tripal DBX | Chado Group 5 - Search | ElasticSearch | Views Priority - Medium
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 74/100
-
nginx update required due to NGINX2RootCó thể đã có người làm Có pull request liên kết đang mở hoặc đã được merge. Đang mở
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 65/100
mailcow/mailcow-dockerized#7668 · 5 bình luận · 2 reaction ·
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 77/100
lara-zeus/spatie-translatable#80 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
small
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 66/100
uiowa/uiowa#10296 · 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 75/100
asyncapi/modelina#2709 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày