Skip to content

Commit 83fe753

Browse files
committed
test: fix command tests that may hang on linux due to sudo
1 parent 246cbd4 commit 83fe753

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
@@ -80,34 +80,13 @@ public function testClearDebugbarWithError(): void
8080
{
8181
$path = WRITEPATH . 'debugbar' . DIRECTORY_SEPARATOR . "debugbar_{$this->time}.json";
8282

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

10386
command('debugbar:clear');
10487

10588
// Restore attributes so other tests are not affected.
106-
if (str_starts_with(PHP_OS, 'Darwin')) {
107-
@exec(sprintf('chflags nouchg %s', escapeshellarg($path)));
108-
} else {
109-
@exec(sprintf('sudo chattr -i %s', escapeshellarg($path)));
110-
}
89+
chmod(dirname($path), 0755);
11190

11291
$this->assertFileExists($path);
11392
$this->assertSame(

tests/system/Commands/Housekeeping/ClearLogsTest.php

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

146-
// Attempt to make the file itself undeletable by setting the
147-
// immutable/uchg flag on supported platforms.
148-
$immutableSet = false;
149-
if (str_starts_with(PHP_OS, 'Darwin')) {
150-
@exec(sprintf('chflags uchg %s', escapeshellarg($path)), $output, $rc);
151-
$immutableSet = $rc === 0;
152-
} else {
153-
// Try chattr on Linux with sudo (for containerized environments)
154-
@exec('which chattr', $whichOut, $whichRc);
155-
156-
if ($whichRc === 0) {
157-
@exec(sprintf('sudo chattr +i %s', escapeshellarg($path)), $output, $rc);
158-
$immutableSet = $rc === 0;
159-
}
160-
}
161-
162-
if (! $immutableSet) {
163-
$this->markTestSkipped('Cannot set file immutability in this environment');
164-
}
146+
// Attempt to make the file itself undeletable
147+
chmod(dirname($path), 0555);
165148

166149
command('logs:clear --force');
167150

168151
// Restore attributes so other tests are not affected.
169-
if (str_starts_with(PHP_OS, 'Darwin')) {
170-
@exec(sprintf('chflags nouchg %s', escapeshellarg($path)));
171-
} else {
172-
@exec(sprintf('sudo chattr -i %s', escapeshellarg($path)));
173-
}
152+
chmod(dirname($path), 0755);
174153

175154
$this->assertFileExists($path);
176155
$this->assertSame("Error in deleting the logs files.\n", preg_replace('/\e\[[^m]+m/', '', $this->getStreamFilterBuffer()));

0 commit comments

Comments
 (0)