PHPackages                             bberkaysari/laravel-test-generator - 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. bberkaysari/laravel-test-generator

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

bberkaysari/laravel-test-generator
==================================

Universal Laravel test generator without AI - Generate comprehensive tests automatically

v1.6.0(5mo ago)116MITPHPPHP ^8.2|^8.3|^8.4CI passing

Since Jan 17Pushed 5mo agoCompare

[ Source](https://github.com/bberkaysari/laravel-test-generator)[ Packagist](https://packagist.org/packages/bberkaysari/laravel-test-generator)[ RSS](/packages/bberkaysari-laravel-test-generator/feed)WikiDiscussions main Synced today

READMEChangelogDependencies (13)Versions (12)Used By (0)

🚀 Laravel Test Generator
========================

[](#-laravel-test-generator)

[![CI](https://github.com/bberkaysari/laravel-test-generator/workflows/CI/badge.svg)](https://github.com/bberkaysari/laravel-test-generator/actions)[![Tests](https://camo.githubusercontent.com/68a12ea564e35545d09442f7512bb6cca8d89f68f781c292b5734e36647a2dd2/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f74657374732d31343525323070617373696e672d627269676874677265656e)](https://github.com/bberkaysari/laravel-test-generator)[![PHPStan](https://camo.githubusercontent.com/044b0eef98bf13b08496180de49e5f42d80875f8fc8635654086ba2ac4149873/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5048505374616e2d6c6576656c253230352d626c7565)](https://phpstan.org)[![PHP Version](https://camo.githubusercontent.com/50b13d3d01778282febe11a92c7166976ae637e4ee8ffe64bce210549ed5e096/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5048502d382e32253230253743253230382e33253230253743253230382e342d626c7565)](https://www.php.net/)[![Laravel](https://camo.githubusercontent.com/add0a2daaf51dd84233459fc84033647bab96087f8cefa4e7b8e3a56e1f52451/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c61726176656c2d313025324225323025374325323031312532422d726564)](https://laravel.com)[![License](https://camo.githubusercontent.com/8bb50fd2278f18fc326bf71f6e88ca8f884f72f179d3e555e20ed30157190d0d/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d677265656e2e737667)](LICENSE)

**Production-ready Laravel test generator with 85-90% automation without AI**

Generate comprehensive PHPUnit tests for your Laravel application through **static code analysis** - no AI, no guessing, just reliable test generation from your actual code.

🆕 What's New in Latest Version
------------------------------

[](#-whats-new-in-latest-version)

### 🎯 Professional Test Quality (NEW!)

[](#-professional-test-quality-new)

- 🚀 **4-5 tests per method** (previously 1) - Happy path, edge cases, error handling
- 📋 **PHPUnit Annotations** - @test, @group (service, repository, edge-case, error-handling)
- 🎲 **Data Provider Support** - Multiple scenario testing with @dataProvider
- 💡 **Smart Assertion Guides** - Type-specific TODO comments with examples
- 🎭 **Mock Expectation Examples** - Repository, Service, API patterns

### 🔧 Enhanced Scanner Capabilities (NEW!)

[](#-enhanced-scanner-capabilities-new)

- 📁 **Laravel Modules Support** - Automatically scans /Modules directory
- 🛣️ **Custom Route Files** - Supports mock-api.php, admin-api.php, etc.
- 🎯 **Smart Method Detection** - Skips constructors and private methods
- 🔍 **Improved Import Management** - No more duplicate namespaces

✨ Features
----------

[](#-features)

### 🎯 Core Capabilities

[](#-core-capabilities)

- ✅ **Model Tests**: Fillable validation, casts, relationships, scopes
- ✅ **Controller Tests**: HTTP methods, validation rules, route parameters
- ✅ **Service/Repository Tests**: Mock setup, edge cases, error handling (NEW!)
- ✅ **Migration Tests**: Schema validation, indexes, foreign keys
- ✅ **85-90% Automation**: Comprehensive test coverage without manual work

### 🚀 Enterprise-Scale Support

[](#-enterprise-scale-support)

- ⚡ **Intelligent Caching**: 10-50x speedup on subsequent runs (27ms → 2ms)
- 📊 **Performance Monitoring**: Track analysis metrics for large projects
- 📈 **Progress Tracking**: Visual progress bars for bulk operations
- 🏢 **1000+ Models**: Designed for enterprise-scale Laravel applications
- 🔗 **Laravel Modules**: Full support for modular Laravel projects (NEW!)

### 🔍 Advanced Analysis

[](#-advanced-analysis)

- 🔬 **Static Code Analysis**: PHP-Parser based AST parsing
- 🎯 **Resource Detection**: Automatically identifies RESTful patterns
- ✔️ **Validation Detection**: Finds `$request->validate()` calls
- 🔗 **Relationship Mapping**: Detects all Eloquent relationships
- 📁 **Multi-Directory Scanning**: app/, src/, Modules/ (NEW!)

📦 Installation
--------------

[](#-installation)

```
composer require --dev bberkaysari/laravel-test-generator
```

🎮 Quick Start
-------------

[](#-quick-start)

### Command Line Interface

[](#command-line-interface)

**Generate all tests:**

```
php vendor/bin/generate-tests
```

**Generate only model tests:**

```
php vendor/bin/generate-tests --type=model
```

**Generate only controller tests:**

```
php vendor/bin/generate-tests --type=controller
```

**Generate service/repository tests:**

```
php vendor/bin/generate-tests --type=service
```

**Custom options:**

```
php vendor/bin/generate-tests \
  --path=/path/to/laravel \
  --output=tests \
  --force \
  --no-cache
```

### Running Generated Tests with Groups (NEW!)

[](#running-generated-tests-with-groups-new)

**Run all tests:**

```
vendor/bin/phpunit
```

**Run only service tests:**

```
vendor/bin/phpunit --group service
```

**Run only repository tests:**

```
vendor/bin/phpunit --group repository
```

**Run edge case tests:**

```
vendor/bin/phpunit --group edge-case
```

**Exclude incomplete tests:**

```
vendor/bin/phpunit --exclude-group error-handling
```

**Run parametrized tests:**

```
vendor/bin/phpunit --group parametrized
```

### Programmatic Usage

[](#programmatic-usage)

```
use Bberkaysari\LaravelTestGenerator\Core\ProjectAnalyzer;
use Bberkaysari\LaravelTestGenerator\Generator\Generators\ModelTestGenerator;
use Bberkaysari\LaravelTestGenerator\Generator\Generators\ControllerTestGenerator;

// Analyze entire project
$analyzer = new ProjectAnalyzer('/path/to/laravel');
$results = $analyzer->analyze();

// Results contain:
// - models: Array of analyzed models
// - controllers: Array of analyzed controllers
// - migrations: Array of parsed migrations
// - statistics: Test estimates and metrics
// - performance: Execution time and memory

// Generate model tests
$modelGenerator = new ModelTestGenerator();
foreach ($results['models'] as $model) {
    $testCode = $modelGenerator->generate($model);
    file_put_contents("tests/Unit/{$model['name']}Test.php", $testCode);
}

// Generate controller tests
$controllerGenerator = new ControllerTestGenerator();
foreach ($results['controllers'] as $controller) {
    $testCode = $controllerGenerator->generate($controller);
    file_put_contents("tests/Feature/{$controller['name']}Test.php", $testCode);
}
```

📊 What Gets Generated
---------------------

[](#-what-gets-generated)

### Model Tests (8+ tests per model)

[](#model-tests-8-tests-per-model)

```
✓ test_model_can_be_instantiated
✓ test_fillable_attributes_work_correctly
✓ test_casts_are_applied_correctly
✓ test_belongs_to_relationships_work
✓ test_has_many_relationships_work
✓ test_belongs_to_many_relationships_work
✓ test_query_scopes_work_correctly
✓ test_database_schema_matches_expectations
```

### Controller Tests (3+ tests per method)

[](#controller-tests-3-tests-per-method)

```
✓ test_index              // GET /users returns 200
✓ test_store              // POST /users creates user
✓ test_store_validation   // POST /users validation fails
✓ test_show               // GET /users/{id} returns user
✓ test_update             // PUT /users/{id} updates user
✓ test_update_validation  // PUT /users/{id} validation fails
✓ test_destroy            // DELETE /users/{id} removes user
```

### Example Generated Test

[](#example-generated-test)

```
