diff --git a/tests/system/Commands/Housekeeping/ClearDebugbarTest.php b/tests/system/Commands/Housekeeping/ClearDebugbarTest.php index bb14906bcff9..a19522d21a53 100644 --- a/tests/system/Commands/Housekeeping/ClearDebugbarTest.php +++ b/tests/system/Commands/Housekeeping/ClearDebugbarTest.php @@ -80,34 +80,13 @@ public function testClearDebugbarWithError(): void { $path = WRITEPATH . 'debugbar' . DIRECTORY_SEPARATOR . "debugbar_{$this->time}.json"; - // Attempt to make the file itself undeletable by setting the - // immutable/uchg flag on supported platforms. - $immutableSet = false; - if (str_starts_with(PHP_OS, 'Darwin')) { - @exec(sprintf('chflags uchg %s', escapeshellarg($path)), $output, $rc); - $immutableSet = $rc === 0; - } else { - // Try chattr on Linux with sudo (for containerized environments) - @exec('which chattr', $whichOut, $whichRc); - - if ($whichRc === 0) { - @exec(sprintf('sudo chattr +i %s', escapeshellarg($path)), $output, $rc); - $immutableSet = $rc === 0; - } - } - - if (! $immutableSet) { - $this->markTestSkipped('Cannot set file immutability in this environment'); - } + // Attempt to make the file itself undeletable + chmod(dirname($path), 0555); command('debugbar:clear'); // Restore attributes so other tests are not affected. - if (str_starts_with(PHP_OS, 'Darwin')) { - @exec(sprintf('chflags nouchg %s', escapeshellarg($path))); - } else { - @exec(sprintf('sudo chattr -i %s', escapeshellarg($path))); - } + chmod(dirname($path), 0755); $this->assertFileExists($path); $this->assertSame( diff --git a/tests/system/Commands/Housekeeping/ClearLogsTest.php b/tests/system/Commands/Housekeeping/ClearLogsTest.php index 70406956d66e..eb09e8ee1d8b 100644 --- a/tests/system/Commands/Housekeeping/ClearLogsTest.php +++ b/tests/system/Commands/Housekeeping/ClearLogsTest.php @@ -143,34 +143,13 @@ public function testClearLogsFailsOnChmodFailure(): void $path = WRITEPATH . 'logs' . DIRECTORY_SEPARATOR . "log-{$this->date}.log"; file_put_contents($path, 'Lorem ipsum'); - // Attempt to make the file itself undeletable by setting the - // immutable/uchg flag on supported platforms. - $immutableSet = false; - if (str_starts_with(PHP_OS, 'Darwin')) { - @exec(sprintf('chflags uchg %s', escapeshellarg($path)), $output, $rc); - $immutableSet = $rc === 0; - } else { - // Try chattr on Linux with sudo (for containerized environments) - @exec('which chattr', $whichOut, $whichRc); - - if ($whichRc === 0) { - @exec(sprintf('sudo chattr +i %s', escapeshellarg($path)), $output, $rc); - $immutableSet = $rc === 0; - } - } - - if (! $immutableSet) { - $this->markTestSkipped('Cannot set file immutability in this environment'); - } + // Attempt to make the file itself undeletable + chmod(dirname($path), 0555); command('logs:clear --force'); // Restore attributes so other tests are not affected. - if (str_starts_with(PHP_OS, 'Darwin')) { - @exec(sprintf('chflags nouchg %s', escapeshellarg($path))); - } else { - @exec(sprintf('sudo chattr -i %s', escapeshellarg($path))); - } + chmod(dirname($path), 0755); $this->assertFileExists($path); $this->assertSame("Error in deleting the logs files.\n", preg_replace('/\e\[[^m]+m/', '', $this->getStreamFilterBuffer()));