respect-validation/src-dev/Commands/SmokeTestsCheckCompleteCommand.php
Henrique Moody 140bd36aa3
Rename library/ to src/
We've always considered renaming this directory, as it's not a common
standard to name `library` the directory where the source code of a
library it. Having it as `src/` is a common pattern we find in several
PHP libraries these days.

Acked-by: Alexandre Gomes Gaigalas <alganet@gmail.com>
2026-01-22 13:13:15 +01:00

70 lines
2 KiB
PHP

<?php
/*
* SPDX-License-Identifier: MIT
* SPDX-FileCopyrightText: (c) Respect Project Contributors
* SPDX-FileContributor: Alexandre Gomes Gaigalas <alganet@gmail.com>
*/
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) . '/src/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;
}
}