Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Output option for Mutation coverage #19

Open
wants to merge 14 commits into
base: 3.x
Choose a base branch
from

Conversation

LasseRafn
Copy link

@LasseRafn LasseRafn commented Sep 30, 2024

On a similar note as pestphp/pest-plugin-type-coverage#19, I would like to add an output option for mutation coverage.

The format follows more or less the same as for the type coverage and usage is the same as well:

--mutate-output-json=[path]

This will output a computer-readable file which can be used for reporting and tracking historical changes (especially relevant for repositories that does not have full coverage).

Based on comments from the type coverage PR, I have followed a very similar pattern with a NullLogger as default that can then be overwritten, which also would let us extend this to other formats than JSON. I did an unset of the arg after usage because the configuration class did not like me passing the arg to it.

Notes

  • I was unsure how to write tests for the plugin, couldn't find any that ran the src/Plugins/Mutate.php code to use as inspiration, so I just wrote a test for the JsonLogger
  • I hooked into the neat subscriber pattern that PrinterSubscriber uses to trigger output, but naming etc. might not be ideal to change?

Please do provide with feedback. Hope you'll consider support for this 🙏🏻 I will commit to keeping the output code maintained (tag me for related issues I'll be on it asap!)

Output example

{
	"format": "pest",
	"results": [
		{
			"path": "\/Users\/lasserafn\/Downloads\/php-example-pestphp-mutation-coverage\/src\/User.php",
			"count_total": 9,
			"count_not_run": 0,
			"count_timed_out": 0,
			"count_uncovered": 0,
			"count_untested": 2,
			"tests": [
				{
					"id": "6d3549fc8e6a1f96",
					"duration": 0.1179,
					"result": "tested",
					"mutation": {
						"id": "6d3549fc8e6a1f96",
						"mutator": "Pest\\Mutate\\Mutators\\ControlStructures\\IfNegated",
						"start_line": 20,
						"end_line": 25
					}
				},
				{
					"id": "70dfd45e38c4631e",
					"duration": 0.1071,
					"result": "tested",
					"mutation": {
						"id": "70dfd45e38c4631e",
						"mutator": "Pest\\Mutate\\Mutators\\Equality\\IdenticalToNotIdentical",
						"start_line": 20,
						"end_line": 20
					}
				},
				{
					"id": "75e38a7740a0415a",
					"duration": 0.1078,
					"result": "tested",
					"mutation": {
						"id": "75e38a7740a0415a",
						"mutator": "Pest\\Mutate\\Mutators\\Number\\DecrementInteger",
						"start_line": 20,
						"end_line": 20
					}
				},
				{
					"id": "8e91b931bd0908bb",
					"duration": 0.1051,
					"result": "tested",
					"mutation": {
						"id": "8e91b931bd0908bb",
						"mutator": "Pest\\Mutate\\Mutators\\Number\\IncrementInteger",
						"start_line": 20,
						"end_line": 20
					}
				},
				{
					"id": "aa7a76fbc9a8d0a9",
					"duration": 0.0999,
					"result": "untested",
					"mutation": {
						"id": "aa7a76fbc9a8d0a9",
						"mutator": "Pest\\Mutate\\Mutators\\Number\\DecrementInteger",
						"start_line": 21,
						"end_line": 21
					}
				},
				{
					"id": "12f7cc5502bddaf3",
					"duration": 0.0982,
					"result": "untested",
					"mutation": {
						"id": "12f7cc5502bddaf3",
						"mutator": "Pest\\Mutate\\Mutators\\Number\\IncrementInteger",
						"start_line": 21,
						"end_line": 21
					}
				},
				{
					"id": "07ad61bc7838a59c",
					"duration": 0.1061,
					"result": "tested",
					"mutation": {
						"id": "07ad61bc7838a59c",
						"mutator": "Pest\\Mutate\\Mutators\\Logical\\TrueToFalse",
						"start_line": 24,
						"end_line": 24
					}
				},
				{
					"id": "c8d4ddcec1589bbe",
					"duration": 0.1176,
					"result": "tested",
					"mutation": {
						"id": "c8d4ddcec1589bbe",
						"mutator": "Pest\\Mutate\\Mutators\\Removal\\RemoveEarlyReturn",
						"start_line": 24,
						"end_line": 24
					}
				},
				{
					"id": "ba3ed65695679b63",
					"duration": 0.1112,
					"result": "tested",
					"mutation": {
						"id": "ba3ed65695679b63",
						"mutator": "Pest\\Mutate\\Mutators\\Logical\\FalseToTrue",
						"start_line": 27,
						"end_line": 27
					}
				}
			]
		}
	],
	"stats": {
		"duration": 0.9737,
		"score": 77.77777777777779,
		"tests": {
			"count_total": 1,
			"count_not_run": 0,
			"count_timed_out": 0,
			"count_uncovered": 0,
			"count_untested": 2
		}
	}
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant