|
| 1 | +<?php |
| 2 | + |
| 3 | +/* |
| 4 | + * This file is part of the Symfony package. |
| 5 | + * |
| 6 | + * (c) Fabien Potencier <[email protected]> |
| 7 | + * |
| 8 | + * For the full copyright and license information, please view the LICENSE |
| 9 | + * file that was distributed with this source code. |
| 10 | + */ |
| 11 | + |
| 12 | +namespace Symfony\Flex\Tests; |
| 13 | + |
| 14 | +use Composer\Composer; |
| 15 | +use Composer\IO\NullIO; |
| 16 | +use Composer\Util\ProcessExecutor; |
| 17 | +use PHPUnit\Framework\TestCase; |
| 18 | +use Symfony\Component\Process\PhpExecutableFinder; |
| 19 | +use Symfony\Flex\Options; |
| 20 | +use Symfony\Flex\ScriptExecutor; |
| 21 | + |
| 22 | +final class ScriptExecutorTest extends TestCase |
| 23 | +{ |
| 24 | + /** |
| 25 | + * @backupGlobals enabled |
| 26 | + */ |
| 27 | + public function testMemoryLimit(): void |
| 28 | + { |
| 29 | + $command = './command.php'; |
| 30 | + $memoryLimit = '32M'; |
| 31 | + putenv("COMPOSER_MEMORY_LIMIT={$memoryLimit}"); |
| 32 | + $executorMock = $this->createMock(ProcessExecutor::class); |
| 33 | + $scriptExecutor = new ScriptExecutor(new Composer(), new NullIO(), new Options(), $executorMock); |
| 34 | + |
| 35 | + $phpFinder = new PhpExecutableFinder(); |
| 36 | + if (!$php = $phpFinder->find(false)) { |
| 37 | + throw new \RuntimeException('The PHP executable could not be found, add it to your PATH and try again.'); |
| 38 | + } |
| 39 | + |
| 40 | + $arguments = $phpFinder->findArguments(); |
| 41 | + $ini = php_ini_loaded_file(); |
| 42 | + $arguments[] = "--php-ini={$ini}"; |
| 43 | + $arguments[] = "-d memory_limit={$memoryLimit}"; |
| 44 | + |
| 45 | + $phpArgs = implode(' ', array_map([ProcessExecutor::class, 'escape'], $arguments)); |
| 46 | + |
| 47 | + $expectedCommand = ProcessExecutor::escape($php).($phpArgs ? ' '.$phpArgs : '').' '.$command; |
| 48 | + |
| 49 | + $executorMock |
| 50 | + ->method('execute') |
| 51 | + ->with($expectedCommand) |
| 52 | + ->willReturn(0) |
| 53 | + ; |
| 54 | + $this->expectNotToPerformAssertions(); |
| 55 | + |
| 56 | + $scriptExecutor->execute('php-script', $command); |
| 57 | + } |
| 58 | +} |
0 commit comments