Skip to content

Commit

Permalink
Merge branch 'main' into blt-5222
Browse files Browse the repository at this point in the history
  • Loading branch information
danepowell authored Oct 23, 2023
2 parents b59733b + 030e53b commit f5adacf
Show file tree
Hide file tree
Showing 5 changed files with 90 additions and 43 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
"symfony/yaml": "^6.0",
"thecodingmachine/safe": "^2.4",
"typhonius/acquia-logstream": "^0.0.13",
"typhonius/acquia-php-sdk-v2": "^3.1.0",
"typhonius/acquia-php-sdk-v2": "^3.1.1",
"vlucas/phpdotenv": "^5.5",
"zumba/amplitude-php": "^1.0.4"
},
Expand Down
76 changes: 41 additions & 35 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 2 additions & 4 deletions src/Helpers/LocalMachineHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -215,15 +215,13 @@ private function fixFilename(string $filename): string {
/**
* Returns the appropriate home directory.
*
* Adapted from Ads Package Manager by Ed Reel.
*
* @url https://github.com/uberhacker/tpm
* @see https://github.com/pantheon-systems/terminus/blob/1d89e20dd388dc08979a1bc52dfd142b26c03dcf/src/Config/DefaultsConfig.php#L99
*/
public static function getHomeDir(): string {
$home = getenv('HOME');
if (!$home) {
$system = '';
if (getenv('MSYSTEM') !== NULL) {
if (getenv('MSYSTEM')) {
$system = strtoupper(substr(getenv('MSYSTEM'), 0, 4));
}
if ($system !== 'MING') {
Expand Down
35 changes: 35 additions & 0 deletions tests/phpunit/src/Misc/LocalMachineHelperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

namespace Acquia\Cli\Tests\Misc;

use Acquia\Cli\Exception\AcquiaCliException;
use Acquia\Cli\Helpers\LocalMachineHelper;
use Acquia\Cli\Tests\TestBase;
use Symfony\Component\Console\Output\BufferedOutput;

Expand Down Expand Up @@ -61,4 +63,37 @@ public function testCommandExists(): void {
$this->assertIsBool($exists);
}

public function testHomeDirWindowsCmd(): void {
self::setEnvVars([
'HOMEPATH' => 'something',
]);
self::unsetEnvVars([
'MSYSTEM',
'HOME',
]);
$home = LocalMachineHelper::getHomeDir();
$this->assertEquals('something', $home);
}

public function testHomeDirWindowsMsys2(): void {
self::setEnvVars([
'HOMEPATH' => 'something',
'MSYSTEM' => 'MSYS2',
]);
self::unsetEnvVars(['HOME']);
$home = LocalMachineHelper::getHomeDir();
$this->assertEquals('something', $home);
}

/**
* I don't know why, but apparently Ming is unsupported ¯\_(ツ)_/¯.
*/
public function testHomeDirWindowsMing(): void {
self::setEnvVars(['MSYSTEM' => 'MING']);
self::unsetEnvVars(['HOME']);
$this->expectException(AcquiaCliException::class);
$this->expectExceptionMessage('Could not determine $HOME directory. Ensure $HOME is set in your shell.');
LocalMachineHelper::getHomeDir();
}

}
14 changes: 11 additions & 3 deletions tests/phpunit/src/TestBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,10 @@ public function setupFsFixture(): void {
* This method is called before each test.
*/
protected function setUp(): void {
putenv('COLUMNS=85');
self::setEnvVars([
'COLUMNS' => '85',
'HOME' => '/home/test',
]);
$this->output = new BufferedOutput();
$this->input = new ArrayInput([]);

Expand Down Expand Up @@ -241,9 +244,14 @@ public static function setEnvVars(array $envVars): void {
}
}

public static function unsetEnvVars(mixed $envVars): void {
public static function unsetEnvVars(array $envVars): void {
foreach ($envVars as $key => $value) {
putenv($key);
if (is_int($key)) {
putenv($value);
}
else {
putenv($key);
}
}
}

Expand Down

0 comments on commit f5adacf

Please sign in to comment.