PHPackages                             mottaviani-dev/laravel-reductor - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Testing &amp; Quality](/categories/testing)
4. /
5. mottaviani-dev/laravel-reductor

ActiveLibrary[Testing &amp; Quality](/categories/testing)

mottaviani-dev/laravel-reductor
===============================

ML-powered test suite optimization for Laravel - Reduce CI/CD time by identifying redundant tests

v1.0.0(9mo ago)210MITPythonPHP ^8.1|^8.2|^8.3

Since Jul 18Pushed 9mo ago1 watchersCompare

[ Source](https://github.com/mottaviani-dev/laravel-reductor)[ Packagist](https://packagist.org/packages/mottaviani-dev/laravel-reductor)[ Docs](https://github.com/mottaviani-dev/laravel-reductor)[ RSS](/packages/mottaviani-dev-laravel-reductor/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependencies (11)Versions (2)Used By (0)

Laravel Reductor
================

[](#laravel-reductor)

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.

Features
--------

[](#features)

- **ML-Powered Analysis**: Uses advanced clustering algorithms (DBSCAN, Hierarchical, K-means) to identify redundant tests
- **Coverage-Based Detection**: Analyzes code coverage patterns to find tests with similar execution paths
- **Semantic Understanding**: Combines coverage analysis with semantic similarity of test code
- **Safety Validation**: Prevents merging of semantically opposing tests (e.g., success vs failure tests)
- **Multiple Output Formats**: Markdown (default), JSON, YAML, and HTML reports
- **IDF-Weighted Coverage**: Uses Inverse Document Frequency to emphasize unique coverage patterns
- **Configurable Thresholds**: Adjust similarity thresholds to control reduction aggressiveness

Installation
------------

[](#installation)

1. Install the package via Composer:

```
composer require mottaviani-dev/laravel-reductor
```

2. Publish the configuration file:

```
php artisan vendor:publish --provider="Reductor\ReductorServiceProvider"
```

3. Run migrations to create the necessary database tables:

```
php artisan migrate
```

4. Ensure Python 3.8+ is installed with required packages (alpine based images):

```
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
```

Quick Start
-----------

[](#quick-start)

### 1. Generate Coverage Data

[](#1-generate-coverage-data)

First, generate PHPUnit coverage in text format:

```
XDEBUG_MODE=coverage ./vendor/bin/phpunit --coverage-php=storage/coverage.cov
```

### 2. Ingest Coverage Data

[](#2-ingest-coverage-data)

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.

### 3. Analyze for Redundancy

[](#3-analyze-for-redundancy)

Run the redundancy detection (K-Means algorithm and Markdown output are defaults):

```
php artisan tests:reduce
```

Usage Examples
--------------

[](#usage-examples)

### Basic Usage with Different Algorithms

[](#basic-usage-with-different-algorithms)

```
# 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
```

### Output Formats

[](#output-formats)

```
# 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
```

### Adjusting Similarity Thresholds

[](#adjusting-similarity-thresholds)

```
# 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
```

### Combined Options

[](#combined-options)

```
# Full example with all options
php artisan tests:reduce 46 \
  --algorithm dbscan \
  --threshold 0.85 \
  --format markdown \
  --output storage/reductor/analysis.md
```

Configuration
-------------

[](#configuration)

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'),
        ],
    ],
];
```

Understanding the Algorithms
----------------------------

[](#understanding-the-algorithms)

### K-means (Default)

[](#k-means-default)

- **Centroid-based clustering** that automatically finds optimal number of clusters
- **Most validated algorithm** in research literature (35% of studies)
- **Fast and deterministic** with consistent results across runs
- **Works well** when test clusters have similar sizes

### DBSCAN

[](#dbscan)

- **Density-based clustering** that can identify noise points and outliers
- **Good for varied density** when test clusters have very different sizes
- **Adaptive parameters** based on dataset characteristics

### Hierarchical Clustering

[](#hierarchical-clustering)

- **Structure-aware clustering** that builds a tree of clusters
- **Useful for** understanding hierarchical relationships between test groups
- **Good alternative** when you need dendrogram visualization

Interpreting Results
--------------------

[](#interpreting-results)

### Redundancy Scores

[](#redundancy-scores)

- **95-100%**: Nearly identical tests - safe to remove
- **85-95%**: Very similar tests - review recommended
- **70-85%**: Related tests - manual review required
- **Below 70%**: Different tests - keep both

### Priority Levels

[](#priority-levels)

- **High**: Tests with &gt;90% similarity in large clusters
- **Medium**: Tests with 70-90% similarity
- **Low**: Tests with &lt;70% similarity or small clusters

### Coverage Overlap

[](#coverage-overlap)

- Shows percentage of shared code coverage between tests
- 100% overlap doesn't always mean redundant (different assertions possible)
- Combined with semantic similarity for accurate detection

Advanced Features
-----------------

[](#advanced-features)

### Safety Validation

[](#safety-validation)

Reductor automatically prevents merging tests with opposing semantics:

- Success vs Failure tests
- Valid vs Invalid tests
- Create vs Delete operations
- Authorized vs Unauthorized tests

### IDF-Weighted Coverage

[](#idf-weighted-coverage)

Lines covered by many tests are weighted less than unique coverage patterns, improving discrimination between tests that share common initialization code.

### Dimensionality Reduction

[](#dimensionality-reduction)

Automatically reduces high-dimensional vectors (640D) to manageable size (128D) while preserving 95%+ variance for accurate clustering.

Troubleshooting
---------------

[](#troubleshooting)

### "Pipeline failed" Error

[](#pipeline-failed-error)

- Check Python is installed: `python3 --version`
- Verify ML dependencies: `pip list | grep -E "scikit-learn|numpy"`
- Check logs: `tail -50 storage/logs/laravel.log`

### Poor Clustering Results

[](#poor-clustering-results)

- Ensure coverage data is comprehensive
- Try different algorithms (DBSCAN or Hierarchical)
- Adjust threshold based on your needs
- Check for semantic vector issues (all zeros)

Example Output (Markdown)
-------------------------

[](#example-output-markdown)

```
# 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
```

Contributing
------------

[](#contributing)

Please see [CONTRIBUTING.md](CONTRIBUTING.md) for details.

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

32

—

LowBetter than 72% of packages

Maintenance56

Moderate activity, may be stable

Popularity8

Limited adoption so far

Community4

Small or concentrated contributor base

Maturity51

Maturing project, gaining track record

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

296d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/30998271726a46d5d6bf3ccf7afa3ee2e985cdbe05ccf4eda762b517c89440b5?d=identicon)[mottaviani-dev](/maintainers/mottaviani-dev)

---

Tags

testingphpunitpestlaravelcoverageTDDcontinuous integrationmachine learningci-cdtest-optimizationtest-reductionredundancy-detection

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StylePHP CS Fixer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/mottaviani-dev-laravel-reductor/health.svg)

```
[![Health](https://phpackages.com/badges/mottaviani-dev-laravel-reductor/health.svg)](https://phpackages.com/packages/mottaviani-dev-laravel-reductor)
```

###  Alternatives

[orchestra/testbench

Laravel Testing Helper for Packages Development

2.2k39.1M32.1k](/packages/orchestra-testbench)[larastan/larastan

Larastan - Discover bugs in your code without running it. A phpstan/phpstan extension for Laravel

6.4k43.5M5.2k](/packages/larastan-larastan)[brianium/paratest

Parallel testing for PHP

2.5k118.8M754](/packages/brianium-paratest)[orchestra/workbench

Workbench Companion for Laravel Packages Development

8017.0M43](/packages/orchestra-workbench)[code-distortion/adapt

A Laravel package that builds databases for your tests, improving their speed.

2835.5k](/packages/code-distortion-adapt)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
