respect-validation/src-dev/Commands/SmokeTestsCheckCompleteCommand.php
Alexandre Gomes Gaigalas 3270c1f72c Make all remaining validators serializable
This commit concludes the effort to make all current validators
serializable by fixing the remaining ones.

The ability to use `finfo` instances on some filesystem validators
was removed. `Image` was refactored to be a readonly class.

A command was added to the main `composer qa` flow that checks
if all validators are covered by smoke tests (which are currently
used by benchmarks and serialization tests). Therefore, this commit
also ensures that every validator has a benchmark.
2026-01-19 11:04:35 +00:00

69 lines
2 KiB
PHP

<?php
/*
* Copyright (c) Alexandre Gomes Gaigalas <alganet@gmail.com>
* SPDX-License-Identifier: MIT
*/
declare(strict_types=1);
namespace Respect\Dev\Commands;
use Respect\Validation\Test\SmokeTestProvider;
use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use function array_diff;
use function array_filter;
use function array_keys;
use function array_map;
use function count;
use function dirname;
use function iterator_to_array;
use function lcfirst;
use function scandir;
use function str_ends_with;
use function substr;
#[AsCommand(
name: 'smoke-tests:check-complete',
description: 'Verifies if all validators are included in the SmokeTestProvider',
)]
final class SmokeTestsCheckCompleteCommand extends Command
{
protected function execute(InputInterface $input, OutputInterface $output): int
{
$validatorDir = dirname(__DIR__, 2) . '/library/Validators';
$missingSmokeTests = array_diff(
array_map(
static fn(string $fileName) => lcfirst(substr($fileName, 0, -4)),
array_filter(
scandir($validatorDir),
static fn(string $fileName) => str_ends_with($fileName, '.php'),
),
),
array_map(
lcfirst(...),
array_keys(
iterator_to_array((new class {
use SmokeTestProvider;
})->provideValidatorInput()),
),
),
);
if (count($missingSmokeTests) > 0) {
$output->writeln('The following validators are missing from the SmokeTestProvider:');
foreach ($missingSmokeTests as $validatorName) {
$output->writeln('- ' . $validatorName);
}
return Command::FAILURE;
}
return Command::SUCCESS;
}
}