Phred/tests/MakeCommandTest.php
Funky Waddle fd1c9d23df refactor(core): enforce SOLID across HTTP pipeline; add small contracts and defaults; align tests
- Introduce small interfaces and default adapters (DIP):
  - Support\Contracts\ConfigInterface + Support\DefaultConfig
  - Http\Contracts\ErrorFormatNegotiatorInterface + Http\Support\DefaultErrorFormatNegotiator
  - Http\Contracts\RequestIdProviderInterface + Http\Support\DefaultRequestIdProvider
  - Http\Contracts\ExceptionToStatusMapperInterface + Http\Support\DefaultExceptionToStatusMapper
- Kernel: bind new contracts in the container; keep DelegatingApiResponseFactory wiring
- ContentNegotiationMiddleware: depend on ConfigInterface + negotiator; honor Accept for JSON:API
- ProblemDetailsMiddleware: inject negotiator + config; split into small helpers; deterministic content negotiation; stable Whoops HTML; include X-Request-Id
- DispatchMiddleware: SRP refactor into small methods; remove hidden coupling; normalize non-Response returns
- Add/adjust tests:
  - tests/ErrorHandlingTest.php for problem details, JSON:API errors, and Whoops HTML
  - tests/ContentNegotiationTest.php for format selection
  - tests/MakeCommandTest.php aligned with create:command scaffolder
- Docs/Meta: update README and MILESTONES; .gitignore to ignore .junie.json

No runtime behavior changes intended beyond clearer DI boundaries and content-negotiation determinism. All tests green.
2025-12-15 09:15:49 -06:00

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') . ' create: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);
}
}