function ProcessFactoryTest::testPhpDirectoryPrependedToPath

Tests that the process factory prepends the PHP directory to PATH.

File

core/modules/package_manager/tests/src/Kernel/ProcessFactoryTest.php, line 20

Class

ProcessFactoryTest
@coversDefaultClass \Drupal\package_manager\ProcessFactory @group auto_updates @internal

Namespace

Drupal\Tests\package_manager\Kernel

Code

public function testPhpDirectoryPrependedToPath() : void {
    $factory = $this->container
        ->get(ProcessFactoryInterface::class);
    $this->assertInstanceOf(ProcessFactory::class, $factory);
    // Ensure that the directory of the PHP interpreter can be found.
    $reflector = new \ReflectionObject($factory);
    $method = $reflector->getMethod('getPhpDirectory');
    $php_dir = $method->invoke(NULL);
    $this->assertNotEmpty($php_dir);
    // The process factory should always put the PHP interpreter's directory
    // at the beginning of the PATH environment variable.
    $env = $factory->create([
        'whoami',
    ])
        ->getEnv();
    $this->assertStringStartsWith("{$php_dir}:", $env['PATH']);
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.