1
0
Fork 0

Merge pull request #8492 from staabm/putenv

implemented `@putenv` composer script
pull/8494/head
Jordi Boggiano 2019-12-22 12:27:23 +01:00 committed by GitHub
commit 2dd001132a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 43 additions and 2 deletions

View File

@ -244,7 +244,11 @@ class EventDispatcher
}
}
if (substr($exec, 0, 5) === '@php ') {
if (substr($exec, 0, 8) === '@putenv ') {
putenv(substr($exec, 8));
continue;
} elseif (substr($exec, 0, 5) === '@php ') {
$exec = $this->getPhpExecCommand() . ' ' . substr($exec, 5);
} else {
$finder = new PhpExecutableFinder();
@ -512,7 +516,7 @@ class EventDispatcher
*/
protected function isComposerScript($callable)
{
return '@' === substr($callable, 0, 1) && '@php ' !== substr($callable, 0, 5);
return '@' === substr($callable, 0, 1) && '@php ' !== substr($callable, 0, 5) && '@putenv ' !== substr($callable, 0, 8);
}
/**

View File

@ -230,6 +230,43 @@ class EventDispatcherTest extends TestCase
$this->assertEquals($expected, $io->getOutput());
}
public function testDispatcherCanPutEnv()
{
$process = $this->getMockBuilder('Composer\Util\ProcessExecutor')->getMock();
$dispatcher = $this->getMockBuilder('Composer\EventDispatcher\EventDispatcher')
->setConstructorArgs(array(
$this->createComposerInstance(),
$io = new BufferIO('', OutputInterface::VERBOSITY_VERBOSE),
$process,
))
->setMethods(array(
'getListeners',
))
->getMock();
$listeners = array(
'@putenv ABC=123',
'Composer\\Test\\EventDispatcher\\EventDispatcherTest::getTestEnv',
);
$dispatcher->expects($this->atLeastOnce())
->method('getListeners')
->will($this->returnValue($listeners));
$dispatcher->dispatchScript(ScriptEvents::POST_INSTALL_CMD, false);
$expected = '> post-install-cmd: @putenv ABC=123'.PHP_EOL.
'> post-install-cmd: Composer\Test\EventDispatcher\EventDispatcherTest::getTestEnv'.PHP_EOL;
$this->assertEquals($expected, $io->getOutput());
}
static public function getTestEnv() {
$val = getenv('ABC');
if ($val !== '123') {
throw new \Exception('getenv() did not return the expected value. expected 123 got '. var_export($val, true));
}
}
public function testDispatcherCanExecuteComposerScriptGroups()
{
$process = $this->getMockBuilder('Composer\Util\ProcessExecutor')->getMock();