<?php

use App\Services\Command;

it('loads project env values and compose file overrides from the current working directory', function () {
    $projectDir = sys_get_temp_dir() . '/probots-cli-env-' . bin2hex(random_bytes(5));
    mkdir($projectDir, 0777, true);
    file_put_contents($projectDir . '/.env', "THEME_NAME=theme\nCLI_COMPOSE_FILES=docker-compose.yml,../workspace/docker-compose.workspace.yml\n");

    $cwd = getcwd();
    chdir($projectDir);

    try {
        new class extends Command {
            protected $signature = 'test:dummy';

            public function handle(): void
            {
            }
        };
    } finally {
        chdir($cwd);
    }

    expect(config('project.env')->get('THEME_NAME'))->toBe('theme');
    expect(config('project.compose_files'))->toBe(['docker-compose.yml', '../workspace/docker-compose.workspace.yml']);

    unlink($projectDir . '/.env');
    rmdir($projectDir);
});
