Skip to content

Commit 828cb83

Browse files
test
1 parent 9d1289c commit 828cb83

File tree

2 files changed

+63
-41
lines changed

2 files changed

+63
-41
lines changed

src/Tests/CreateContractAndResponseTest.php

Lines changed: 2 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,6 @@ public function test_handles_missing_files_gracefully()
6363
$this->artisan('files:delete-all')
6464
->assertExitCode(0);
6565
$this->assertFalse(File::exists($directory) && count(File::files($directory)) > 0);
66-
6766
}
6867

6968
public function test_handles_permission_errors_gracefully()
@@ -79,49 +78,11 @@ public function test_handles_permission_errors_gracefully()
7978
$this->artisan('files:delete-all');
8079

8180
// Ensure file still exists
82-
$this->assertFileExists($filePath);
81+
chmod($filePath, 0775);
82+
$this->assertTrue(File::exists($filePath));
8383

8484
// Reset permissions
85-
chmod($filePath, 0775);
8685
File::delete($filePath);
8786
}
8887

89-
90-
public function test_command_help_message()
91-
{
92-
$this->artisan('files:delete-all --help')
93-
->expectsOutputToContain('Delete all files and folders recursively, skipping undeletable ones and logging them');
94-
}
95-
96-
public function test_deletes_only_specific_file_extensions()
97-
{
98-
Storage::fake();
99-
100-
// Create multiple file types
101-
Storage::put('logs/app.log', 'Log content');
102-
Storage::put('logs/debug.txt', 'Debug content');
103-
104-
// Run command with `--ext=log`
105-
$this->artisan('files:delete-all --ext=log');
106-
107-
// Ensure only `.log` is deleted
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);
126-
}
12788
}

src/Tests/DeleteFilesTest.php

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
<?php
2+
3+
namespace Tests\Feature;
4+
5+
use Tests\TestCase;
6+
use Illuminate\Support\Facades\Artisan;
7+
use Illuminate\Support\Facades\File;
8+
use Illuminate\Support\Facades\Storage;
9+
10+
class DeleteFilesTest extends TestCase
11+
{
12+
/**
13+
* A basic test example.
14+
*
15+
* @return void
16+
*/
17+
public function test_the_application_returns_a_successful_response()
18+
{
19+
$response = $this->get('/');
20+
21+
$response->assertStatus(200);
22+
}
23+
public function test_command_help_message()
24+
{
25+
$this->artisan('files:delete-all --help')
26+
->expectsOutputToContain('Delete all files and folders recursively, skipping undeletable ones and logging them');
27+
}
28+
29+
public function test_deletes_only_specific_file_extensions()
30+
{
31+
Storage::fake();
32+
33+
// Create multiple file types
34+
Storage::put('logs/app.log', 'Log content');
35+
Storage::put('logs/debug.txt', 'Debug content');
36+
37+
// Run command with `--ext=log`
38+
$this->artisan('files:delete-all storage/app/logs --ext=log');
39+
40+
// Ensure only `.log` is deleted
41+
$this->assertFalse(File::exists(storage_path('app.logs/app.log')));
42+
$this->assertTrue(Storage::exists('logs/debug.txt'));
43+
Storage::delete('logs/debug.txt');
44+
}
45+
public function test_deletes_directories()
46+
{
47+
Storage::fake();
48+
49+
// Create multiple file types
50+
Storage::put('custom/logs/app.log', 'Log content');
51+
Storage::put('custom/app.log', 'Log content');
52+
53+
// Run command with `--ext=log`
54+
$this->artisan('files:delete-all storage/app/custom/app.log --ext=log');
55+
56+
// Ensure only `.log` is deleted
57+
$this->assertFalse(File::exists(storage_path('app/custom/logs/app.log')));
58+
$this->assertFalse(File::exists(storage_path('app/custom/app.log')));
59+
$this->assertFalse(File::exists(storage_path('app/custom')) && count(File::files(storage_path('app/custom'))) > 0);
60+
}
61+
}

0 commit comments

Comments
 (0)