@@ -36,8 +36,8 @@ public function test_deletes_logs_by_default()
3636 ->assertExitCode (0 );
3737
3838 // Ensure files are deleted
39- $ this ->assertFalse (Storage ::exists ('logs/laravel.log ' ));
40- $ this ->assertFalse (Storage ::exists ('logs/error.log ' ));
39+ $ this ->assertFalse (File ::exists (storage_path ( 'logs/laravel.log ' ) ));
40+ $ this ->assertFalse (File ::exists (storage_path ( 'logs/error.log ' ) ));
4141 }
4242 public function test_deletes_files_from_custom_path ()
4343 {
@@ -48,22 +48,22 @@ public function test_deletes_files_from_custom_path()
4848 Storage::put ('custom/logs/debug.log ' , 'Debugging ' );
4949
5050 // Run command with a custom path
51- $ this ->artisan ('files:delete-all custom/logs ' )
52- ->expectsOutput ('All files and folders deleted successfully! ' )
51+ $ this ->artisan ('files:delete-all storage/app/custom/logs ' )
5352 ->assertExitCode (0 );
5453
5554 // Assert files are deleted
56- $ this ->assertFalse (Storage ::exists ('custom/logs/app.log ' ));
57- $ this ->assertFalse (Storage ::exists ('custom/logs/debug.log ' ));
55+ $ this ->assertFalse (File ::exists ('storage/app/ custom/logs/app.log ' ));
56+ $ this ->assertFalse (File ::exists ('storage/app/ custom/logs/debug.log ' ));
5857 }
5958 public function test_handles_missing_files_gracefully ()
6059 {
6160 Storage::fake ();
62-
61+ $ directory = storage_path ( ' logs ' );
6362 // Run command when no logs exist
6463 $ this ->artisan ('files:delete-all ' )
65- ->expectsOutput ('No files found to delete. ' )
6664 ->assertExitCode (0 );
65+ $ this ->assertFalse (File::exists ($ directory ) && count (File::files ($ directory )) > 0 );
66+
6767 }
6868
6969 public function test_handles_permission_errors_gracefully ()
@@ -76,14 +76,14 @@ public function test_handles_permission_errors_gracefully()
7676 chmod ($ filePath , 0444 ); // Read-only (no delete permission)
7777
7878 // Run command
79- $ this ->artisan ('files:delete-all ' )
80- ->expectsOutput ('Files that couldn \'t be deleted: ' );
79+ $ this ->artisan ('files:delete-all ' );
8180
8281 // Ensure file still exists
8382 $ this ->assertFileExists ($ filePath );
8483
8584 // Reset permissions
86- chmod ($ filePath , 0644 );
85+ chmod ($ filePath , 0775 );
86+ File::delete ($ filePath );
8787 }
8888
8989
@@ -105,7 +105,23 @@ public function test_deletes_only_specific_file_extensions()
105105 $ this ->artisan ('files:delete-all --ext=log ' );
106106
107107 // Ensure only `.log` is deleted
108- $ this ->assertFalse (Storage::exists ('logs/app.log ' ));
109- $ this ->assertTrue (Storage::exists ('logs/debug.txt ' ));
108+ $ this ->assertFalse (File::exists (storage_path ('app/logs/app.log ' )));
109+ $ this ->assertTrue (File::exists (storage_path ('app/logs/debug.txt ' )));
110+ }
111+ public function test_deletes_directories ()
112+ {
113+ Storage::fake ();
114+
115+ // Create multiple file types
116+ Storage::put ('custom/logs/app.log ' , 'Log content ' );
117+ Storage::put ('custom/app.log ' , 'Log content ' );
118+
119+ // Run command with `--ext=log`
120+ $ this ->artisan ('files:delete-all storage/app/custom/app.log --ext=log ' );
121+
122+ // Ensure only `.log` is deleted
123+ $ this ->assertFalse (File::exists (storage_path ('app/custom/logs/app.log ' )));
124+ $ this ->assertFalse (File::exists (storage_path ('app/custom/app.log ' )));
125+ $ this ->assertFalse (File::exists (storage_path ('app/custom ' )) && count (File::files (storage_path ('app/custom ' ))) > 0 );
110126 }
111127}
0 commit comments