Skip to content

Commit c8ae390

Browse files
authored
test: fix command tests that may hang on linux due to sudo (#10107)
1 parent 2010172 commit c8ae390

File tree

2 files changed

+6
-48
lines changed

2 files changed

+6
-48
lines changed

tests/system/Commands/Housekeeping/ClearDebugbarTest.php

Lines changed: 3 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -85,34 +85,13 @@ public function testClearDebugbarWithError(): void
8585
{
8686
$path = WRITEPATH . 'debugbar' . DIRECTORY_SEPARATOR . "debugbar_{$this->time}.json";
8787

88-
// Attempt to make the file itself undeletable by setting the
89-
// immutable/uchg flag on supported platforms.
90-
$immutableSet = false;
91-
if (str_starts_with(PHP_OS, 'Darwin')) {
92-
@exec(sprintf('chflags uchg %s', escapeshellarg($path)), $output, $rc);
93-
$immutableSet = $rc === 0;
94-
} else {
95-
// Try chattr on Linux with sudo (for containerized environments)
96-
@exec('which chattr', $whichOut, $whichRc);
97-
98-
if ($whichRc === 0) {
99-
@exec(sprintf('sudo chattr +i %s', escapeshellarg($path)), $output, $rc);
100-
$immutableSet = $rc === 0;
101-
}
102-
}
103-
104-
if (! $immutableSet) {
105-
$this->markTestSkipped('Cannot set file immutability in this environment');
106-
}
88+
// Attempt to make the file itself undeletable
89+
chmod(dirname($path), 0555);
10790

10891
command('debugbar:clear');
10992

11093
// Restore attributes so other tests are not affected.
111-
if (str_starts_with(PHP_OS, 'Darwin')) {
112-
@exec(sprintf('chflags nouchg %s', escapeshellarg($path)));
113-
} else {
114-
@exec(sprintf('sudo chattr -i %s', escapeshellarg($path)));
115-
}
94+
chmod(dirname($path), 0755);
11695

11796
$this->assertFileExists($path);
11897
$this->assertSame(

tests/system/Commands/Housekeeping/ClearLogsTest.php

Lines changed: 3 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -156,34 +156,13 @@ public function testClearLogsFailsOnChmodFailure(): void
156156
$path = WRITEPATH . 'logs' . DIRECTORY_SEPARATOR . "log-{$this->date}.log";
157157
file_put_contents($path, 'Lorem ipsum');
158158

159-
// Attempt to make the file itself undeletable by setting the
160-
// immutable/uchg flag on supported platforms.
161-
$immutableSet = false;
162-
if (str_starts_with(PHP_OS, 'Darwin')) {
163-
@exec(sprintf('chflags uchg %s', escapeshellarg($path)), $output, $rc);
164-
$immutableSet = $rc === 0;
165-
} else {
166-
// Try chattr on Linux with sudo (for containerized environments)
167-
@exec('which chattr', $whichOut, $whichRc);
168-
169-
if ($whichRc === 0) {
170-
@exec(sprintf('sudo chattr +i %s', escapeshellarg($path)), $output, $rc);
171-
$immutableSet = $rc === 0;
172-
}
173-
}
174-
175-
if (! $immutableSet) {
176-
$this->markTestSkipped('Cannot set file immutability in this environment');
177-
}
159+
// Attempt to make the file itself undeletable
160+
chmod(dirname($path), 0555);
178161

179162
command('logs:clear --force');
180163

181164
// Restore attributes so other tests are not affected.
182-
if (str_starts_with(PHP_OS, 'Darwin')) {
183-
@exec(sprintf('chflags nouchg %s', escapeshellarg($path)));
184-
} else {
185-
@exec(sprintf('sudo chattr -i %s', escapeshellarg($path)));
186-
}
165+
chmod(dirname($path), 0755);
187166

188167
$this->assertFileExists($path);
189168
$this->assertSame(

0 commit comments

Comments
 (0)