Skip to content

Commit

Permalink
Add sprintf imports and update dependencies and baselines (#668)
Browse files Browse the repository at this point in the history
* Add `sprintf` imports and update dependencies and baselines

This commit introduces `sprintf` imports across various files for consistency and resolves potential missing imports. Additionally, it updates dependency versions in `composer.json`, allowing support for newer releases, and updates the PHPStan baseline to reflect these changes and new ignored error patterns. Some minor formatting issues in method chaining were also fixed.

* Refactor test configuration and improve error handling.

Updated PHPUnit environment settings to adjust deprecations handling and removed outdated entries in phpstan-baseline. Additionally, added a Symfony error handler in the test bootstrap for better exception management.
  • Loading branch information
Spomky authored Jan 3, 2025
1 parent 00e620f commit 5a43790
Show file tree
Hide file tree
Showing 51 changed files with 1,140 additions and 410 deletions.
103 changes: 64 additions & 39 deletions castor.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Castor\Attribute\AsOption;
use Castor\Attribute\AsTask;
use function Castor\context;
use function Castor\io;
use function Castor\run;

Expand All @@ -28,32 +29,42 @@ function infect(int $minMsi = 0, int $minCoveredMsi = 0, bool $ci = false): void
$command[] = '--logger-github';
$command[] = '-s';
}
$environment = [
'XDEBUG_MODE' => 'coverage',
];
run($command, environment: $environment);

$context = context()
->withEnvironment([
'XDEBUG_MODE' => 'coverage',
])
;
run($command, context: $context);
}

#[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',
];

$context = context()
->withEnvironment([
'XDEBUG_MODE' => 'off',
])
;
if ($coverageHtml) {
$command[] = '--coverage-html=build/coverage';
$environment['XDEBUG_MODE'] = 'coverage';
$context = $context->withEnvironment([
'XDEBUG_MODE' => 'coverage',
]);
}
if ($coverageText) {
$command[] = '--coverage-text';
$environment['XDEBUG_MODE'] = 'coverage';
$context = $context->withEnvironment([
'XDEBUG_MODE' => 'coverage',
]);
}
if ($group !== null) {
$command[] = sprintf('--group=%s', $group);
}
run($command, environment: $environment);
run($command, context: $context);
}

#[AsTask(description: 'Coding standards check')]
Expand All @@ -65,16 +76,18 @@ function cs(
): void {
io()->title('Running coding standards check');
$command = ['php', 'vendor/bin/ecs', 'check'];
$environment = [
'XDEBUG_MODE' => 'off',
];
$context = context()
->withEnvironment([
'XDEBUG_MODE' => 'off',
])
;
if ($fix) {
$command[] = '--fix';
}
if ($clearCache) {
$command[] = '--clear-cache';
}
run($command, environment: $environment);
run($command, context: $context);
}

#[AsTask(description: 'Running PHPStan')]
Expand All @@ -85,24 +98,28 @@ function stan(bool $baseline = false): void
if ($baseline) {
$command[] = '--generate-baseline';
}
$environment = [
'XDEBUG_MODE' => 'off',
];
run($command, environment: $environment);
$context = context()
->withEnvironment([
'XDEBUG_MODE' => 'off',
])
;
run($command, context: $context);
}

#[AsTask(description: 'Validate Composer configuration')]
function validate(): void
{
io()->title('Validating Composer configuration');
$command = ['composer', 'validate', '--strict'];
$environment = [
'XDEBUG_MODE' => 'off',
];
run($command, environment: $environment);
$context = context()
->withEnvironment([
'XDEBUG_MODE' => 'off',
])
;
run($command, context: $context);

$command = ['composer', 'dump-autoload', '--optimize', '--strict-psr'];
run($command, environment: $environment);
run($command, context: $context);
}

