Phred/tests/CommandDiscoveryTest.php

50 lines
1.4 KiB
PHP
Raw Normal View History

2025-12-14 23:10:01 +00:00
<?php
declare(strict_types=1);
namespace Phred\Tests;
use PHPUnit\Framework\TestCase;
final class CommandDiscoveryTest extends TestCase
{
private string $userCmdPath;
protected function setUp(): void
{
$root = dirname(__DIR__);
$consoleDir = $root . '/console/commands';
if (!is_dir($consoleDir)) {
@mkdir($consoleDir, 0777, true);
}
$this->userCmdPath = $consoleDir . '/_DummyDiscoveryCmd.php';
$cmd = <<<'PHP'
<?php
use Phred\Console\Command;
use Symfony\Component\Console\Input\InputInterface as Input;
use Symfony\Component\Console\Output\OutputInterface as Output;
return new class extends Command {
protected string $command = 'dummy:discovery';
protected string $description = 'Dummy user command for discovery test';
public function handle(Input $i, Output $o): int { $o->writeln('ok'); return 0; }
};
PHP;
@file_put_contents($this->userCmdPath, $cmd);
}
protected function tearDown(): void
{
if (is_file($this->userCmdPath)) {
@unlink($this->userCmdPath);
}
}
public function testUserCommandIsDiscovered(): void
{
$root = dirname(__DIR__);
$cmd = 'php ' . escapeshellarg($root . '/bin/phred') . ' list';
$output = shell_exec($cmd) ?: '';
$this->assertStringContainsString('dummy:discovery', $output, 'User command from console/commands should be discovered');
}
}