File tree Expand file tree Collapse file tree 1 file changed +54
-0
lines changed Expand file tree Collapse file tree 1 file changed +54
-0
lines changed Original file line number Diff line number Diff line change 1+ <?php
2+
3+ namespace Tests \Unit \Actions ;
4+
5+ use App \Actions \DeleteUserAction ;
6+ use App \Exceptions \UserNotFoundException ;
7+ use App \Models \User ;
8+ use Illuminate \Support \Facades \Storage ;
9+ use Tests \TestCase ;
10+
11+ class DeleteUserTest extends TestCase
12+ {
13+ public function testUserNotFound (): void
14+ {
15+ $ this ->expectException (UserNotFoundException::class);
16+
17+ (new DeleteUserAction ())->execute (999 );
18+ }
19+
20+ public function testSuccessfulAvatarCleared (): void
21+ {
22+ $ image = \Image::canvas (500 , 500 , '#CCC ' );
23+
24+ Storage::put ('public/avatars/yabadabadoo.png ' , (string ) $ image ->encode ());
25+
26+ $ user = factory (User::class)->create ([
27+ 'avatar ' => 'yabadabadoo.png '
28+ ]);
29+
30+ $ this ->assertFileExists (storage_path () . '/app/public/avatars/yabadabadoo.png ' );
31+
32+ (new DeleteUserAction ())->execute ($ user ->id );
33+
34+ $ this ->assertFileNotExists (storage_path () . '/app/public/avatars/yabadabadoo.png ' );
35+ }
36+
37+ public function testSuccessfulColumnsCleared (): void
38+ {
39+ $ user = factory (User::class)->create ([
40+ 'name ' => 'John Doe ' ,
41+ 42+ ]);
43+
44+ $ this ->assertNotNull ($ user ->name );
45+ $ this ->assertNotNull ($ user ->email );
46+
47+ (new DeleteUserAction ())->execute ($ user ->id );
48+
49+ $ user ->refresh ();
50+
51+ $ this ->assertNull ($ user ->name );
52+ $ this ->assertNull ($ user ->email );
53+ }
54+ }
You can’t perform that action at this time.
0 commit comments