88use Illuminate \Foundation \Testing \DatabaseTransactions ;
99
1010use App \File ;
11+ use App \User ;
1112
1213class FileBaseControllerTest extends TestCase
1314{
1415 use RefreshDatabase;
1516
16- protected $ user_index ;
17- protected $ user_index_error ;
18- protected $ user_create ;
19- protected $ user_update ;
20- protected $ user_delete ;
17+ protected function getUserForIndex ()
18+ {
19+ return factory (User::class)->create ();
20+ }
21+
22+ protected function getUserForIndexError ()
23+ {
24+ return factory (User::class)->create ();
25+ }
26+
27+ protected function getUserForCreate ()
28+ {
29+ return factory (User::class)->create ();
30+ }
31+
32+ protected function getUserForUpdate ()
33+ {
34+ return factory (User::class)->create ();
35+ }
36+
37+ protected function getUserForDelete ()
38+ {
39+ return factory (User::class)->create ();
40+ }
2141
2242 /** @test */
2343 public function it_checks_if_index_work ()
2444 {
2545 $ files = factory (File::class, 4 )->create ();
2646
27- $ response = $ this ->actingAs ($ this ->user_index )->json ('GET ' , route ('api.files.index ' ));
47+ $ response = $ this ->actingAs ($ this ->getUserForIndex () )->json ('GET ' , route ('api.files.index ' ));
2848
2949 $ response ->assertStatus (200 );
3050 $ response ->assertJson ([
@@ -42,7 +62,7 @@ public function it_checks_if_index_gives_error()
4262 {
4363 $ files = factory (File::class, 4 )->create ();
4464
45- $ response = $ this ->actingAs ($ this ->user_index_error )->json ('GET ' , route ('api.files.index ' ));
65+ $ response = $ this ->actingAs ($ this ->getUserForIndexError () )->json ('GET ' , route ('api.files.index ' ));
4666
4767 $ response ->assertStatus (403 );
4868 $ response ->assertJson ([
@@ -56,7 +76,7 @@ public function it_checks_if_index_gives_error()
5676 /** @test */
5777 public function it_checks_create_works ()
5878 {
59- $ response = $ this ->actingAs ($ this ->user_create )->json ('POST ' , route ('api.files.store ' , [
79+ $ response = $ this ->actingAs ($ this ->getUserForCreate () )->json ('POST ' , route ('api.files.store ' , [
6080 'file_name ' => 'something cute.png ' ,
6181 'file_type ' => 'image/png ' ,
6282 'file_data ' => $ this ->get1x1RedPixelImage ()
@@ -78,7 +98,7 @@ public function it_checks_update_works()
7898 {
7999 $ file = factory (File::class)->create ();
80100
81- $ response = $ this ->actingAs ($ this ->user_update )->json ('PUT ' , route ('api.files.update ' , [
101+ $ response = $ this ->actingAs ($ this ->getUserForUpdate () )->json ('PUT ' , route ('api.files.update ' , [
82102 'file ' => $ file ->id ,
83103 'file_name ' => 'something cute.png ' ,
84104 'file_type ' => 'image/png ' ,
@@ -101,7 +121,7 @@ public function it_checks_delete_works()
101121 {
102122 $ file = factory (File::class)->create ();
103123
104- $ response = $ this ->actingAs ($ this ->user_delete )->json ('DELETE ' , route ('api.files.destroy ' , [
124+ $ response = $ this ->actingAs ($ this ->getUserForDelete () )->json ('DELETE ' , route ('api.files.destroy ' , [
105125 'file ' => $ file ->id
106126 ]));
107127
0 commit comments