Phred/tests/MakeCommandTest.php

42 lines
1.3 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 MakeCommandTest extends TestCase
{
private string $createdPath;
protected function tearDown(): void
{
if ($this->createdPath && is_file($this->createdPath)) {
@unlink($this->createdPath);
}
}
public function testMakeCommandCreatesFileAndIsDiscovered(): void
{
$root = dirname(__DIR__);
$target = $root . '/console/commands/HelloWorld.php';
if (is_file($target)) {
@unlink($target);
}
$cmd = 'php ' . escapeshellarg($root . '/bin/phred') . ' create:command hello:world';
2025-12-14 23:10:01 +00:00
$output = shell_exec($cmd) ?: '';
$this->assertStringContainsString('created', $output, 'Expected creation message');
$this->createdPath = $target;
$this->assertFileExists($target, 'Scaffolded command file should exist');
$contents = @file_get_contents($target) ?: '';
$this->assertStringContainsString("protected string \$command = 'hello:world';", $contents);
// And the new command should be listed by the CLI
$listOut = shell_exec('php ' . escapeshellarg($root . '/bin/phred') . ' list') ?: '';
$this->assertStringContainsString('hello:world', $listOut);
}
}