Skip to content

Commit 090f944

Browse files
committed
fix(self-update): include XDG_CONFIG_HOME as composer home candidate
1 parent fe01d3e commit 090f944

2 files changed

Lines changed: 34 additions & 0 deletions

File tree

src/SelfUpdate/ComposerSelfUpdateScopeResolver.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,12 @@ private function getComposerHomeCandidates(): array
7474
$candidates[] = $composerHome;
7575
}
7676

77+
$xdgConfigHome = $this->environment->get('XDG_CONFIG_HOME');
78+
79+
if (null !== $xdgConfigHome && '' !== $xdgConfigHome) {
80+
$candidates[] = Path::join($xdgConfigHome, 'composer');
81+
}
82+
7783
$home = $this->environment->get('HOME');
7884

7985
if (null !== $home && '' !== $home) {

tests/SelfUpdate/ComposerSelfUpdateScopeResolverTest.php

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@ public function isGlobalInstallationWillReturnTrueWhenPackageLivesUnderComposerH
5757
->willReturn(null);
5858
$this->environment->get('APPDATA')
5959
->willReturn(null);
60+
$this->environment->get('XDG_CONFIG_HOME')
61+
->willReturn(null);
6062
$resolver = new ComposerSelfUpdateScopeResolver(
6163
$this->environment->reveal(),
6264
'/home/felipe/.composer/vendor/fast-forward/dev-tools',
@@ -77,6 +79,8 @@ public function isGlobalInstallationWillReturnTrueWhenPackageLivesUnderDefaultCo
7779
->willReturn('/Users/felipe');
7880
$this->environment->get('APPDATA')
7981
->willReturn(null);
82+
$this->environment->get('XDG_CONFIG_HOME')
83+
->willReturn(null);
8084
$resolver = new ComposerSelfUpdateScopeResolver(
8185
$this->environment->reveal(),
8286
'/Users/felipe/Library/Application Support/Composer/vendor/fast-forward/dev-tools',
@@ -97,11 +101,35 @@ public function isGlobalInstallationWillReturnFalseWhenPackageLivesUnderProjectV
97101
->willReturn('/home/felipe');
98102
$this->environment->get('APPDATA')
99103
->willReturn(null);
104+
$this->environment->get('XDG_CONFIG_HOME')
105+
->willReturn(null);
100106
$resolver = new ComposerSelfUpdateScopeResolver(
101107
$this->environment->reveal(),
102108
'/home/felipe/project/vendor/fast-forward/dev-tools',
103109
);
104110

105111
self::assertFalse($resolver->isGlobalInstallation());
106112
}
113+
114+
/**
115+
* @return void
116+
*/
117+
#[Test]
118+
public function isGlobalInstallationWillReturnTrueWhenPackageLivesUnderXdgComposerHome(): void
119+
{
120+
$this->environment->get('COMPOSER_HOME')
121+
->willReturn(null);
122+
$this->environment->get('HOME')
123+
->willReturn(null);
124+
$this->environment->get('APPDATA')
125+
->willReturn(null);
126+
$this->environment->get('XDG_CONFIG_HOME')
127+
->willReturn('/tmp/xdg');
128+
$resolver = new ComposerSelfUpdateScopeResolver(
129+
$this->environment->reveal(),
130+
'/tmp/xdg/composer/vendor/fast-forward/dev-tools',
131+
);
132+
133+
self::assertTrue($resolver->isGlobalInstallation());
134+
}
107135
}

0 commit comments

Comments
 (0)