-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #8 from michaeldyrynda/chore/laravel-5.7-support
Laravel 5.7 support
- Loading branch information
Showing
10 changed files
with
53 additions
and
263 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1 @@ | ||
preset: laravel | ||
|
||
linting: true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
# Laravel Make User | ||
## v3.0.0 | ||
## v4.0.0 | ||
|
||
[![Build Status](https://travis-ci.org/michaeldyrynda/laravel-make-user.svg?branch=master)](https://travis-ci.org/michaeldyrynda/laravel-make-user) | ||
[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/michaeldyrynda/laravel-make-user/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/michaeldyrynda/laravel-make-user/?branch=master) | ||
|
@@ -11,7 +11,7 @@ | |
|
||
## Introduction | ||
|
||
Out of the box, Laravel makes it really simple to scaffold out with its [authentication quickstart](https://laravel.com/docs/5.4/authentication#authentication-quickstart). Whilst this makes it really easy to register and authenticate users, for many of the applications I find myself building, we usually remove the ability for visitors to register themselves. | ||
Out of the box, Laravel makes it really simple to scaffold out with its [authentication quickstart](https://laravel.com/docs/5.7/authentication#authentication-quickstart). Whilst this makes it really easy to register and authenticate users, for many of the applications I find myself building, we usually remove the ability for visitors to register themselves. | ||
|
||
I still need a way to get users into those applications, however, and whilst they're in early development this usually involves firing up Laravel Tinker. This can be a tedious process, and one that I repeat many times over. | ||
|
||
|
@@ -24,45 +24,26 @@ Laravel | Package | |
5.4.* | 1.0.* | ||
5.5.* | 2.0.* | ||
5.6.* | 3.0.* | ||
5.7.* | 4.0.* | ||
|
||
## Code Samples | ||
|
||
This package exposes a `make:user` command, which is accessed via the Artisan command line utility. The package will use the model defined in your `auth.providers.users.model` configuration value. | ||
|
||
``` | ||
php artisan make:user email {--name=NAME} {--password=PASSWORD} {--send-reset} {--fields=FIELDS} {--force} | ||
php artisan make:user | ||
``` | ||
|
||
If the password is not specified, the `--send-reset` option is implicit, sending the default password reset notification to the user. This package does not currently provide support to customise the content or notification sent as my general practice is to create a user account, then have the user manually perform a password reset. The implied `--send-reset` saves a manual step in this process. | ||
|
||
This package runs on the assumption that you are using Laravel's default `users` table structure. If you have additional columns in your database, they can be specified using the `--fields` option, separating each key/value pair with a comma: | ||
|
||
``` | ||
php artisan make:user [email protected] --fields="admin:true,other_field:other value" | ||
``` | ||
|
||
This will create a new user with the email address `[email protected]`, a randomly generated password, send the password reset email to `[email protected]`, and set the `admin` field to `true`. Should you need to circumvent your user model's guarded fields, you can pass the `--force` option, and the user model will be created using the `forceCreate` method. | ||
This package runs on the assumption that you are using Laravel's default `users` table structure. You can specify additional fields when prompted. | ||
|
||
## Installation | ||
|
||
This package is installed via [Composer](https://getcomposer.org/). To install, run the following command. | ||
|
||
```bash | ||
composer require "dyrynda/laravel-make-user:~3.0" | ||
composer require "dyrynda/laravel-make-user:~4.0" | ||
``` | ||
|
||
Then add the service provider to your `config/app.php` file: | ||
|
||
```php | ||
'providers' => [ | ||
// ... | ||
Dyrynda\Artisan\MakeUserServiceProvider::class, | ||
// ... | ||
] | ||
``` | ||
|
||
Note, this package has support for Laravel's auto package discovery, which will be available from version 5.5 onwards. | ||
|
||
## Support | ||
|
||
If you are having general issues with this package, feel free to contact me on [Twitter](https://twitter.com/michaeldyrynda). | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,116 +2,28 @@ | |
|
||
namespace Tests; | ||
|
||
use Illuminate\Support\Facades\Hash; | ||
use Illuminate\Support\Facades\Artisan; | ||
use Illuminate\Support\Facades\Notification; | ||
use Illuminate\Auth\Notifications\ResetPassword; | ||
|
||
class MakeUserTest extends TestCase | ||
{ | ||
/** @test */ | ||
public function it_requires_a_valid_email_address() | ||
{ | ||
Artisan::call('make:user', ['email' => 'invalidemail']); | ||
|
||
$this->assertFalse(User::where('email', 'invalidemail')->exists()); | ||
} | ||
|
||
/** @test */ | ||
public function it_requires_a_unique_email_address() | ||
{ | ||
User::create(['name' => 'Adam Wathan', 'email' => '[email protected]', 'password' => '']); | ||
|
||
$exitCode = Artisan::call('make:user', ['email' => '[email protected]']); | ||
|
||
$this->assertContains('The user was not created', Artisan::output()); | ||
$this->assertEquals(1, User::where('email', '[email protected]')->count()); | ||
} | ||
|
||
/** @test */ | ||
public function it_hashes_the_password_when_specified() | ||
{ | ||
Artisan::call('make:user', ['email' => '[email protected]', '--password' => 'secret']); | ||
|
||
tap(User::first(), function ($user) { | ||
$this->assertTrue(Hash::check('secret', $user->password)); | ||
}); | ||
} | ||
|
||
/** @test */ | ||
public function it_sends_the_password_reset_email_when_generating_a_password() | ||
{ | ||
Notification::fake(); | ||
|
||
Artisan::call('make:user', ['email' => '[email protected]', '--name' => 'Michael Dyrynda']); | ||
|
||
Notification::assertSentTo(User::first(), ResetPassword::class); | ||
|
||
tap(['email' => '[email protected]', 'name' => 'Michael Dyrynda'], function ($credentials) { | ||
$this->assertTrue(User::where($credentials)->exists()); | ||
$this->assertEquals(1, User::where($credentials)->count()); | ||
}); | ||
} | ||
|
||
/** @test */ | ||
public function it_does_not_send_the_password_reset_email_when_the_password_is_specified() | ||
{ | ||
Notification::fake(); | ||
|
||
Artisan::call('make:user', ['email' => '[email protected]', '--password' => 'secret']); | ||
|
||
Notification::assertNotSentTo(User::first(), ResetPassword::class); | ||
|
||
tap(['email' => '[email protected]'], function ($credentials) { | ||
$this->assertTrue(User::where($credentials)->exists()); | ||
$this->assertEquals(1, User::where($credentials)->count()); | ||
}); | ||
} | ||
|
||
/** @test */ | ||
public function it_sends_the_password_reset_email_when_flagged_to_do_so() | ||
{ | ||
Notification::fake(); | ||
|
||
Artisan::call('make:user', ['email' => '[email protected]', '--password' => 'secret', '--send-reset' => true]); | ||
|
||
Notification::assertSentTo(User::first(), ResetPassword::class); | ||
} | ||
|
||
/** @test */ | ||
public function it_fills_additional_fields_when_specified() | ||
public function it_creates_a_new_user() | ||
{ | ||
Artisan::call('make:user', ['email' => '[email protected]', '--password' => 'secret', '--fields' => 'admin:true']); | ||
|
||
$this->assertTrue(User::where([ | ||
'email' => '[email protected]', | ||
'admin' => true, | ||
])->exists()); | ||
$this->artisan('make:user') | ||
->expectsQuestion("What is the new user's email address?", '[email protected]') | ||
->expectsQuestion("What is the new user's name?", 'Test User') | ||
->expectsQuestion("What is the new user's password? (blank generates a random one)", '') | ||
->expectsQuestion('Do you want to send a password reset email?', 'no') | ||
->expectsQuestion('Do you have any custom user fields to add? Field=Value (blank continues)', ''); | ||
} | ||
|
||
/** @test */ | ||
public function it_handles_null_field_values_correctly() | ||
public function it_creates_a_new_user_with_additional_fields() | ||
{ | ||
Artisan::call('make:user', ['email' => '[email protected]', '--fields' => 'force_filled:null']); | ||
|
||
tap(User::first(), function ($user) { | ||
$this->assertNull($user->force_filled); | ||
}); | ||
} | ||
|
||
/** @test */ | ||
public function it_force_filles_guarded_properties_when_instructed() | ||
{ | ||
Artisan::call('make:user', [ | ||
'email' => '[email protected]', | ||
'--password' => 'secret', | ||
'--force' => true, | ||
'--fields' => 'admin:false,force_filled:string field', | ||
]); | ||
|
||
tap(User::first(), function ($user) { | ||
$this->assertFalse($user->admin); | ||
$this->assertEquals('string field', $user->force_filled); | ||
}); | ||
$this->artisan('make:user') | ||
->expectsQuestion("What is the new user's email address?", '[email protected]') | ||
->expectsQuestion("What is the new user's name?", 'Test User') | ||
->expectsQuestion("What is the new user's password? (blank generates a random one)", '') | ||
->expectsQuestion('Do you want to send a password reset email?', 'no') | ||
->expectsQuestion('Do you have any custom user fields to add? Field=Value (blank continues)', 'field=value') | ||
->expectsQuestion('Do you have any custom user fields to add? Field=Value (blank continues)', ''); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.