laravel / framework

The Laravel Framework.
https://laravel.com
MIT License
32.52k stars 11.02k forks source link

'tests/Feature/EmailVerificationTest.php' failed after enable email verification #35970

Closed fen9li closed 3 years ago

fen9li commented 3 years ago

Description:

'tests/Feature/EmailVerificationTest.php' failed after enable email verification

Steps To Reproduce:

  1. Install Laravel 8 with JetStream, Inertia stack with teams. Migrate.
  2. Run all 'tests/Feature/*' successfully.
  3. Make below changes to enable email verification.
$ git diff
diff --git a/app/Models/User.php b/app/Models/User.php
index 3481e75..ea2f8c4 100644
--- a/app/Models/User.php
+++ b/app/Models/User.php
@@ -11,7 +11,7 @@ use Laravel\Jetstream\HasProfilePhoto;
 use Laravel\Jetstream\HasTeams;
 use Laravel\Sanctum\HasApiTokens;

-class User extends Authenticatable
+class User extends Authenticatable implements MustVerifyEmail
 {
     use HasApiTokens;
     use HasFactory;
diff --git a/config/fortify.php b/config/fortify.php
index 0226449..b64a87a 100644
--- a/config/fortify.php
+++ b/config/fortify.php
@@ -134,7 +134,7 @@ return [
     'features' => [
         Features::registration(),
         Features::resetPasswords(),
-        // Features::emailVerification(),
+        Features::emailVerification(),
         Features::updateProfileInformation(),
         Features::updatePasswords(),
         Features::twoFactorAuthentication([
$
  1. Run below test failed
$ sail test tests/Feature/EmailVerificationTest.php 

   FAIL  Tests\Feature\EmailVerificationTest
  ⨯ email verification screen can be rendered
  ✓ email can be verified
  ✓ email can not verified with invalid hash

  ---

  • Tests\Feature\EmailVerificationTest > email verification screen can be rendered
  Expected status code 200 but received 500.
  Failed asserting that 200 is identical to 500.

  at tests/Feature/EmailVerificationTest.php:30
     26▕         ]);
     27▕ 
     28▕         $response = $this->actingAs($user)->get('/email/verify');
     29▕ 
  ➜  30▕         $response->assertStatus(200);
     31▕     }
     32▕ 
     33▕     public function test_email_can_be_verified()
     34▕     {

  Tests:  1 failed, 2 passed
  Time:   17.19s

$ 

However, when I tried to register user manually, it works well. Please help on this. Thank you!

driesvints commented 3 years ago

Hi there,

Thanks for reporting but it looks like this is a question which can be asked on a support channel. Please only use this issue tracker for reporting bugs with the library itself. If you have a question on how to use functionality provided by this repo you can try one of the following channels:

However, this issue will not be locked and everyone is still free to discuss solutions to your problem!

Thanks.

SimplyCorey commented 3 years ago

Anyone who comes across this can modify the test to this if they have teams enabled to get this to pass:

    public function test_email_verification_screen_can_be_rendered()
    {
        if (! Features::enabled(Features::emailVerification())) {
            return $this->markTestSkipped('Email verification not enabled.');
        }

        $user = User::factory()
            ->withPersonalTeam()
            ->create([
                'email_verified_at' => null,
            ]);

        $response = $this->actingAs($user)->get('/email/verify');

        $response->assertStatus(200);
    }