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
25 changes: 8 additions & 17 deletions docs/mutation-testing.md
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,7 @@ The following options are available.
- [`mutator()`](#mutator)
- [`except()`](#except)
- [`coveredOnly()`](#coveredOnly)
- [`uncommittedOnly()`](#uncommittedOnly)
- [`changedOnly()`](#changedOnly)
- [`changed()`](#changed)
- [`stopOnEscaped()`](#stopOnEscaped)
- [`stopOnNotCovered()`](#stopOnNotCovered)
- [`bail()`](#bail)
Expand Down Expand Up @@ -234,27 +233,19 @@ mutate()
```


<a name="options-uncommitted-only"></a>
### `uncommittedOnly()`
CLI: `--uncommitted-only`
<a name="options-changed"></a>
### `changed()`
CLI: `--changed`

Limit mutations to code that has uncommitted changes.
Only mutate the files a change since the given git revision can affect: the source files that changed, and the code the changed test files cover or run. Without a revision, only uncommitted changes count; with one, everything since HEAD forked from it does. When a file every test depends on changes, such as a fixture or `composer.lock`, everything is mutated; a support file like `tests/Pest.php` that only gained functions doesn't count.

```php
mutate()
->uncommittedOnly();
->changed(); // or ->changed('origin/main');
```


<a name="options-changed-only"></a>
### `changedOnly()`
CLI: `--changed-only`

Limit mutations to code that has changed relative to a common ancestor of the given branch (defaults to `main`).

```php
mutate()
->changedOnly(); // or ->changedOnly('add-xyz');
```bash
vendor/bin/pest --mutate --changed=origin/main
```


Expand Down
3 changes: 3 additions & 0 deletions src/Contracts/Printer.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Pest\Mutate\MutationSuite;
use Pest\Mutate\MutationTest;
use Pest\Mutate\MutationTestCollection;
use Pest\Mutate\Support\ChangedScope;

interface Printer
{
Expand All @@ -26,6 +27,8 @@ public function reportScoreNotReached(float $scoreReached, float $scoreRequired)

public function printFilename(MutationTestCollection $testCollection): void;

public function reportChangedScope(ChangedScope $scope): void;

public function reportMutationGenerationStarted(MutationSuite $mutationSuite): void;

public function reportMutationGenerationFinished(MutationSuite $mutationSuite): void;
Expand Down
28 changes: 28 additions & 0 deletions src/Options/ChangedOption.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

declare(strict_types=1);

namespace Pest\Mutate\Options;

use Symfony\Component\Console\Input\InputOption;

class ChangedOption
{
final public const string ARGUMENT = 'changed';

public static function remove(): bool
{
return true;
}

public static function match(string $argument): bool
{
return $argument === sprintf('--%s', self::ARGUMENT) ||
str_starts_with($argument, sprintf('--%s=', self::ARGUMENT));
}

public static function inputOption(): InputOption
{
return new InputOption(sprintf('--%s', self::ARGUMENT), null, InputOption::VALUE_OPTIONAL, '');
}
}
1 change: 1 addition & 0 deletions src/Repositories/ConfigurationRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ classes: $config['classes'] ?? [],
mutationId: $config['mutation_id'] ?? null,
retry: $config['retry'] ?? false,
everything: $config['everything'] ?? false,
changed: $config['changed'] ?? null,
);
}

Expand Down
Loading