633Innovations

Knowledgebase | Documentation


TestCase - Setting up the test environment.

<?php

namespace Tests;

use Illuminate\Contracts\Auth\Authenticatable;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Foundation\Testing\TestCase as BaseTestCase;
use Illuminate\Foundation\Testing\WithFaker;
use Modules\User\Models\User;

abstract class TestCase extends BaseTestCase
{
    use RefreshDatabase;
    use WithFaker;

    protected $start_time;

    protected Authenticatable $user;

    /**
     * Set up the test environment.
     */
    protected function setUp(): void
    {
        parent::setUp();

        $this->start_time = microtime(true);

        $this->user = User::factory()->create();
        $this->actingAs($this->user);
    }
}

Like the __construct() in Controller and mount() in a Livewire component, the setUp() method is use to set up the test environment.

The TestCase class is an intermediate class that bridges the base TestCase and the actual test class we create.

The properties and methods defined here are accessible from your custom test classes.

However, this class like every other arbitrage class should always remain light and basic.