1
0
Fork 0
mirror of https://github.com/composer/composer synced 2025-05-09 00:22:53 +00:00

Add a way to control which scripts get args and where (#12086)

Add support for `@no_additional_args` and `@additional_args` tags inside script handlers.
This commit is contained in:
Jordi Boggiano 2024-09-18 14:44:55 +02:00 committed by GitHub
parent 8bc8c4383a
commit 17930441a1
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 96 additions and 5 deletions

View file

@ -311,6 +311,51 @@ class EventDispatcherTest extends TestCase
}
}
public function testDispatcherSupportForAdditionalArgs(): void
{
$process = $this->getProcessExecutorMock();
$dispatcher = $this->getMockBuilder('Composer\EventDispatcher\EventDispatcher')
->setConstructorArgs([
$this->createComposerInstance(),
$io = new BufferIO('', OutputInterface::VERBOSITY_VERBOSE),
$process,
])
->onlyMethods([
'getListeners',
])
->getMock();
$reflMethod = new \ReflectionMethod($dispatcher, 'getPhpExecCommand');
if (PHP_VERSION_ID < 80100) {
$reflMethod->setAccessible(true);
}
$phpCmd = $reflMethod->invoke($dispatcher);
$args = ProcessExecutor::escape('ARG').' '.ProcessExecutor::escape('ARG2').' '.ProcessExecutor::escape('--arg');
$process->expects([
'echo -n foo',
$phpCmd.' foo.php '.$args.' then the rest',
'echo -n bar '.$args,
], true);
$listeners = [
'echo -n foo @no_additional_args',
'@php foo.php @additional_args then the rest',
'echo -n bar',
];
$dispatcher->expects($this->atLeastOnce())
->method('getListeners')
->will($this->returnValue($listeners));
$dispatcher->dispatchScript(ScriptEvents::POST_INSTALL_CMD, false, ['ARG', 'ARG2', '--arg']);
$expected = '> post-install-cmd: echo -n foo'.PHP_EOL.
'> post-install-cmd: @php foo.php '.$args.' then the rest'.PHP_EOL.
'> post-install-cmd: echo -n bar '.$args.PHP_EOL;
self::assertEquals($expected, $io->getOutput());
}
public static function createsVendorBinFolderChecksEnvDoesNotContainsBin(): void
{
mkdir(__DIR__ . '/vendor/bin', 0700, true);