Tests
When you run the Modular Installer, it will publish the tests for the provided Modules (like User Module, ACL Module, etc) to the Tests
directory of each respective module. The tests are written using the Pest 3 PHP Testing Framework.
Setting Up the Tests
Before running the initial test suite for your Modular installation, make the following changes in your ./phpunit.xml
file:
- Add the new
Modules
testsuite entry. - Ensure you uncomment the
DB_CONNECTION
andDB_DATABASE
lines.
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="vendor/phpunit/phpunit/phpunit.xsd"
bootstrap="vendor/autoload.php"
colors="true"
>
<testsuites>
<testsuite name="Unit">
<directory>tests/Unit</directory>
</testsuite>
<testsuite name="Feature">
<directory>tests/Feature</directory>
</testsuite>
<testsuite name="Modules">
<directory>modules/*/Tests</directory>
</testsuite>
</testsuites>
<source>
<include>
<directory>app</directory>
</include>
</source>
<php>
<env name="APP_ENV" value="testing"/>
<env name="BCRYPT_ROUNDS" value="4"/>
<env name="CACHE_DRIVER" value="array"/>
<env name="DB_CONNECTION" value="sqlite"/>
<env name="DB_DATABASE" value=":memory:"/>
<env name="MAIL_MAILER" value="array"/>
<env name="QUEUE_CONNECTION" value="sync"/>
<env name="SESSION_DRIVER" value="array"/>
<env name="TELESCOPE_ENABLED" value="false"/>
</php>
</phpunit>
Running the Tests
You can run the initial Test Suite by typing the following command in your Terminal (from your project root directory):
./vendor/bin/pest
The result will be similar to:
PASS Tests\Feature\Auth\AuthenticationTest
✓ login screen can be rendered 0.19s
✓ users can authenticate using the login screen 0.09s
✓ users can not authenticate with invalid password 0.01s
✓ users can logout 0.02s
PASS Tests\Feature\Auth\PasswordResetTest
✓ reset password link screen can be rendered 0.01s
✓ reset password link can be requested 0.02s
✓ reset password screen can be rendered 0.01s
✓ password can be reset with valid token 0.02s
PASS Tests\Feature\Dashboard\DashboardTest
✓ it can render the dashboard page 0.02s
PASS Tests\Feature\Permission\GetUserPermissionTest
✓ user permission service returns correct direct permissions for the… 0.01s
✓ user permission service returns correct empty permissions for the u… 0.01s
✓ user permission service returns correct role permissions for the us… 0.01s
✓ user permission service returns correct direct and role permissions… 0.01s
PASS Tests\Feature\Permission\PermissionTest
✓ permission list can be rendered 0.02s
✓ permission can be created 0.01s
✓ permission edit can be rendered 0.01s
✓ permission can be updated 0.01s
✓ permission can be deleted 0.01s
PASS Tests\Feature\Role\RolePermissionTest
✓ role permissions can be rendered 0.02s
✓ role permissions can be updated 0.01s
PASS Tests\Feature\Role\RoleTest
✓ role list can be rendered 0.01s
✓ role can be created 0.01s
✓ role edit can be rendered 0.01s
✓ role can be updated 0.01s
✓ role can be deleted 0.01s
PASS Tests\Feature\Support\ActivityLogTraitTest
✓ it logs the activity for the model 0.01s
PASS Tests\Feature\Support\EditorImageTraitTest
✓ it can upload an image to the default editor media file path 0.02s
PASS Tests\Feature\Support\FileNameGeneratorTraitTest
✓ it can set the name of a uploaded file 0.01s
PASS Tests\Feature\Support\SearchableTraitTest
✓ it returns empty collection if no result is found 0.01s
✓ it can search a single database column 0.01s
✓ it can search multiple database columns 0.01s
PASS Tests\Feature\Support\UpdateOrderTraitTest
✓ it can update the order of the model items 0.01s
PASS Tests\Feature\Support\UploadFileTraitTest
✓ it can handle requests without uploads 0.01s
✓ it can handle requests with wrong inputs 0.01s
PASS Tests\Feature\User\UserPermissionTest
✓ user permissions can be rendered 0.01s
✓ user permissions can be updated 0.02s
PASS Tests\Feature\User\UserRoleTest
✓ user roles can be rendered 0.02s
✓ user roles can be updated 0.01s
PASS Tests\Feature\User\UserTest
✓ user list can be rendered 0.01s
✓ user can be created 0.01s
✓ user edit can be rendered 0.01s
✓ user can be updated 0.01s
✓ user can be deleted 0.01s
Tests: 45 passed (370 assertions)
Duration: 0.96s
Writing Tests
As you create new modules, it is recommended that you write tests for them.
Modular provides a generator specifically for tests. This tool can be used to create a new test file for a given module, equipped with a basic blueprint.
The initial tests included in Modular's Core Modules serve as a useful starting point for your own tests. They cover all CRUD operations and include Inertia.js Specific Tests Syntax. For more information about testing, refer to the Pest 3 Testing Framework documentation and Testing Section of the Laravel Docs.