autoapi / laravel-tester
Automatically test all your Laravel API endpoints without writing tests
Requires
- php: ^8.4
- illuminate/console: ^10.0|^11.0
- illuminate/support: ^10.0|^11.0
- laravel/framework: ^10.0|^11.0
Requires (Dev)
- orchestra/testbench: ^8.0
- phpunit/phpunit: ^10.0
This package is not auto-updated.
Last update: 2025-06-04 15:56:01 UTC
README
🚀 Automatically test all your Laravel API endpoints without writing a single test file!
This package discovers all your API routes and tests them automatically with intelligent dummy data generation, comprehensive response analysis, and detailed reporting.
Features
- 🔍 Auto-discovery: Automatically finds all your API routes
- 🎯 Smart Testing: Tests GET, POST, PUT, PATCH, DELETE requests with appropriate dummy data
- 🔐 Authentication Support: Test authenticated endpoints with real users
- 📊 Detailed Reports: Comprehensive analysis of responses, performance, and issues
- ⚡ Performance Insights: Response time analysis and slow endpoint detection
- 🛡️ Safety First: Configurable to avoid destructive operations
- 📤 Export Results: Save test results as JSON for CI/CD integration
Installation
Install via Composer:
composer require --dev autoapi/laravel-tester
Publish the config file (optional):
php artisan vendor:publish --tag=api-tester-config
Usage
Basic Usage
Test all API endpoints:
php artisan api:test
Advanced Usage
Test with authentication:
php artisan api:test --user=1
Test only specific HTTP methods:
php artisan api:test --method=GET php artisan api:test --method=POST
Test routes matching a pattern:
php artisan api:test --route=users php artisan api:test --route=posts
Detailed output with response analysis:
php artisan api:test --detailed
Export results to JSON:
php artisan api:test --export
Combine options:
php artisan api:test --user=1 --detailed --export --method=POST
Configuration
The package works out of the box, but you can customize behavior by publishing and editing the config file:
// config/api-tester.php return [ // Which route prefixes to test 'route_prefixes' => ['api'], // HTTP methods to test 'test_methods' => ['GET', 'POST', 'PUT', 'PATCH', 'DELETE'], // Skip routes that match these patterns 'skip_routes' => [ 'api/login', 'api/register', 'api/password/*', 'sanctum/*', ], // Authentication settings 'authentication' => [ 'enabled' => true, 'guard' => 'api', 'user_factory' => \App\Models\User::class, ], // Customize dummy data generation 'dummy_data' => [ 'string_fields' => [ 'name' => 'Test Name', 'title' => 'Test Title', // Add your custom fields... ], // More field types... ], // Response validation 'validation' => [ 'check_json_structure' => true, 'max_response_time' => 5000, // milliseconds ], ];
What Gets Tested
Automatic Route Discovery
- Scans all routes with configured prefixes (default:
api
) - Tests each HTTP method (GET, POST, PUT, PATCH, DELETE)
- Skips authentication routes and other configured patterns
Smart Data Generation
- GET requests: Tests with route parameters filled with realistic values
- POST/PUT/PATCH: Generates appropriate dummy data based on:
- Route names (users, posts, products, etc.)
- Common field patterns (email, name, title, etc.)
- Your custom configuration
Response Analysis
- ✅ Status codes: 2xx, 3xx, 4xx, 5xx analysis
- 📊 JSON structure: Validates and describes response format
- ⏱️ Performance: Response time tracking and slow endpoint detection
- 🔍 Headers: Validates expected headers like Content-Type
- ⚠️ Issues: Detects common problems (empty responses, server errors, etc.)
Sample Output
🚀 Laravel API Auto-Tester ============================ 🔍 Discovering API routes... Found 12 routes to test ✅ GET /api/users - 200 (45ms) ✅ POST /api/users - 201 (120ms) ⚠️ GET /api/users/1 - 200 (350ms) ⚠️ Slow response: 350ms (max: 300ms) ✅ PUT /api/users/1 - 200 (89ms) ❌ DELETE /api/users/1 - 500 (1200ms) ❌ Server error detected 📊 Test Summary ================ Total endpoints tested: 12 ✅ Successful: 9 ⚠️ With warnings: 2 ❌ Errors: 1 ⏱️ Average response time: 156ms 🕐 Total test time: 1,872ms 🚨 Routes with errors: - DELETE /api/users/1 ⚡ Performance Insights ======================== Fastest response: 23ms Slowest response: 1200ms Median response time: 89ms 95th percentile: 350ms
Safety Features
- Non-destructive by default: Carefully designed to avoid data corruption
- Configurable skips: Exclude sensitive routes like authentication endpoints
- Smart dummy data: Uses realistic but safe test data
- Real ID detection: Tries to use existing record IDs when possible
- Separate test environment: Runs in your test environment context
CI/CD Integration
Export results for automated testing:
php artisan api:test --export
Results are saved to storage/app/api-test-results.json
with comprehensive data:
{ "generated_at": "2024-01-01T00:00:00Z", "total_tests": 12, "summary": { "successful": 9, "warnings": 2, "errors": 1, "avg_response_time": 156 }, "results": [...] }
Requirements
- PHP ^8.1
- Laravel ^10.0 or ^11.0
- Your existing Laravel test setup (PHPUnit, etc.)
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
License
MIT License. See LICENSE file for details.
Support
If you find this package helpful, please ⭐ star it on GitHub!
For issues or questions, please use the GitHub issue tracker.