Getting Started with Testing

Guide for testing applications built with Stilmark Base.

Testing Setup

PHPUnit Installation

Add PHPUnit to your project:

composer require --dev phpunit/phpunit

Directory Structure

Organize your tests following PSR-4 conventions:

tests/
├── Unit/
│   ├── EnvTest.php
│   ├── RequestTest.php
│   └── ControllerTest.php
├── Integration/
│   ├── AuthTest.php
│   └── RouterTest.php
└── bootstrap.php

Test Bootstrap

Create tests/bootstrap.php:

Unit Testing Examples

Testing Environment Management

Testing Request Handling

Testing Controllers

Integration Testing

Testing Authentication Flow

Testing Router Integration

Testing Best Practices

Environment Isolation

Create a separate .env.testing file:

Mocking External Services

Database Testing

Running Tests

Basic Test Execution

PHPUnit Configuration

Create phpunit.xml:

Continuous Integration

GitHub Actions Example

Create .github/workflows/tests.yml:

Performance Testing

Benchmarking Routes

This testing guide provides comprehensive examples for testing Stilmark Base applications with proper isolation, mocking, and CI integration.

Last updated