1
0
Fork 0

Do not output script being run when running via composer <script-name> (#12383)

* Do not output script being run when running via composer <script-name>

Fixes #12375

* Fix global test expectations
main
Jordi Boggiano 2025-04-16 13:38:39 +02:00 committed by GitHub
parent 1ff5c7cf1b
commit 29e47ed68c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 10 additions and 7 deletions

View File

@ -346,8 +346,12 @@ class EventDispatcher
if ($this->io->isVerbose()) {
$this->io->writeError(sprintf('> %s: %s', $event->getName(), $exec));
} elseif ($event->getName() !== '__exec_command') {
} elseif (
// do not output the command being run when using `composer exec` as it is fairly obvious the user is running it
$event->getName() !== '__exec_command'
// do not output the command being run when using `composer <script-name>` as it is also fairly obvious the user is running it
&& ($event->getFlags()['script-alias-input'] ?? null) === null
) {
$this->io->writeError(sprintf('> %s', $exec));
}

View File

@ -23,10 +23,10 @@ class GlobalCommandTest extends TestCase
Platform::clearEnv('COMPOSER_HOME');
Platform::clearEnv('COMPOSER');
}
public function testGlobal(): void
{
$script = '@php -r \'echo getenv("COMPOSER") . PHP_EOL;\'';
$script = '@php -r "echo \'COMPOSER SCRIPT OUTPUT: \'.getenv(\'COMPOSER\') . PHP_EOL;"';
$fakeComposer = 'TMP_COMPOSER.JSON';
$composerHome = $this->initTempComposer(
[
@ -51,12 +51,11 @@ class GlobalCommandTest extends TestCase
$display = $appTester->getDisplay(true);
self::assertStringContainsString(
'Changed current directory to ' . $composerHome,
self::assertSame(
'Changed current directory to ' . $composerHome . "\n".
"COMPOSER SCRIPT OUTPUT: \n",
$display
);
self::assertStringContainsString($script, $display);
self::assertStringNotContainsString($fakeComposer, $display, '$COMPOSER is not unset by global command');
}
public function testCannotCreateHome(): void