Overview
AnimeThemes Server uses Pest PHP as its testing framework, providing an expressive and elegant syntax for writing tests. The test suite includes both unit tests and feature tests to ensure code quality and reliability.Test Framework
The project uses:- Pest PHP 4.x: Modern PHP testing framework
- Pest Plugin Laravel: Laravel-specific testing utilities
- PHPUnit: Underlying test runner (via Pest)
- Mockery: Mocking library
Test Structure
Tests are organized into two main categories:Running Tests
Run All Tests
Run Specific Test Suites
Run Specific Test Files
Run Tests with Coverage
Filter Tests by Name
Writing Tests
Basic Test Structure
Pest uses a functional syntax for defining tests:Using Expectations
Pest provides an expressive expectation API:Feature Test Example
Testing API endpoints:Unit Test Example
Testing model behavior:Testing Relationships
Using Datasets
Pest supports data providers for testing multiple scenarios:Test Configuration
Pest Configuration
Thetests/Pest.php file configures global test settings:
- RefreshDatabase: Automatically migrates and refreshes database for each test
- TestCase: Extends base Laravel test case
- Traits: Additional testing traits can be added globally
PHPUnit Configuration
Test environment settings inphpunit.xml:
- In-memory SQLite: Fast database for testing
- Array drivers: For cache and session
- Sync queue: Execute jobs synchronously
- Disabled Scout: Search functionality turned off
Factory Usage
Creating Test Data
Laravel factories generate model instances for testing:Custom States
Testing Best Practices
1. Arrange-Act-Assert Pattern
2. Test One Thing
Each test should verify a single behavior:3. Use Descriptive Names
4. Clean Up Resources
When working with files or external resources:Continuous Integration
The project uses GitHub Actions for automated testing:Test Workflow
Tests run automatically on:- Pull requests
- Pushes to main branch
- Manual workflow dispatch
Static Analysis Workflow
Runs PHPStan for type checking: Static AnalysisCommon Testing Patterns
Testing API Filters
Testing Validation Rules
Testing Events and Listeners
Debugging Tests
Run Single Test
Stop on Failure
Verbose Output
Use dd() for Debugging
Additional Resources
- Pest Documentation: https://pestphp.com
- Laravel Testing: https://laravel.com/docs/testing
- Test Examples: Browse
tests/directory in the repository