Unit Tests

Apex utilizes the popular phpUnit package, plus also adds its own layer that includes custom assertions and other methods to aid in testing. For full details, please visit the Unit Tests section of the developer documentation.

Within terminal, run the following create test CLI command:

apex create test disaster projects

Open the newly generated file at /tests/Disaster/ProjectsTest.php and replace it with the following contents:

<?php
declare(strict_types = 1);

namespace Tests\Disaster;

use Apex\Svc\{Di, Db};
use Apex\App\Sys\Tests\ApexTestCase;

/**
 * Projects Test
 */
class ProjectsTest extends ApexTestCase
{

    /**
     * Projects menu
     */
    public function testProjectsMenuAdminPanel():void
    {

        // Login as admin
        $db = Di::get(Db::class);
        $admin_user = $db->getField("SELECT username FROM armor_users WHERE type = 'admin'");
        $this->login($admin_user);

        // Send http request to Projects menu
        $this->http('/admin/disaster/projects');

        // Assertions
        $this->assertPageTitle('Projects');
        $this->assertHasTable('disaster.projects');
    }

}

The above method will login as an admistrator, then proceed to visit the Disaster Relief->Projects menu and ensure the page title is correct and it contains the correct data table.