Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/Commands/MakeUserCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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');

Expand All @@ -63,7 +63,7 @@ public function handle(): int
$this->promptEmail();
}

if (! $this->isAdmin) {
if ($this->isAdmin === null) {
$this->promptIsAdmin();
}

Expand Down
59 changes: 59 additions & 0 deletions tests/Unit/Commands/MakeUserCommandTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<?php

it('creates the admin user', function () {
$this->artisan('cachet:make:user', [
'email' => '[email protected]',
'--name' => 'Dan',
'--admin' => true,
'--password' => 'password',
]);

$this->assertDatabaseHas('users', [
'email' => '[email protected]',
'name' => 'Dan',
'is_admin' => true,
]);
});

it('creates the standard user', function () {
$this->artisan('cachet:make:user', [
'email' => '[email protected]',
'--name' => 'Dan',
'--admin' => false,
'--password' => 'password',
]);

$this->assertDatabaseHas('users', [
'email' => '[email protected]',
'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?', '[email protected]')
->expectsConfirmation('Is the user an admin?', 'No')
->expectsQuestion('What is the user\'s password?', 'password');

$this->assertDatabaseHas('users', [
'email' => '[email protected]',
'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?', '[email protected]')
->expectsConfirmation('Is the user an admin?', 'Yes')
->expectsQuestion('What is the user\'s password?', 'password');

$this->assertDatabaseHas('users', [
'email' => '[email protected]',
'name' => 'Dan',
'is_admin' => true,
]);
});