diff --git a/.github/actions/common/setup b/.github/actions/common/setup index b6a775b..b5ded99 100644 --- a/.github/actions/common/setup +++ b/.github/actions/common/setup @@ -5,7 +5,7 @@ commit="tmp-$(git rev-parse --verify HEAD)" git checkout -b $commit # Create Laravel project -composer create-project --prefer-dist laravel/laravel test-app '7.*' +composer create-project --prefer-dist laravel/laravel test-app '8.*' cd test-app # Require Laravel auth preset and setup views diff --git a/.github/actions/tests-with-email-verification b/.github/actions/tests-with-email-verification index 7387cc5..46eec69 100644 --- a/.github/actions/tests-with-email-verification +++ b/.github/actions/tests-with-email-verification @@ -8,4 +8,4 @@ php artisan make:auth-tests # Prepare for running tests sed -i 's###g' phpunit.xml sed -i $'s#Auth::routes();#Auth::routes(\[\'verify\' => true\]);#g' ./routes/web.php -sed -i 's#extends Authenticatable#extends Authenticatable implements MustVerifyEmail#g' ./app/User.php +sed -i 's#extends Authenticatable#extends Authenticatable implements MustVerifyEmail#g' ./app/Models/User.php diff --git a/.github/workflows/run-tests-on-laravel.yml b/.github/workflows/run-tests-on-laravel.yml index 3db33d7..83a88e3 100644 --- a/.github/workflows/run-tests-on-laravel.yml +++ b/.github/workflows/run-tests-on-laravel.yml @@ -9,11 +9,11 @@ on: jobs: test_without_email_verification: - name: (PHP ${{ matrix.php }}, Laravel 7) Tests without email verification + name: (PHP ${{ matrix.php }}, Laravel 8) Tests without email verification runs-on: ubuntu-latest strategy: matrix: - php: ['7.2', '7.3', '7.4'] + php: ['7.3', '7.4'] steps: - uses: actions/checkout@v2 @@ -37,11 +37,11 @@ jobs: run: ( cd test-app && ./vendor/bin/phpunit ) test_with_email_verification: - name: (PHP ${{ matrix.php }}, Laravel 7) Tests with email verification + name: (PHP ${{ matrix.php }}, Laravel 8) Tests with email verification runs-on: ubuntu-latest strategy: matrix: - php: ['7.2', '7.3', '7.4'] + php: ['7.3', '7.4'] steps: - uses: actions/checkout@v2 diff --git a/README.md b/README.md index 89d6015..fc0c1ca 100644 --- a/README.md +++ b/README.md @@ -5,6 +5,13 @@ ![](https://i.imgur.com/1z5XkDc.png) +## ⚠️ Deprecation notice ⚠️ +As of Laravel 8, the [laravel/ui](https://github.com/laravel/ui) package is discouraged to be used on new Laravel installations. **This package should be used only with already-existing, created with Laravel 7 or lower, applications that use laravel/ui auth controllers.** + +All of the applications already using [laravel/ui](https://github.com/laravel/ui) will get updates of this package to new Laravel versions, although the support may be dropped in the future. This doesn't mean you won't be able to use the package or upgrade to new Laravel versions, but that the upgrades to the major versions may require manual changes from the consumers of this package. + +The new way of installing Laravel 8's and above auth scaffolding is using the `--jet` option in the Laravel installer. Laravel [Jetstream](https://github.com/laravel/jetstream) hides all of its controllers inside the package, meaning it doesn't make sense to test those controllers, as they [are already tested inside the package](https://github.com/laravel/jetstream/tree/1.x/tests). + ## 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.*`.~ @@ -37,7 +44,7 @@ If you want to use the e-mail verification feature, you will have to make follow - Auth::routes(); + Auth::routes(['verify' => true]); ``` -- update `app/User.php`: +- update `app/Models/User.php`: ```diff - class User extends Authenticatable + class User extends Authenticatable implements MustVerifyEmail diff --git a/composer.json b/composer.json index c17d9bd..cef6d1f 100644 --- a/composer.json +++ b/composer.json @@ -10,7 +10,7 @@ } ], "require": { - "laravel/framework": "^7.0" + "laravel/framework": "^8.0" }, "extra": { "laravel": { diff --git a/src/AuthTestsServiceProvider.php b/src/AuthTestsServiceProvider.php index 04941ca..1488d59 100644 --- a/src/AuthTestsServiceProvider.php +++ b/src/AuthTestsServiceProvider.php @@ -2,8 +2,8 @@ namespace DCzajkowski\AuthTests; -use Illuminate\Support\ServiceProvider; use DCzajkowski\AuthTests\Console\Commands\AuthTestsMakeCommand; +use Illuminate\Support\ServiceProvider; class AuthTestsServiceProvider extends ServiceProvider { diff --git a/src/Console/stubs/tests/Feature/Auth/EmailVerificationTest.php b/src/Console/stubs/tests/Feature/Auth/EmailVerificationTest.php index a266c31..c8def6b 100644 --- a/src/Console/stubs/tests/Feature/Auth/EmailVerificationTest.php +++ b/src/Console/stubs/tests/Feature/Auth/EmailVerificationTest.php @@ -2,12 +2,12 @@ namespace Tests\Feature\Auth; -use App\User; -use Tests\TestCase; -use Illuminate\Support\Facades\URL; -use Illuminate\Support\Facades\Notification; +use App\Models\User; use Illuminate\Auth\Notifications\VerifyEmail; use Illuminate\Foundation\Testing\RefreshDatabase; +use Illuminate\Support\Facades\Notification; +use Illuminate\Support\Facades\URL; +use Tests\TestCase; class EmailVerificationTest extends TestCase { @@ -60,7 +60,7 @@ public function testGuestCannotSeeTheVerificationNotice() public function testUserSeesTheVerificationNoticeWhenNotVerified() { - $user = factory(User::class)->create([ + $user = User::factory()->create([ 'email_verified_at' => null, ]); @@ -72,7 +72,7 @@ public function testUserSeesTheVerificationNoticeWhenNotVerified() public function testVerifiedUserIsRedirectedHomeWhenVisitingVerificationNoticeRoute() { - $user = factory(User::class)->create([ + $user = User::factory()->create([ 'email_verified_at' => now(), ]); @@ -83,7 +83,7 @@ public function testVerifiedUserIsRedirectedHomeWhenVisitingVerificationNoticeRo public function testGuestCannotSeeTheVerificationVerifyRoute() { - $user = factory(User::class)->create([ + $user = User::factory()->create([ 'id' => 1, 'email_verified_at' => null, ]); @@ -95,12 +95,12 @@ public function testGuestCannotSeeTheVerificationVerifyRoute() public function testUserCannotVerifyOthers() { - $user = factory(User::class)->create([ + $user = User::factory()->create([ 'id' => 1, 'email_verified_at' => null, ]); - $user2 = factory(User::class)->create(['id' => 2, 'email_verified_at' => null]); + $user2 = User::factory()->create(['id' => 2, 'email_verified_at' => null]); $response = $this->actingAs($user)->get($this->validVerificationVerifyRoute($user2)); @@ -110,7 +110,7 @@ public function testUserCannotVerifyOthers() public function testUserIsRedirectedToCorrectRouteWhenAlreadyVerified() { - $user = factory(User::class)->create([ + $user = User::factory()->create([ 'email_verified_at' => now(), ]); @@ -121,7 +121,7 @@ public function testUserIsRedirectedToCorrectRouteWhenAlreadyVerified() public function testForbiddenIsReturnedWhenSignatureIsInvalidInVerificationVerifyRoute() { - $user = factory(User::class)->create([ + $user = User::factory()->create([ 'email_verified_at' => now(), ]); @@ -132,7 +132,7 @@ public function testForbiddenIsReturnedWhenSignatureIsInvalidInVerificationVerif public function testUserCanVerifyThemselves() { - $user = factory(User::class)->create([ + $user = User::factory()->create([ 'email_verified_at' => null, ]); @@ -151,7 +151,7 @@ public function testGuestCannotResendAVerificationEmail() public function testUserIsRedirectedToCorrectRouteIfAlreadyVerified() { - $user = factory(User::class)->create([ + $user = User::factory()->create([ 'email_verified_at' => now(), ]); @@ -163,7 +163,7 @@ public function testUserIsRedirectedToCorrectRouteIfAlreadyVerified() public function testUserCanResendAVerificationEmail() { Notification::fake(); - $user = factory(User::class)->create([ + $user = User::factory()->create([ 'email_verified_at' => null, ]); diff --git a/src/Console/stubs/tests/Feature/Auth/ForgotPasswordTest.php b/src/Console/stubs/tests/Feature/Auth/ForgotPasswordTest.php index bb78260..f76ed41 100644 --- a/src/Console/stubs/tests/Feature/Auth/ForgotPasswordTest.php +++ b/src/Console/stubs/tests/Feature/Auth/ForgotPasswordTest.php @@ -2,13 +2,13 @@ namespace Tests\Feature\Auth; -use App\User; -use Tests\TestCase; +use App\Models\User; +use Illuminate\Auth\Notifications\ResetPassword; +use Illuminate\Foundation\Testing\RefreshDatabase; use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\Hash; use Illuminate\Support\Facades\Notification; -use Illuminate\Auth\Notifications\ResetPassword; -use Illuminate\Foundation\Testing\RefreshDatabase; +use Tests\TestCase; class ForgotPasswordTest extends TestCase { @@ -39,7 +39,7 @@ public function testUserCanViewAnEmailPasswordForm() public function testUserCanViewAnEmailPasswordFormWhenAuthenticated() { - $user = factory(User::class)->make(); + $user = User::factory()->make(); $response = $this->actingAs($user)->get($this->passwordRequestRoute()); @@ -50,7 +50,7 @@ public function testUserCanViewAnEmailPasswordFormWhenAuthenticated() public function testUserReceivesAnEmailWithAPasswordResetLink() { Notification::fake(); - $user = factory(User::class)->create([ + $user = User::factory()->create([ 'email' => 'john@example.com', ]); @@ -74,7 +74,7 @@ public function testUserDoesNotReceiveEmailWhenNotRegistered() $response->assertRedirect($this->passwordEmailGetRoute()); $response->assertSessionHasErrors('email'); - Notification::assertNotSentTo(factory(User::class)->make(['email' => 'nobody@example.com']), ResetPassword::class); + Notification::assertNotSentTo(User::factory()->make(['email' => 'nobody@example.com']), ResetPassword::class); } public function testEmailIsRequired() diff --git a/src/Console/stubs/tests/Feature/Auth/LoginTest.php b/src/Console/stubs/tests/Feature/Auth/LoginTest.php index ad6aaf2..811223c 100644 --- a/src/Console/stubs/tests/Feature/Auth/LoginTest.php +++ b/src/Console/stubs/tests/Feature/Auth/LoginTest.php @@ -2,11 +2,11 @@ namespace Tests\Feature\Auth; -use App\User; -use Tests\TestCase; +use App\Models\User; +use Illuminate\Foundation\Testing\RefreshDatabase; use Illuminate\Support\Facades\Auth; use Illuminate\Support\Facades\Hash; -use Illuminate\Foundation\Testing\RefreshDatabase; +use Tests\TestCase; class LoginTest extends TestCase { @@ -57,7 +57,7 @@ public function testUserCanViewALoginForm() public function testUserCannotViewALoginFormWhenAuthenticated() { - $user = factory(User::class)->make(); + $user = User::factory()->make(); $response = $this->actingAs($user)->get($this->loginGetRoute()); @@ -66,7 +66,7 @@ public function testUserCannotViewALoginFormWhenAuthenticated() public function testUserCanLoginWithCorrectCredentials() { - $user = factory(User::class)->create([ + $user = User::factory()->create([ 'password' => Hash::make($password = 'i-love-laravel'), ]); @@ -81,7 +81,7 @@ public function testUserCanLoginWithCorrectCredentials() public function testRememberMeFunctionality() { - $user = factory(User::class)->create([ + $user = User::factory()->create([ 'id' => random_int(1, 100), 'password' => Hash::make($password = 'i-love-laravel'), ]); @@ -105,7 +105,7 @@ public function testRememberMeFunctionality() public function testUserCannotLoginWithIncorrectPassword() { - $user = factory(User::class)->create([ + $user = User::factory()->create([ 'password' => Hash::make('i-love-laravel'), ]); @@ -137,7 +137,7 @@ public function testUserCannotLoginWithEmailThatDoesNotExist() public function testUserCanLogout() { - $this->be(factory(User::class)->create()); + $this->be(User::factory()->create()); $response = $this->post($this->logoutRoute()); @@ -155,7 +155,7 @@ public function testUserCannotLogoutWhenNotAuthenticated() public function testUserCannotMakeMoreThanFiveAttemptsInOneMinute() { - $user = factory(User::class)->create([ + $user = User::factory()->create([ 'password' => Hash::make($password = 'i-love-laravel'), ]); @@ -168,7 +168,7 @@ public function testUserCannotMakeMoreThanFiveAttemptsInOneMinute() $response->assertRedirect($this->loginGetRoute()); $response->assertSessionHasErrors('email'); - $this->assertRegExp( + $this->assertMatchesRegularExpression( $this->getTooManyLoginAttemptsMessage(), collect( $response diff --git a/src/Console/stubs/tests/Feature/Auth/RegisterTest.php b/src/Console/stubs/tests/Feature/Auth/RegisterTest.php index c8e85e3..d38a685 100644 --- a/src/Console/stubs/tests/Feature/Auth/RegisterTest.php +++ b/src/Console/stubs/tests/Feature/Auth/RegisterTest.php @@ -2,12 +2,12 @@ namespace Tests\Feature\Auth; -use App\User; -use Tests\TestCase; -use Illuminate\Support\Facades\Hash; -use Illuminate\Support\Facades\Event; +use App\Models\User; use Illuminate\Auth\Events\Registered; use Illuminate\Foundation\Testing\RefreshDatabase; +use Illuminate\Support\Facades\Event; +use Illuminate\Support\Facades\Hash; +use Tests\TestCase; class RegisterTest extends TestCase { @@ -43,7 +43,7 @@ public function testUserCanViewARegistrationForm() public function testUserCannotViewARegistrationFormWhenAuthenticated() { - $user = factory(User::class)->make(); + $user = User::factory()->make(); $response = $this->actingAs($user)->get($this->registerGetRoute()); diff --git a/src/Console/stubs/tests/Feature/Auth/ResetPasswordTest.php b/src/Console/stubs/tests/Feature/Auth/ResetPasswordTest.php index ccbad05..da57c4d 100644 --- a/src/Console/stubs/tests/Feature/Auth/ResetPasswordTest.php +++ b/src/Console/stubs/tests/Feature/Auth/ResetPasswordTest.php @@ -2,13 +2,13 @@ namespace Tests\Feature\Auth; -use App\User; -use Tests\TestCase; -use Illuminate\Support\Facades\Hash; -use Illuminate\Support\Facades\Event; -use Illuminate\Support\Facades\Password; +use App\Models\User; use Illuminate\Auth\Events\PasswordReset; use Illuminate\Foundation\Testing\RefreshDatabase; +use Illuminate\Support\Facades\Event; +use Illuminate\Support\Facades\Hash; +use Illuminate\Support\Facades\Password; +use Tests\TestCase; class ResetPasswordTest extends TestCase { @@ -41,7 +41,7 @@ protected function successfulPasswordResetRoute() public function testUserCanViewAPasswordResetForm() { - $user = factory(User::class)->create(); + $user = User::factory()->create(); $response = $this->get($this->passwordResetGetRoute($token = $this->getValidToken($user))); @@ -52,7 +52,7 @@ public function testUserCanViewAPasswordResetForm() public function testUserCanViewAPasswordResetFormWhenAuthenticated() { - $user = factory(User::class)->create(); + $user = User::factory()->create(); $response = $this->actingAs($user)->get($this->passwordResetGetRoute($token = $this->getValidToken($user))); @@ -64,7 +64,7 @@ public function testUserCanViewAPasswordResetFormWhenAuthenticated() public function testUserCanResetPasswordWithValidToken() { Event::fake(); - $user = factory(User::class)->create(); + $user = User::factory()->create(); $response = $this->post($this->passwordResetPostRoute(), [ 'token' => $this->getValidToken($user), @@ -84,7 +84,7 @@ public function testUserCanResetPasswordWithValidToken() public function testUserCannotResetPasswordWithInvalidToken() { - $user = factory(User::class)->create([ + $user = User::factory()->create([ 'password' => Hash::make('old-password'), ]); @@ -103,7 +103,7 @@ public function testUserCannotResetPasswordWithInvalidToken() public function testUserCannotResetPasswordWithoutProvidingANewPassword() { - $user = factory(User::class)->create([ + $user = User::factory()->create([ 'password' => Hash::make('old-password'), ]); @@ -125,7 +125,7 @@ public function testUserCannotResetPasswordWithoutProvidingANewPassword() public function testUserCannotResetPasswordWithoutProvidingAnEmail() { - $user = factory(User::class)->create([ + $user = User::factory()->create([ 'password' => Hash::make('old-password'), ]);