-
-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Castor tasks and update Infection workflow
This commit introduces a new Castor PHP script with different tasks for test execution, mutation testing, coding standards check, PHPStan, and others. The Infection GitHub workflow was also updated to use the new Castor 'infect' task instead of 'make ci-mu'. The 'Infection' workflow name was also corrected.
- Loading branch information
Showing
3 changed files
with
140 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
use Castor\Attribute\AsTask; | ||
use function Castor\io; | ||
use function Castor\run; | ||
|
||
#[AsTask(description: 'Run mutation testing')] | ||
function infect(int $minMsi = 0, int $minCoveredMsi = 0, bool $ci = false): void | ||
{ | ||
io()->title('Running infection'); | ||
$nproc = run('nproc', quiet: true); | ||
if (! $nproc->isSuccessful()) { | ||
io()->error('Cannot determine the number of processors'); | ||
return; | ||
} | ||
$threads = (int) $nproc->getOutput(); | ||
$command = [ | ||
'php', | ||
'vendor/bin/infection', | ||
sprintf('--min-msi=%s', $minMsi), | ||
sprintf('--min-covered-msi=%s', $minCoveredMsi), | ||
sprintf('--threads=%s', $threads), | ||
]; | ||
if ($ci) { | ||
$command[] = '--logger-github'; | ||
$command[] = '-s'; | ||
} | ||
$environment = [ | ||
'XDEBUG_MODE' => 'coverage', | ||
]; | ||
run($command, environment: $environment); | ||
} | ||
|
||
#[AsTask(description: 'Run tests')] | ||
function test(bool $coverageHtml = false, bool $coverageText = false, null|string $group = null): void | ||
{ | ||
io()->title('Running tests'); | ||
$command = ['php', 'vendor/bin/phpunit', '--color']; | ||
$environment = [ | ||
'XDEBUG_MODE' => 'off', | ||
]; | ||
if ($coverageHtml) { | ||
$command[] = '--coverage-html=build/coverage'; | ||
$environment['XDEBUG_MODE'] = 'coverage'; | ||
} | ||
if ($coverageText) { | ||
$command[] = '--coverage-text'; | ||
$environment['XDEBUG_MODE'] = 'coverage'; | ||
} | ||
if ($group !== null) { | ||
$command[] = sprintf('--group=%s', $group); | ||
} | ||
run($command, environment: $environment); | ||
} | ||
|
||
#[AsTask(description: 'Coding standards check')] | ||
function cs(bool $fix = false): void | ||
{ | ||
io()->title('Running coding standards check'); | ||
$command = ['php', 'vendor/bin/ecs', 'check']; | ||
$environment = [ | ||
'XDEBUG_MODE' => 'off', | ||
]; | ||
if ($fix) { | ||
$command[] = '--fix'; | ||
} | ||
run($command, environment: $environment); | ||
} | ||
|
||
#[AsTask(description: 'Running PHPStan')] | ||
function stan(): void | ||
{ | ||
io()->title('Running PHPStan'); | ||
$command = ['php', 'vendor/bin/phpstan', 'analyse']; | ||
$environment = [ | ||
'XDEBUG_MODE' => 'off', | ||
]; | ||
run($command, environment: $environment); | ||
} | ||
|
||
#[AsTask(description: 'Validate Composer configuration')] | ||
function validate(): void | ||
{ | ||
io()->title('Validating Composer configuration'); | ||
$command = ['composer', 'validate']; | ||
$environment = [ | ||
'XDEBUG_MODE' => 'off', | ||
]; | ||
run($command, environment: $environment); | ||
} | ||
|
||
#[AsTask(description: 'Run Rector')] | ||
function rector(bool $fix = false): void | ||
{ | ||
io()->title('Running Rector'); | ||
$command = ['php', 'vendor/bin/rector', 'process', '--ansi']; | ||
if (! $fix) { | ||
$command[] = '--dry-run'; | ||
} | ||
$environment = [ | ||
'XDEBUG_MODE' => 'off', | ||
]; | ||
run($command, environment: $environment); | ||
} | ||
|
||
#[AsTask(description: 'Run Rector')] | ||
function deptrac(): void | ||
{ | ||
io()->title('Running Rector'); | ||
$command = ['php', 'vendor/bin/deptrac', 'analyse', '--fail-on-uncovered', '--no-cache']; | ||
$environment = [ | ||
'XDEBUG_MODE' => 'off', | ||
]; | ||
run($command, environment: $environment); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
{ | ||
"timeout":20, | ||
"source": { | ||
"directories": [ | ||
"src" | ||
] | ||
}, | ||
"logs": { | ||
"text": "infection.log" | ||
}, | ||
"mutators": { | ||
"@default": true, | ||
"MBString": { | ||
"settings": { | ||
"mb_substr": false, | ||
"mb_strlen": false | ||
} | ||
} | ||
} | ||
} |