Skip to content

Commit f884a79

Browse files
authored
Tests for MakeUserCommand (#268)
1 parent dfa7943 commit f884a79

File tree

2 files changed

+62
-3
lines changed

2 files changed

+62
-3
lines changed

src/Commands/MakeUserCommand.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ class MakeUserCommand extends Command
1616
*
1717
* @var string
1818
*/
19-
protected $signature = 'cachet:make:user {email?} {--password= : The user\'s password} {--admin : Whether the user is an admin} {--name= : The name of the user }';
19+
protected $signature = 'cachet:make:user {email?} {--password= : The user\'s password} {--admin= : Whether the user is an admin} {--name= : The name of the user }';
2020

2121
/**
2222
* The console command description.
@@ -51,7 +51,7 @@ class MakeUserCommand extends Command
5151
public function handle(): int
5252
{
5353
$this->email = $this->argument('email');
54-
$this->isAdmin = $this->option('admin');
54+
$this->isAdmin = $this->option('admin') !== null ? (bool) $this->option('admin') : null;
5555
$this->password = $this->option('password');
5656
$this->data['name'] = $this->option('name');
5757

@@ -63,7 +63,7 @@ public function handle(): int
6363
$this->promptEmail();
6464
}
6565

66-
if (! $this->isAdmin) {
66+
if ($this->isAdmin === null) {
6767
$this->promptIsAdmin();
6868
}
6969

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
<?php
2+
3+
it('creates the admin user', function () {
4+
$this->artisan('cachet:make:user', [
5+
'email' => '[email protected]',
6+
'--name' => 'Dan',
7+
'--admin' => true,
8+
'--password' => 'password',
9+
]);
10+
11+
$this->assertDatabaseHas('users', [
12+
'email' => '[email protected]',
13+
'name' => 'Dan',
14+
'is_admin' => true,
15+
]);
16+
});
17+
18+
it('creates the standard user', function () {
19+
$this->artisan('cachet:make:user', [
20+
'email' => '[email protected]',
21+
'--name' => 'Dan',
22+
'--admin' => false,
23+
'--password' => 'password',
24+
]);
25+
26+
$this->assertDatabaseHas('users', [
27+
'email' => '[email protected]',
28+
'name' => 'Dan',
29+
'is_admin' => false,
30+
]);
31+
});
32+
33+
it('creates the standard user using prompts', function () {
34+
$this->artisan('cachet:make:user')
35+
->expectsQuestion('What is the user\'s name?', 'Dan')
36+
->expectsQuestion('What is the user\'s email?', '[email protected]')
37+
->expectsConfirmation('Is the user an admin?', 'No')
38+
->expectsQuestion('What is the user\'s password?', 'password');
39+
40+
$this->assertDatabaseHas('users', [
41+
'email' => '[email protected]',
42+
'name' => 'Dan',
43+
'is_admin' => false,
44+
]);
45+
});
46+
47+
it('creates the admin user using prompts', function () {
48+
$this->artisan('cachet:make:user')
49+
->expectsQuestion('What is the user\'s name?', 'Dan')
50+
->expectsQuestion('What is the user\'s email?', '[email protected]')
51+
->expectsConfirmation('Is the user an admin?', 'Yes')
52+
->expectsQuestion('What is the user\'s password?', 'password');
53+
54+
$this->assertDatabaseHas('users', [
55+
'email' => '[email protected]',
56+
'name' => 'Dan',
57+
'is_admin' => true,
58+
]);
59+
});

0 commit comments

Comments
 (0)