Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/Support/MutationGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ public function generate(
}

$mutatorsToIgnoreByLine = [];
foreach (explode(PHP_EOL, $contents) as $lineNumber => $line) {
$lines = preg_split('/\R/', $contents) ?: [];
foreach ($lines as $lineNumber => $line) {
if (str_contains($line, '@pest-mutate-ignore')) {
if (Str::after($line, '@pest-mutate-ignore:') !== $line) {
$mutatorsToIgnore = explode(',', Str::after($line, '@pest-mutate-ignore:'));
Expand Down
10 changes: 10 additions & 0 deletions tests/Unit/MutationGeneratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,16 @@ classesToMutate: $classes,
->{0}->mutator->toBe(IfNegated::class);
});

it('ignores lines with the ignore annotation when file has LF line endings', function (): void {
$code = "<?php\n\n\$foo = 1;\n\$bar = 2;\nif (\$a > \$b) { // @pest-mutate-ignore: GreaterOrEqualToGreater\n \$a = \$b;\n}\n";

$mutations = ($this->generate)($code, [GreaterOrEqualToGreater::class, IfNegated::class]);

expect($mutations)
->toHaveCount(1)
->{0}->mutator->toBe(IfNegated::class);
});

it('ignores lines with the ignore annotation for multiple mutators', function (): void {
$mutations = ($this->generate)(<<<'PHP'
<?php
Expand Down