1. Go to this page and download the library: Download rasuvaeff/mutation-history library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
rasuvaeff / mutation-history example snippets
doc-exec
use Rasuvaeff\MutationHistory\InfectionLogParser;
use Rasuvaeff\MutationHistory\MutantId;
use Rasuvaeff\QualityLedger\Ledger;
use Rasuvaeff\QualityLedger\LocalFileStorage;
use Rasuvaeff\QualityLedger\RatchetGate;
// Two runs of the same mutant: killed first, escaping afterwards. In real
// use these are the bytes of Infection's own JSON log.
$mutant = [
'mutator' => ['mutatorName' => 'TrueValue', 'originalFilePath' => 'src/RetryPolicy.php', 'originalStartLine' => 42],
'diff' => "@@ -42,1 +42,1 @@\n- return \$this->attempts < \$this->max;\n+ return true;",
];
$before = json_encode(['killed' => [$mutant]]);
$after = json_encode(['escaped' => [$mutant]]);
$parser = new InfectionLogParser();
$ledger = new Ledger(
id: new MutantId(),
storage: new LocalFileStorage(sys_get_temp_dir() . '/mutation-history-readme'),
);
$ledger->append($parser->parse(json: $before, run: 'run-1', ts: 1_700_000_000, scope: 'acme/widgets', metrics: ['msi' => 100.0]));
$ledger->append($parser->parse(json: $after, run: 'run-2', ts: 1_700_003_600, scope: 'acme/widgets', metrics: ['msi' => 50.0]));
$isBad = static fn(string $status): bool => $status === 'escaped';
$diff = $ledger->diff(scope: 'acme/widgets', base: 'run-1', head: 'run-2', isBad: $isBad);
$gate = (new RatchetGate())->evaluate($diff);
count($diff->newBad); // => 1
$gate->ok; // => false
$gate->regressions[0]->meta['file']; // => 'src/RetryPolicy.php'
$ledger->trend(scope: 'acme/widgets', metric: 'msi')->points[1]->value; // => 50.0