| Install | |
|---|---|
composer require mottaviani-dev/laravel-reductor |
|
| Latest Version: | v1.0.0 |
| PHP: | ^8.1|^8.2|^8.3 |
A powerful Laravel package for detecting and reducing test redundancy using machine learning clustering algorithms. Reductor analyzes your test suite to identify similar tests that provide overlapping coverage, helping you maintain a leaner, more efficient test suite.
composer require mottaviani-dev/laravel-reductor
php artisan vendor:publish --provider="Reductor\ReductorServiceProvider"
php artisan migrate
apk add --no-cache build-base python3-dev py3-pip py3-wheel py3-setuptools py3-numpy cmake
pip install -r vendor/mottaviani-dev/laravel-reductor/requirements.txt
First, generate PHPUnit coverage in text format:
XDEBUG_MODE=coverage ./vendor/bin/phpunit --coverage-php=storage/coverage.cov
Import the coverage data into Reductor:
php artisan reductor:ingest-coverage storage/coverage.cov
This will output a test run ID that you'll use for analysis.
Run the redundancy detection (K-Means algorithm and Markdown output are defaults):
php artisan tests:reduce <test-run-id>
# Using K-means (default)
php artisan tests:reduce 46 --algorithm kmeans
# Using DBSCAN (good for varied density data)
php artisan tests:reduce 46 --algorithm dbscan
# Using Hierarchical clustering
php artisan tests:reduce 46 --algorithm hierarchical
# Markdown report (default, human-readable)
php artisan tests:reduce 46
# JSON format (for programmatic use)
php artisan tests:reduce 46 --format json
# HTML report
php artisan tests:reduce 46 --format html --output report.html
# YAML format
php artisan tests:reduce 46 --format yaml
# Conservative (95% similarity required)
php artisan tests:reduce 46 --threshold 0.95
# Balanced (85% default)
php artisan tests:reduce 46
# Aggressive (70% similarity)
php artisan tests:reduce 46 --threshold 0.7
# Full example with all options
php artisan tests:reduce 46 \
--algorithm dbscan \
--threshold 0.85 \
--format markdown \
--output storage/reductor/analysis.md
Edit config/reductor.php to customize default settings:
return [
'analysis' => [
// Default clustering algorithm
'algorithm' => env('REDUCTOR_ALGORITHM', 'kmeans'),
// Similarity thresholds
'similarity_thresholds' => [
'conservative' => 0.95, // High confidence
'balanced' => 0.85, // Default
'aggressive' => 0.75, // More reduction
],
// DBSCAN parameters
'dbscan' => [
'eps' => null, // Auto-detect
'min_samples' => 3,
'metric' => 'euclidean',
],
],
'coverage' => [
// Coverage file search paths
'auto_detect_paths' => [
storage_path('coverage.txt'),
storage_path('coverage.cov'),
base_path('coverage/coverage.txt'),
],
],
];
Reductor automatically prevents merging tests with opposing semantics:
Lines covered by many tests are weighted less than unique coverage patterns, improving discrimination between tests that share common initialization code.
Automatically reduces high-dimensional vectors (640D) to manageable size (128D) while preserving 95%+ variance for accurate clustering.
python3 --versionpip list | grep -E "scikit-learn|numpy"tail -50 storage/logs/laravel.log# Test Redundancy Analysis Report
## Summary
- Total Redundant Tests: 23
- High Priority: 1 findings
- Medium Priority: 2 findings
- Low Priority: 4 findings
## High Priority Findings
### Cluster 1
**Redundancy Score**: 96%
**Representative Test**: UserLoginTest::test_successful_login
**Redundant Tests** (3):
- UserAuthTest::test_user_can_login
- LoginControllerTest::test_login_success
- AuthenticationTest::test_valid_credentials
Please see CONTRIBUTING.md for details.
The MIT License (MIT). Please see License File for more information.