diff --git a/src/tests/Feature/SignupCodeTest.php b/src/tests/Feature/SignupCodeTest.php index 78321c21..d6576559 100644 --- a/src/tests/Feature/SignupCodeTest.php +++ b/src/tests/Feature/SignupCodeTest.php @@ -1,53 +1,45 @@ [ 'email' => 'User@email.org', ] ]; $now = Carbon::now(); $code = SignupCode::create($data); + $code_length = env('VERIFICATION_CODE_LENGTH', SignupCode::SHORTCODE_LENGTH); + $exp = Carbon::now()->addHours(env('SIGNUP_CODE_EXPIRY', SignupCode::CODE_EXP_HOURS)); + $this->assertFalse($code->isExpired()); $this->assertTrue(strlen($code->code) === SignupCode::CODE_LENGTH); - - $this->assertTrue( - strlen($code->short_code) === env( - 'VERIFICATION_CODE_LENGTH', - SignupCode::SHORTCODE_LENGTH - ) - ); - + $this->assertTrue(strlen($code->short_code) === $code_length); $this->assertSame($data['data'], $code->data); $this->assertInstanceOf(Carbon::class, $code->expires_at); - - $this->assertSame( - env('SIGNUP_CODE_EXPIRY', SignupCode::CODE_EXP_HOURS), - $code->expires_at->diffInHours($now) + 1 - ); + $this->assertSame($code->expires_at->toDateTimeString(), $exp->toDateTimeString()); $inst = SignupCode::find($code->code); $this->assertInstanceOf(SignupCode::class, $inst); $this->assertSame($inst->code, $code->code); } } diff --git a/src/tests/Feature/VerificationCodeTest.php b/src/tests/Feature/VerificationCodeTest.php index d130ea3b..4742ff5e 100644 --- a/src/tests/Feature/VerificationCodeTest.php +++ b/src/tests/Feature/VerificationCodeTest.php @@ -1,59 +1,60 @@ deleteTestUser('UserAccountA@UserAccount.com'); } public function tearDown(): void { $this->deleteTestUser('UserAccountA@UserAccount.com'); parent::tearDown(); } /** * Test VerificationCode creation */ public function testVerificationCodeCreate(): void { $user = $this->getTestUser('UserAccountA@UserAccount.com'); $data = [ 'user_id' => $user->id, 'mode' => 'password-reset', ]; $now = new \DateTime('now'); $code = VerificationCode::create($data); $code_length = env('VERIFICATION_CODE_LENGTH', VerificationCode::SHORTCODE_LENGTH); $code_exp_hrs = env('VERIFICATION_CODE_EXPIRY', VerificationCode::CODE_EXP_HOURS); + $exp = Carbon::now()->addHours($code_exp_hrs); $this->assertFalse($code->isExpired()); $this->assertTrue(strlen($code->code) === VerificationCode::CODE_LENGTH); $this->assertTrue(strlen($code->short_code) === $code_length); $this->assertSame($data['mode'], $code->mode); $this->assertEquals($user->id, $code->user->id); $this->assertInstanceOf(\DateTime::class, $code->expires_at); - - $this->assertSame($code_exp_hrs, $code->expires_at->diff($now)->h + 1); + $this->assertSame($code->expires_at->toDateTimeString(), $exp->toDateTimeString()); $inst = VerificationCode::find($code->code); $this->assertInstanceOf(VerificationCode::class, $inst); $this->assertSame($inst->code, $code->code); } }