<?php

namespace Tests\Feature;

use Tests\TestCase;

class OctaneInstallationTest extends TestCase
{
    /**
     * 测试 Octane 配置是否正确加载
     */
    public function test_octane_configuration_is_loaded_correctly(): void
    {
        // 验证 Octane 服务器配置为 swoole
        $this->assertEquals('swoole', config('octane.server'));
        
        // 验证配置文件包含正确的默认值
        $this->assertIsArray(config('octane.listeners'));
        $this->assertIsArray(config('octane.warm'));
        $this->assertIsArray(config('octane.tables'));
        $this->assertIsArray(config('octane.cache'));
        $this->assertIsArray(config('octane.watch'));
    }

    /**
     * 测试 Octane 命令是否可用
     */
    public function test_octane_commands_are_available(): void
    {
        // 测试 octane:status 命令存在
        $this->artisan('octane:status')
            ->assertExitCode(1); // 服务器未运行时返回 1
    }

    /**
     * 测试 Laravel Octane 包是否正确安装
     */
    public function test_octane_package_is_installed(): void
    {
        // 检查配置文件是否存在
        $this->assertFileExists(config_path('octane.php'));
        
        // 检查 Octane 相关类是否可用
        $this->assertTrue(class_exists(\Laravel\Octane\Octane::class));
        $this->assertTrue(class_exists(\Laravel\Octane\OctaneServiceProvider::class));
    }

    /**
     * 测试 Composer 脚本是否包含 Octane 支持
     */
    public function test_composer_scripts_include_octane_support(): void
    {
        $composerJson = json_decode(file_get_contents(base_path('composer.json')), true);
        
        // 验证 dev-octane 脚本存在
        $this->assertArrayHasKey('dev-octane', $composerJson['scripts']);
        
        // 验证脚本包含 octane:start 命令
        $devOctaneScript = implode(' ', $composerJson['scripts']['dev-octane']);
        $this->assertStringContainsString('octane:start', $devOctaneScript);
    }
}