@@ -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