61 lines
2.1 KiB
PHP
Executable File
61 lines
2.1 KiB
PHP
Executable File
<?php
|
|
|
|
namespace App\Console\Commands;
|
|
|
|
use Symfony\Component\Console\Command\Command;
|
|
use Symfony\Component\Console\Input\InputArgument;
|
|
use Symfony\Component\Console\Input\InputInterface;
|
|
use Symfony\Component\Console\Output\OutputInterface;
|
|
use Symfony\Component\Console\Style\SymfonyStyle;
|
|
|
|
class ModuleTestCommand extends Command
|
|
{
|
|
protected static $defaultName = 'module:test';
|
|
|
|
protected function configure()
|
|
{
|
|
$this
|
|
->setDescription('Executa testes automatizados para um módulo específico')
|
|
->addArgument('name', InputArgument::REQUIRED, 'Nome do módulo');
|
|
}
|
|
|
|
protected function execute(InputInterface $input, OutputInterface $output): int
|
|
{
|
|
$io = new SymfonyStyle($input, $output);
|
|
$moduleName = strtolower($input->getArgument('name'));
|
|
$modulePath = dirname(dirname(dirname(__DIR__))) . '/modules/' . $moduleName;
|
|
|
|
if (!is_dir($modulePath)) {
|
|
$io->error("Módulo '{$moduleName}' não encontrado em {$modulePath}");
|
|
return Command::FAILURE;
|
|
}
|
|
|
|
$testPath = $modulePath . '/tests';
|
|
if (!is_dir($testPath)) {
|
|
$io->warning("O módulo '{$moduleName}' não possui uma pasta de testes em {$testPath}.");
|
|
return Command::INVALID;
|
|
}
|
|
|
|
$io->title("Iniciando testes para o módulo: " . ucfirst($moduleName));
|
|
|
|
// Execute PHPUnit pointing to the module's test directory
|
|
// Using vendor/bin/phpunit which is standard for the project
|
|
$phpunitExec = dirname(dirname(dirname(__DIR__))) . '/vendor/bin/phpunit';
|
|
|
|
// We use the full path to phpunit to avoid command not found issues
|
|
$command = "php \"{$phpunitExec}\" \"{$testPath}\"";
|
|
|
|
$io->note("Executando: {$command}");
|
|
|
|
passthru($command, $exitCode);
|
|
|
|
if ($exitCode === 0) {
|
|
$io->success("Todos os testes do módulo '{$moduleName}' passaram!");
|
|
} else {
|
|
$io->error("Falha nos testes do módulo '{$moduleName}'.");
|
|
}
|
|
|
|
return $exitCode === 0 ? Command::SUCCESS : Command::FAILURE;
|
|
}
|
|
}
|