mirror of
https://gitee.com/zoujingli/ThinkAdmin.git
synced 2026-06-07 04:28:11 +08:00
将 v8 重构分支中残留的 ThinkAdminDeveloper 文本统一调整为 ThinkAdmin,避免迁移到主仓库后继续暴露旧开发仓库名称。 主要内容: - 更新 README 标题与项目描述。 - 统一 PHP 文件头注释中的项目标识。 - 同步调整测试、配置、插件与文档中的旧仓库名称文本。 - 保持旧包删除说明与架构边界测试语义不变,只清理品牌名称残留。
134 lines
4.8 KiB
PHP
134 lines
4.8 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
/**
|
|
* +----------------------------------------------------------------------
|
|
* | ThinkAdmin Plugin
|
|
* +----------------------------------------------------------------------
|
|
* | Copyright (c) 2014~2026 ThinkAdmin [ thinkadmin.top ]
|
|
* +----------------------------------------------------------------------
|
|
* | Official Website: https://thinkadmin.top
|
|
* +----------------------------------------------------------------------
|
|
* | Licensed: https://mit-license.org
|
|
* | Disclaimer: https://thinkadmin.top/disclaimer
|
|
* | Vip Rights: https://thinkadmin.top/vip-introduce
|
|
* +----------------------------------------------------------------------
|
|
* | Gitee Repository: https://gitee.com/zoujingli/ThinkAdmin
|
|
* | Github Repository: https://github.com/zoujingli/ThinkAdmin
|
|
* +----------------------------------------------------------------------
|
|
*/
|
|
|
|
namespace plugin\install\tests;
|
|
|
|
use PHPUnit\Framework\TestCase;
|
|
use plugin\install\command\project\InstallCommand;
|
|
use think\App;
|
|
use think\console\Command;
|
|
use think\console\Input;
|
|
use think\console\input\Option;
|
|
use think\console\Output;
|
|
|
|
/**
|
|
* @internal
|
|
* @coversNothing
|
|
*/
|
|
class InstallCommandTest extends TestCase
|
|
{
|
|
public function testRunDiscoversServicesThenPublishesWithFlags(): void
|
|
{
|
|
$root = sys_get_temp_dir() . '/thinkadmin-install-command-' . bin2hex(random_bytes(6));
|
|
mkdir($root, 0777, true);
|
|
file_put_contents($root . '/think', "#!/usr/bin/env php\n");
|
|
|
|
$app = new App($root);
|
|
$console = $this->createConsole($app, 23);
|
|
$app->instance('console', $console);
|
|
|
|
$command = new InstallCommand();
|
|
$command->setApp($app);
|
|
|
|
$status = $command->run(new Input(['--force', '--migrate']), new Output('buffer'));
|
|
|
|
$this->assertSame(23, $status);
|
|
$this->assertSame([
|
|
['service:discover', []],
|
|
['xadmin:publish', ['--force', '--migrate']],
|
|
], $console->calls);
|
|
}
|
|
|
|
public function testRunSkipsMigrateWhenNoPluginDeclaresMigration(): void
|
|
{
|
|
$root = sys_get_temp_dir() . '/thinkadmin-install-command-' . bin2hex(random_bytes(6));
|
|
mkdir($root . '/vendor/composer', 0777, true);
|
|
file_put_contents($root . '/think', "#!/usr/bin/env php\n");
|
|
file_put_contents($root . '/vendor/composer/installed.json', json_encode(['packages' => []], JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES));
|
|
|
|
$app = new App($root);
|
|
$console = $this->createConsole($app);
|
|
$app->instance('console', $console);
|
|
|
|
$command = new InstallCommand();
|
|
$command->setApp($app);
|
|
|
|
$status = $command->run(new Input([]), new Output('buffer'));
|
|
|
|
$this->assertSame(0, $status);
|
|
$this->assertSame([
|
|
['service:discover', []],
|
|
['xadmin:publish', []],
|
|
], $console->calls);
|
|
}
|
|
|
|
private function createConsole(App $app, int $publishStatus = 0): object
|
|
{
|
|
return new class($app, $publishStatus) {
|
|
public array $calls = [];
|
|
|
|
public function __construct(private readonly App $app, private readonly int $publishStatus)
|
|
{
|
|
}
|
|
|
|
public function find(string $name): Command
|
|
{
|
|
$command = new class($this, $name, $name === 'xadmin:publish' ? $this->publishStatus : 0) extends Command {
|
|
public function __construct(
|
|
private readonly object $owner,
|
|
private readonly string $commandName,
|
|
private readonly int $status
|
|
) {
|
|
parent::__construct();
|
|
}
|
|
|
|
protected function configure()
|
|
{
|
|
$this->setName($this->commandName);
|
|
if ($this->commandName === 'xadmin:publish') {
|
|
$this->addOption('force', 'f', Option::VALUE_NONE);
|
|
$this->addOption('migrate', 'm', Option::VALUE_NONE);
|
|
}
|
|
}
|
|
|
|
protected function execute(Input $input, Output $output): int
|
|
{
|
|
$arguments = [];
|
|
if ($this->commandName === 'xadmin:publish') {
|
|
if ($input->getOption('force')) {
|
|
$arguments[] = '--force';
|
|
}
|
|
if ($input->getOption('migrate')) {
|
|
$arguments[] = '--migrate';
|
|
}
|
|
}
|
|
|
|
$this->owner->calls[] = [$this->commandName, $arguments];
|
|
return $this->status;
|
|
}
|
|
};
|
|
|
|
$command->setApp($this->app);
|
|
return $command;
|
|
}
|
|
};
|
|
}
|
|
}
|