/**
Expand All @@ -115,10 +132,12 @@ function checkLicenses(
io()->title('Checking licenses');
$allowedExceptions = [];
$command = ['composer', 'licenses', '-f', 'json'];
$environment = [
'XDEBUG_MODE' => 'off',
];
$result = run($command, environment: $environment, quiet: true);
$context = context()
->withEnvironment([
'XDEBUG_MODE' => 'off',
])
;
$result = run($command, context: $context, quiet: true);
if (! $result->isSuccessful()) {
io()->error('Cannot determine licenses');
exit(1);
Expand Down Expand Up @@ -178,32 +197,38 @@ function rector(
if ($clearCache) {
$command[] = '--clear-cache';
}
$environment = [
'XDEBUG_MODE' => 'off',
];
run($command, environment: $environment);
$context = context()
->withEnvironment([
'XDEBUG_MODE' => 'off',
])
;
run($command, context: $context);
}

#[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);
$context = context()
->withEnvironment([
'XDEBUG_MODE' => 'off',
])
;
run($command, context: $context);
}

#[AsTask(description: 'Run Linter')]
function lint(): void
{
io()->title('Running Linter');
$command = ['composer', 'exec', '--', 'parallel-lint', __DIR__ . '/src/', __DIR__ . '/tests/'];
$environment = [
'XDEBUG_MODE' => 'off',
];
run($command, environment: $environment);
$context = context()
->withEnvironment([
'XDEBUG_MODE' => 'off',
])
;
run($command, context: $context);
}

#[AsTask(description: 'Run JS tests')]
Expand Down
31 changes: 15 additions & 16 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -91,38 +91,37 @@
"doctrine/dbal": "^3.8|^4.0",
"doctrine/doctrine-bundle": "^2.12",
"doctrine/orm": "^2.14|^3.0",
"doctrine/persistence": "^3.1",
"ekino/phpstan-banned-code": "^1.0 || ^2.0",
"doctrine/persistence": "^3.1|^4.0",
"ekino/phpstan-banned-code": "^3.0",
"infection/infection": "^0.29",
"matthiasnoback/symfony-dependency-injection-test": "^5.1 || ^6.0",
"matthiasnoback/symfony-dependency-injection-test": "^5.1|^6.0",
"php-parallel-lint/php-parallel-lint": "^1.3",
"phpstan/extension-installer": "^1.3",
"phpstan/phpstan": "^1.8",
"phpstan/phpstan-deprecation-rules": "^1.0",
"phpstan/phpstan-doctrine": "^1.4",
"phpstan/phpstan-phpunit": "^1.4",
"phpstan/phpstan-strict-rules": "^1.4",
"phpstan/phpstan-symfony": "^1.4",
"phpunit/phpunit": "^10.1|^11.0",
"phpstan/extension-installer": "^1.4",
"phpstan/phpstan": "^2.0",
"phpstan/phpstan-deprecation-rules": "^2.0",
"phpstan/phpstan-doctrine": "^2.0",
"phpstan/phpstan-phpunit": "^2.0",
"phpstan/phpstan-strict-rules": "^2.0",
"phpstan/phpstan-symfony": "^2.0",
"phpunit/phpunit": "^11.5",
"psr/http-client": "^1.0",
"psr/http-factory": "^1.1",
"psr/http-message": "^2.0",
"qossmic/deptrac": "^2.0",
"rector/rector": "^1.0",
"rector/rector": "^2.0",
"roave/security-advisories": "dev-latest",
"staabm/phpstan-todo-by": "^0.1.27",
"struggle-for-php/sfp-phpstan-psr-log": "^0.21.0 || ^0.22.0",
"staabm/phpstan-todo-by": "^0.2",
"struggle-for-php/sfp-phpstan-psr-log": "^0.23",
"symfony/asset": "^6.4|^7.0",
"symfony/asset-mapper": "^6.4|^7.0",
"symfony/browser-kit": "^6.4|^7.0",
"symfony/filesystem": "^6.4|^7.0",
"symfony/finder": "^6.4|^7.0",
"symfony/monolog-bundle": "^3.8",
"symfony/phpunit-bridge": "^6.4|^7.0",
"symfony/var-dumper": "^6.4|^7.0",
"symfony/yaml": "^6.4|^7.0",
"symplify/easy-coding-standard": "^12.0",
"web-token/jwt-library": "^3.4|^4.0"
"web-token/jwt-library": "^4.0"
},
"extra": {
"thanks": {
Expand Down
Loading

0 comments on commit 5a43790

Please sign in to comment.