<?php

namespace Kylin\Modules\Tests\Feature;

use Illuminate\Filesystem\Filesystem;
use Kylin\Modules\Tests\TestCase;

/**
 * 模块创建命令测试
 *
 * 测试 module:make 命令的功能
 */
class ModuleMakeCommandTest extends TestCase
{
    /**
     * 文件系统实例
     */
    protected Filesystem $files;

    /**
     * 设置测试环境
     */
    protected function setUp(): void
    {
        parent::setUp();

        $this->files = $this->app->make(Filesystem::class);
    }

    /**
     * 清理测试环境
     */
    protected function tearDown(): void
    {
        // 清理测试模块
        $testModulePath = base_path('packages/test-module');

        if ($this->files->exists($testModulePath)) {
            $this->files->deleteDirectory($testModulePath);
        }

        parent::tearDown();
    }

    /**
     * 测试 module:make 命令可以创建新模块
     */
    public function testModuleMakeCommandCanCreateNewModule(): void
    {
        // 运行 module:make 命令
        $this->artisan('module:make', [
            'name' => 'test-module',
        ])->assertExitCode(0);

        // 检查模块目录是否创建
        $modulePath = base_path('packages/test-module');

        $this->assertTrue($this->files->exists($modulePath));
        $this->assertTrue($this->files->exists($modulePath . '/composer.json'));
        $this->assertTrue($this->files->exists($modulePath . '/app'));
        $this->assertTrue($this->files->exists($modulePath . '/routes'));
        $this->assertTrue($this->files->exists($modulePath . '/resources'));
    }
}

