diff --git a/src/Support/MutationGenerator.php b/src/Support/MutationGenerator.php index cebc859..1f241ef 100644 --- a/src/Support/MutationGenerator.php +++ b/src/Support/MutationGenerator.php @@ -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:')); diff --git a/tests/Unit/MutationGeneratorTest.php b/tests/Unit/MutationGeneratorTest.php index 79c67ed..84e94b0 100644 --- a/tests/Unit/MutationGeneratorTest.php +++ b/tests/Unit/MutationGeneratorTest.php @@ -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 = " \$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'