42 lines
1.3 KiB
PHP
42 lines
1.3 KiB
PHP
|
|
<?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') . ' make:command hello:world';
|
||
|
|
$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);
|
||
|
|
}
|
||
|
|
}
|