Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 3 additions & 24 deletions tests/system/Commands/Housekeeping/ClearDebugbarTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
27 changes: 3 additions & 24 deletions tests/system/Commands/Housekeeping/ClearLogsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()));
Expand Down
Loading