diff --git a/src/Commands/MakeUserCommand.php b/src/Commands/MakeUserCommand.php index 2ea2f390..8690e782 100644 --- a/src/Commands/MakeUserCommand.php +++ b/src/Commands/MakeUserCommand.php @@ -16,7 +16,7 @@ class MakeUserCommand extends Command * * @var string */ - protected $signature = 'cachet:make:user {email?} {--password= : The user\'s password} {--admin : Whether the user is an admin} {--name= : The name of the user }'; + protected $signature = 'cachet:make:user {email?} {--password= : The user\'s password} {--admin= : Whether the user is an admin} {--name= : The name of the user }'; /** * The console command description. @@ -51,7 +51,7 @@ class MakeUserCommand extends Command public function handle(): int { $this->email = $this->argument('email'); - $this->isAdmin = $this->option('admin'); + $this->isAdmin = $this->option('admin') !== null ? (bool) $this->option('admin') : null; $this->password = $this->option('password'); $this->data['name'] = $this->option('name'); @@ -63,7 +63,7 @@ public function handle(): int $this->promptEmail(); } - if (! $this->isAdmin) { + if ($this->isAdmin === null) { $this->promptIsAdmin(); } diff --git a/tests/Unit/Commands/MakeUserCommandTest.php b/tests/Unit/Commands/MakeUserCommandTest.php new file mode 100644 index 00000000..cccb544f --- /dev/null +++ b/tests/Unit/Commands/MakeUserCommandTest.php @@ -0,0 +1,59 @@ +artisan('cachet:make:user', [ + 'email' => 'dan@example.com', + '--name' => 'Dan', + '--admin' => true, + '--password' => 'password', + ]); + + $this->assertDatabaseHas('users', [ + 'email' => 'dan@example.com', + 'name' => 'Dan', + 'is_admin' => true, + ]); +}); + +it('creates the standard user', function () { + $this->artisan('cachet:make:user', [ + 'email' => 'dan@example.com', + '--name' => 'Dan', + '--admin' => false, + '--password' => 'password', + ]); + + $this->assertDatabaseHas('users', [ + 'email' => 'dan@example.com', + 'name' => 'Dan', + 'is_admin' => false, + ]); +}); + +it('creates the standard user using prompts', function () { + $this->artisan('cachet:make:user') + ->expectsQuestion('What is the user\'s name?', 'Dan') + ->expectsQuestion('What is the user\'s email?', 'dan@example.com') + ->expectsConfirmation('Is the user an admin?', 'No') + ->expectsQuestion('What is the user\'s password?', 'password'); + + $this->assertDatabaseHas('users', [ + 'email' => 'dan@example.com', + 'name' => 'Dan', + 'is_admin' => false, + ]); +}); + +it('creates the admin user using prompts', function () { + $this->artisan('cachet:make:user') + ->expectsQuestion('What is the user\'s name?', 'Dan') + ->expectsQuestion('What is the user\'s email?', 'dan@example.com') + ->expectsConfirmation('Is the user an admin?', 'Yes') + ->expectsQuestion('What is the user\'s password?', 'password'); + + $this->assertDatabaseHas('users', [ + 'email' => 'dan@example.com', + 'name' => 'Dan', + 'is_admin' => true, + ]); +});