Skip to content

Commit

Permalink
Add Castor tasks and update Infection workflow
Browse files Browse the repository at this point in the history
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
Spomky committed Apr 13, 2024
1 parent 4de637a commit 13298f1
Show file tree
Hide file tree
Showing 3 changed files with 140 additions and 2 deletions.
5 changes: 3 additions & 2 deletions .github/workflows/infection.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# yaml-language-server: $schema=https://json.schemastore.org/github-workflow

name: "Integrate"
name: "Infection"

on:
push:
Expand All @@ -18,6 +18,7 @@ jobs:
php-version: "8.3"
extensions: "ctype, dom, json, libxml, mbstring, openssl, phar, simplexml, tokenizer, xml, xmlwriter"
coverage: "xdebug"
tools: castor

- name: "Checkout code"
uses: "actions/checkout@v3"
Expand All @@ -32,4 +33,4 @@ jobs:
composer-options: "--optimize-autoloader"

- name: "Execute Infection"
run: "make ci-mu"
run: "castor infect --ci"
117 changes: 117 additions & 0 deletions castor.php
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);
}
20 changes: 20 additions & 0 deletions infection.json
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
}
}
}
}

0 comments on commit 13298f1

Please sign in to comment.