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; } }; } }