This repository was archived by the owner on Feb 18, 2023. It is now read-only.
File tree Expand file tree Collapse file tree 4 files changed +35
-7
lines changed
tests/Unit/Services/Installation Expand file tree Collapse file tree 4 files changed +35
-7
lines changed Original file line number Diff line number Diff line change @@ -25,8 +25,7 @@ class Kernel extends ConsoleKernel
2525 */
2626 protected function schedule (Schedule $ schedule )
2727 {
28- // $schedule->command('inspire')
29- // ->hourly();
28+
3029 }
3130
3231 /**
Original file line number Diff line number Diff line change 66use App \Entities \User ;
77use App \Entities \Permission ;
88use App \Services \Installation \Events \ApplicationWasInstalled ;
9+ use Illuminate \Validation \ValidationException ;
910
1011/**
1112 * Class InstallAppHandler
@@ -98,14 +99,22 @@ public function createPermissions()
9899 /**
99100 * @param array $attributes
100101 * @return $this
102+ * @throws ValidationException
101103 */
102104 public function createAdminUser (array $ attributes = [])
103105 {
106+ $ validator = validator ($ attributes , [
107+ 'name ' => 'required ' ,
108+ 'email ' => 'required|email|unique:users,email ' ,
109+ 'password ' => 'required|min:8|confirmed '
110+ ]);
111+ if ($ validator ->fails ()) {
112+ throw new ValidationException ($ validator );
113+ }
104114 $ this ->adminUser = User::create ([
105115 'name ' => $ attributes ['name ' ],
106116 'email ' => $ attributes ['email ' ],
107- 'password ' => $ attributes ['password ' ],
108- 'password_confirmation ' => $ attributes ['password_confirmation ' ]
117+ 'password ' => bcrypt ($ attributes ['password ' ])
109118 ]);
110119 return $ this ;
111120 }
Original file line number Diff line number Diff line change 1313|
1414*/
1515
16- Artisan::command ('inspire ' , function () {
17- $ this ->comment (Inspiring::quote ());
18- })->describe ('Display an inspiring quote ' );
16+ Artisan::command ('dev:generate-personal-token {userId} ' , function ($ userId ) {
17+ $ user = \App \Entities \User::find ($ userId );
18+ $ this ->info ('Token for user ' .$ user ->name );
19+ $ token = $ user ->createToken ('Personal Access Token ' )->accessToken ;
20+ $ this ->info ($ token );
21+ })->describe ('Generates a personal access token for a user ' );
Original file line number Diff line number Diff line change 22
33namespace Tests \Unit \Services \Installation ;
44
5+ use Illuminate \Validation \ValidationException ;
56use Tests \TestCase ;
67use Illuminate \Foundation \Testing \DatabaseMigrations ;
78
@@ -60,6 +61,22 @@ function test_it_creates_admin_user()
6061 $ this ->assertNotNull ($ user ->uuid );
6162 }
6263
64+ function test_it_validates_input_for_creating_user ()
65+ {
66+ $ handler = $ this ->makeHandler ();
67+ try {
68+ $ handler ->createAdminUser ([
69+ 'name ' => 'Jose Fonseca ' ,
70+ ]);
71+ $ this ->fail ('Validation to create user did not run. ' );
72+ } catch (ValidationException $ e ) {
73+ $ this ->assertDatabaseMissing ('users ' , [
74+ 'name ' => 'Jose Fonseca ' ,
75+ 76+ ]);
77+ }
78+ }
79+
6380 function test_it_assigns_admin_role_to_admin_user ()
6481 {
6582 $ handler = $ this ->makeHandler ();
You can’t perform that action at this time.
0 commit comments