DCzajkowski / auth-tests by DCzajkowski

Authentication tests for Laravel built-in authentication module.
60,248
238
9
Package Data
Maintainer Username: DCzajkowski
Maintainer Contact: dare.czajkowski@gmail.com (Dariusz Czajkowski)
Package Create Date: 2017-09-28
Package Last Update: 2021-03-05
Home Page:
Language: PHP
License: MIT
Last Refreshed: 2024-04-18 15:26:51
Package Statistics
Total Downloads: 60,248
Monthly Downloads: 14
Daily Downloads: 0
Total Stars: 238
Total Watchers: 9
Total Forks: 26
Total Open Issues: 1

Missing tests for Laravel's auth module

Latest Stable Version License MIT PRs Welcome

Versioning

~The version of this package reflects current major version of the Laravel framework. For example: If Laravel framework has version 5.6, version of this package compatible will be 5.6.*.~

Due to changes in Laravel's versioning scheme, version 6.1.* will aim to be compatible with a version 6.1.* of Laravel. For example, auth-tests version 6.1.1 and 6.1.20 will be all compatible with Laravel 6.1.*

Installation

Before installation please make sure you have scaffolded frontend views with a --auth flag e.g.

composer require laravel/ui && php artisan ui vue --auth
composer require dczajkowski/auth-tests --dev
php artisan make:auth-tests --without-email-verification

Edit phpunit.xml file by adding these two lines between <php> tags:

<server name="DB_CONNECTION" value="sqlite"/>
<server name="DB_DATABASE" value=":memory:"/>

Alternatively, use different database than sqlite, but also different from the one used for development.

Using the e-mail verification feature

If you want to use the e-mail verification feature, you will have to make following changes:

  • update routes/web.php:
- Auth::routes();
+ Auth::routes(['verify' => true]);
  • update app/User.php:
- class User extends Authenticatable
+ class User extends Authenticatable implements MustVerifyEmail

Options

There are four flags for customizing your tests. You can use any combination of them. (All flags have their short version e.g. --zonda or -z)

# make:auth-tests
public function testUserCanLogout()
{
    //
}

# make:auth-tests --snake-case
public function test_user_can_logout()
{
    //
}

# make:auth-tests --annotation
/** @test */
public function userCanLogout()
{
    //
}

# make:auth-tests --public
function testUserCanLogout()
{
    //
}

# make:auth-tests --curly
public function testUserCanLogout() {
    //
}

# make:auth-tests -caps # or --zonda
/** @test */
function user_can_logout() {
    //
}

Since version 5.7 there has been a new test for email verification added. You can omit it by running --without-email-verification.

To review all flags run php artisan make:auth-tests --help.

Updating

To update tests when a new version of this package arrives:

composer update dczajkowski/auth-tests
php artisan make:auth-tests

Warning! All changes to the files this package provides will be lost when running this command!

Automate your workflow

Instead of including this package manually every project you create, simply create a bash function that will do that for you. I have included my personal function here. Feel free to edit it and reuse however you like.

Contributing

Feel free to make PRs to this repo.

License

This package is open-source software licensed under the MIT license (same as Laravel itself).