Page MenuHomePhorge

VerificationCodeTest.php
No OneTemporary

Authored By
Unknown
Size
2 KB
Referenced Files
None
Subscribers
None

VerificationCodeTest.php

<?php
namespace Tests\Feature;
use App\User;
use App\VerificationCode;
use Carbon\Carbon;
use Tests\TestCase;
class VerificationCodeTest extends TestCase
{
public function setUp(): void
{
parent::setUp();
$this->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->assertTrue($code->active);
$this->assertSame($data['mode'], $code->mode);
$this->assertEquals($user->id, $code->user->id);
$this->assertInstanceOf(\DateTime::class, $code->expires_at);
$this->assertSame($code->expires_at->toDateTimeString(), $exp->toDateTimeString());
$inst = VerificationCode::find($code->code);
$this->assertInstanceOf(VerificationCode::class, $inst);
$this->assertSame($inst->code, $code->code);
// Custom active flag and custom expires_at
$data['expires_at'] = Carbon::now()->addDays(10);
$data['active'] = false;
$code = VerificationCode::create($data);
$this->assertFalse($code->active);
$this->assertSame($code->expires_at->toDateTimeString(), $data['expires_at']->toDateTimeString());
}
}

File Metadata

Mime Type
text/x-php
Expires
Fri, Apr 24, 11:01 AM (1 w, 5 d ago)
Storage Engine
local-disk
Storage Format
Raw Data
Storage Handle
03/9b/0aa15777eaa35f8c704c23ae68d1
Default Alt Text
VerificationCodeTest.php (2 KB)

Event Timeline