Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[5.x] Add password option to make:user command #11005

Merged
merged 4 commits into from
Oct 24, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
9 changes: 9 additions & 0 deletions src/Console/Commands/MakeUser.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,13 @@ class MakeUser extends Command
*/
protected $email;

/**
* The user's password.
*
* @var string
*/
protected $password;

/**
* The user's data.
*
Expand Down Expand Up @@ -172,6 +179,7 @@ protected function createUser()

$user = User::make()
->email($this->email)
->password($this->option('password'))
->data($this->data);

if ($this->super || $this->option('super')) {
Expand Down Expand Up @@ -241,6 +249,7 @@ protected function getOptions()
{
return array_merge(parent::getOptions(), [
['super', '', InputOption::VALUE_NONE, 'Generate a super user with permission to do everything'],
['password', '', InputOption::VALUE_OPTIONAL, 'Generate a user with given password'],
]);
}
}
17 changes: 17 additions & 0 deletions tests/Console/Commands/MakeUserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,4 +106,21 @@ public function it_generates_with_and_without_super_option()
$this->assertTrue($jason->isSuper());
$this->assertFalse($girl->isSuper());
}

#[Test]
public function it_can_make_a_user_with_password_option()
{
$this->withoutMockingConsoleOutput();

$this->assertEmpty(User::all());

$this->artisan('statamic:make:user', ['email' => '[email protected]', '--password' => 'PacManMoonwalk#84'])
->expectsOutputToContain('User created successfully.');

$user = User::all()->first();

$this->assertNotEmpty($user->id());
$this->assertEquals('[email protected]', $user->email());
joshuablum marked this conversation as resolved.
Show resolved Hide resolved
$this->assertNotEmpty($user->password());
}
}
Loading