CreateUser crashes on missing factory and faker. Perhaps caused by me not including the Artisan test script. For now, do not prompt for credentials or attempt to crate the user
This commit is contained in:
parent
4cb061c021
commit
6eeb04a332
3 changed files with 114 additions and 10 deletions
103
conf/CreateUserTest.php
Normal file
103
conf/CreateUserTest.php
Normal file
|
@ -0,0 +1,103 @@
|
|||
<?php
|
||||
|
||||
namespace Tests\Feature\Console;
|
||||
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Foundation\Testing\WithFaker;
|
||||
use Illuminate\Support\Carbon;
|
||||
use Tests\TestCase;
|
||||
|
||||
class CreateUserTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
public function test_user_creates_with_valid_args(): void
|
||||
{
|
||||
$this->artisan('app:create-user', [
|
||||
'name' => 'ajaxray',
|
||||
'email' => 'user@ajaxray.com',
|
||||
'password' => '12345678',
|
||||
])->expectsOutputToContain('User created');
|
||||
|
||||
$this->assertDatabaseCount('users', 1);
|
||||
}
|
||||
|
||||
public function test_cannot_create_user_with_invalid_email(): void
|
||||
{
|
||||
$this->artisan('app:create-user', [
|
||||
'name' => 'ajaxray',
|
||||
'email' => 'user@.com',
|
||||
'password' => '222222',
|
||||
])->assertFailed()
|
||||
->expectsOutputToContain('must be a valid email address.');
|
||||
|
||||
$this->assertDatabaseEmpty('users');
|
||||
}
|
||||
|
||||
public function test_cannot_create_user_with_duplicate_name(): void
|
||||
{
|
||||
$this->artisan('app:create-user', [
|
||||
'name' => 'ajaxray',
|
||||
'email' => 'user1@ajaxray.com',
|
||||
'password' => '111111',
|
||||
])->assertSuccessful();
|
||||
|
||||
$this->artisan('app:create-user', [
|
||||
'name' => 'ajaxray',
|
||||
'email' => 'user2@ajaxray.com',
|
||||
'password' => '222222',
|
||||
])->assertFailed()
|
||||
->expectsOutputToContain('name has already been taken.');
|
||||
|
||||
$this->assertDatabaseCount('users', 1);
|
||||
}
|
||||
|
||||
public function test_cannot_create_user_with_duplicate_email(): void
|
||||
{
|
||||
$this->artisan('app:create-user', [
|
||||
'name' => 'user1',
|
||||
'email' => 'user@ajaxray.com',
|
||||
'password' => '111111',
|
||||
])->assertSuccessful();
|
||||
|
||||
$this->artisan('app:create-user', [
|
||||
'name' => 'user2',
|
||||
'email' => 'user@ajaxray.com',
|
||||
'password' => '222222',
|
||||
])->assertFailed()
|
||||
->expectsOutputToContain('email has already been taken.');
|
||||
|
||||
$this->assertDatabaseCount('users', 1);
|
||||
}
|
||||
|
||||
public function test_created_users_are_verified_by_default(): void
|
||||
{
|
||||
$this->assertDatabaseEmpty('users');
|
||||
|
||||
$this->freezeTime(function (Carbon $time) {
|
||||
$dateTimeStr = date('Y-m-d H:i:s');
|
||||
|
||||
$this->artisan('app:create-user', [
|
||||
'name' => 'user1',
|
||||
'email' => 'user@ajaxray.com',
|
||||
'password' => '111111',
|
||||
])->assertSuccessful();
|
||||
|
||||
$this->assertDatabaseHas('users', ['email_verified_at' => $dateTimeStr]);
|
||||
});
|
||||
}
|
||||
|
||||
public function test_created_users_can_be_kept_unverified(): void
|
||||
{
|
||||
$this->assertDatabaseEmpty('users');
|
||||
|
||||
$this->artisan('app:create-user', [
|
||||
'name' => 'user1',
|
||||
'email' => 'user@ajaxray.com',
|
||||
'password' => '111111',
|
||||
'--unverified' => true
|
||||
])->assertSuccessful();
|
||||
|
||||
$this->assertDatabaseHas('users', ['email_verified_at' => null]);
|
||||
}
|
||||
}
|
|
@ -46,16 +46,16 @@ ram.runtime = "100M"
|
|||
default = "all_users"
|
||||
|
||||
# for now no credentials configured, make it install first
|
||||
[install.user]
|
||||
help.en = "The name of the user"
|
||||
type = "text"
|
||||
[install.email]
|
||||
help.en = "The email address used for logging in to the application"
|
||||
type = "email"
|
||||
[install.password]
|
||||
help.en = "Use the help field to add an information for the admin about this question."
|
||||
help.fr = "Utilisez le champ aide pour ajouter une information à l'intention de l'administrateur à propos de cette question."
|
||||
type = "password"
|
||||
# [install.user]
|
||||
# help.en = "The name of the user"
|
||||
# type = "string"
|
||||
# [install.email]
|
||||
# help.en = "The email address used for logging in to the application"
|
||||
# type = "email"
|
||||
# [install.password]
|
||||
# help.en = "Use the help field to add an information for the admin about this question."
|
||||
# help.fr = "Utilisez le champ aide pour ajouter une information à l'intention de l'administrateur à propos de cette question."
|
||||
# type = "password"
|
||||
|
||||
[resources]
|
||||
# See the packaging documentation for the full set
|
||||
|
|
|
@ -47,6 +47,7 @@ chown "$app:www-data" "$install_dir/.env"
|
|||
# Inject CreateUser.php into app/Console/Commands/ to extend the upstream version with this functionality
|
||||
# Using this, we can create the user with the credentials provided
|
||||
ynh_config_add --template=CreateUser.php --destination="$install_dir/app/Console/Commands/CreateUser.php"
|
||||
ynh_config_add --template=CreateUserTest.php --destination="$install_dir/app/Console/Commands/CreateUserTest.php"
|
||||
|
||||
#=================================================
|
||||
# SYSTEM CONFIGURATION
|
||||
|
|
Loading…
Add table
Reference in a new issue