From f74370aabdda39db25976c2ee73c504d547981c5 Mon Sep 17 00:00:00 2001 From: Olivier Gorzalka Date: Wed, 30 Sep 2026 15:52:26 +0200 Subject: [PATCH] fix: pass --no-interaction on to the artisan commands pollora new runs --- src/Commands/NewCommand.php | 21 ++++++++++++++++----- tests/Unit/Commands/NewCommandTest.php | 16 ++++++++++++++++ 2 files changed, 32 insertions(+), 5 deletions(-) diff --git a/src/Commands/NewCommand.php b/src/Commands/NewCommand.php index 0c80669..6756420 100644 --- a/src/Commands/NewCommand.php +++ b/src/Commands/NewCommand.php @@ -342,6 +342,21 @@ private function runArtisanInstall(string $phpPrefix): self return $this->runArtisan($phpPrefix, 'pollora:install', 'Running pollora:install...'); } + /** + * The shell command that runs an artisan command in the new project. + * + * `pollora new --no-interaction` passes the flag on: the artisan command + * gets a terminal from here, so without it pollora:install would prompt + * anyway — or, with no terminal at all, fall back to its defaults. + */ + private function artisanCommandLine(string $phpPrefix, string $artisanCommand): string + { + $php = str_starts_with($phpPrefix, 'ddev') ? 'ddev exec php' : $phpPrefix; + $flags = $this->input->isInteractive() ? '' : ' --no-interaction'; + + return $php.' artisan '.$artisanCommand.$flags; + } + /** * Run an artisan command with a terminal attached, so that its prompts work. */ @@ -351,11 +366,7 @@ private function runArtisan(string $phpPrefix, string $artisanCommand, string $m $this->output->writeln(' '.$message.''); $this->output->writeln(''); - $isDdev = str_starts_with($phpPrefix, 'ddev'); - - $command = ($isDdev ? 'ddev exec php' : $phpPrefix).' artisan '.$artisanCommand; - - $process = Process::fromShellCommandline($command, $this->absolutePath); + $process = Process::fromShellCommandline($this->artisanCommandLine($phpPrefix, $artisanCommand), $this->absolutePath); $process->setTimeout(null); // Set TERM=dumb on the HOST side to prevent the terminal emulator diff --git a/tests/Unit/Commands/NewCommandTest.php b/tests/Unit/Commands/NewCommandTest.php index d9d6984..c38806b 100644 --- a/tests/Unit/Commands/NewCommandTest.php +++ b/tests/Unit/Commands/NewCommandTest.php @@ -4,6 +4,7 @@ use Pollora\Cli\Application; use Pollora\Cli\Commands\NewCommand; +use Symfony\Component\Console\Input\ArrayInput; use Symfony\Component\Console\Output\BufferedOutput; use Symfony\Component\Console\Tester\CommandTester; @@ -113,6 +114,7 @@ $command = newCommandWith(''); (new ReflectionProperty($command, 'absolutePath'))->setValue($command, $dir); (new ReflectionProperty($command, 'output'))->setValue($command, new BufferedOutput); + (new ReflectionProperty($command, 'input'))->setValue($command, new ArrayInput([])); // `false artisan pollora:install` exits 1, standing in for a failed install. $run = fn (): mixed => (new ReflectionMethod($command, 'runArtisan')) @@ -219,3 +221,17 @@ function prepareEnvironmentFileIn(string $directory): ?string return $path; } + +it('passes --no-interaction on to artisan when it was given one', function (bool $interactive, string $expected): void { + $command = newCommandWith(''); + $input = new ArrayInput([]); + $input->setInteractive($interactive); + (new ReflectionProperty($command, 'input'))->setValue($command, $input); + + $line = (new ReflectionMethod($command, 'artisanCommandLine'))->invoke($command, 'ddev exec php', 'pollora:install'); + + expect($line)->toBe($expected); +})->with([ + 'interactive' => [true, 'ddev exec php artisan pollora:install'], + 'no interaction' => [false, 'ddev exec php artisan pollora:install --no-interaction'], +]);