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
7 changes: 5 additions & 2 deletions app/Console/Commands/RegisterUserCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

class RegisterUserCommand extends Command
{
protected $signature = 'registeruser {name? : Username} {email? : User email address} {--admin}';
protected $signature = 'registeruser {name? : Username} {email? : User email address} {password? : Password for the user} {--admin}';
protected $description = 'Register a new user with a given user name and an email address.';

private ?string $userName;
Expand All @@ -27,6 +27,7 @@ public function handle(): void

$this->userName = $this->argument('name');
$this->userEmail = $this->argument('email');
$this->userPassword = $this->argument('password');

do {
$this->askForUserDetails();
Expand Down Expand Up @@ -68,6 +69,8 @@ protected function askForUserDetails(): void
$this->userEmail = $this->ask('Please enter the user email address', $this->userEmail);
}

$this->userPassword = $this->secret('Please enter a password for ' . $this->userName);
if (empty($this->userPassword) || $this->validationFailed) {
$this->userPassword = $this->ask('Please enter a password for ' . $this->userName, $this->userPassword);
}
}
}
22 changes: 20 additions & 2 deletions tests/Commands/RegisterUserCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,25 @@ public function test_command_with_input(): void
$this->assertEquals('test@linkace.org', $databaseUser->email);
}

public function test_command_with_input_including_password(): void
{
User::factory()->create(); // Create admin dummy user

$this->artisan('registeruser', [
'name' => 'Test',
'email' => 'test@linkace.org',
'password' => 'testpassword',
])
->doesntExpectOutput('Please enter a password for Test')
->expectsOutput('User Test registered.')
->assertExitCode(0);

$databaseUser = User::latest('id')->first();

$this->assertEquals('Test', $databaseUser->name);
$this->assertEquals('test@linkace.org', $databaseUser->email);
}

public function test_command_without_input(): void
{
User::factory()->create(); // Create admin dummy user
Expand Down Expand Up @@ -60,7 +79,6 @@ public function test_command_with_duplicate_user(): void
->expectsQuestion('Please enter the user email address', 'test2@linkace.org')
->expectsQuestion('Please enter a password for Test2', 'testpassword')
->expectsOutput('User Test2 registered.')
->assertExitCode(0)
;
->assertExitCode(0);
}
}
Loading