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

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

aunhurian/laravel-test-generator
================================

The package for generating tests for Laravel models, controllers, and requests.

1.0.2.0(2y ago)139MITPHPPHP ^8.2

Since Mar 23Pushed 2y ago1 watchersCompare

[ Source](https://github.com/AUnhurian/laravel-test-generator)[ Packagist](https://packagist.org/packages/aunhurian/laravel-test-generator)[ RSS](/packages/aunhurian-laravel-test-generator/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (1)Versions (5)Used By (0)

[![Latest Stable Version](https://camo.githubusercontent.com/5cd73189f2e96be3d3937d4a4a203d346ec499335f0e65b980ba62c16c53a865/687474703a2f2f706f7365722e707567782e6f72672f61756e68757269616e2f6c61726176656c2d746573742d67656e657261746f722f76)](https://packagist.org/packages/aunhurian/laravel-test-generator) [![Total Downloads](https://camo.githubusercontent.com/6b097d46558b2bb84373c24123f29fadab0b1dcbe9854bfd6bbe9ef4ef139782/687474703a2f2f706f7365722e707567782e6f72672f61756e68757269616e2f6c61726176656c2d746573742d67656e657261746f722f646f776e6c6f616473)](https://packagist.org/packages/aunhurian/laravel-test-generator) [![Latest Unstable Version](https://camo.githubusercontent.com/be5965c09d992a881b2bb66a6b90186d6c23b9caa6b585db2dc8beb409b2acbb/687474703a2f2f706f7365722e707567782e6f72672f61756e68757269616e2f6c61726176656c2d746573742d67656e657261746f722f762f756e737461626c65)](https://packagist.org/packages/aunhurian/laravel-test-generator) [![License](https://camo.githubusercontent.com/d1ab0a4e5712b723acba220eef70ff57ad9b8a8f472297e5269f1039d52908dd/687474703a2f2f706f7365722e707567782e6f72672f61756e68757269616e2f6c61726176656c2d746573742d67656e657261746f722f6c6963656e7365)](https://packagist.org/packages/aunhurian/laravel-test-generator) [![PHP Version Require](https://camo.githubusercontent.com/977b6861a21c3fadd2f4cc28096ad02389f37a4ca50175cb9964296c6b5cf8ae/687474703a2f2f706f7365722e707567782e6f72672f61756e68757269616e2f6c61726176656c2d746573742d67656e657261746f722f726571756972652f706870)](https://packagist.org/packages/aunhurian/laravel-test-generator)

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

[](#laravel-test-generator)

Use this package to generate test files for your Laravel application, and fix the tests later.

Pay Attention
-------------

[](#pay-attention)

This package is still in development and may not work as expected. Use it at your own risk.

The results of the generated tests are not full. You should fill in this test your logic.

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

[](#installation)

Install the package using composer.

```
composer require aunhurian/laravel-test-generator
```

Usage
-----

[](#usage)

```
php artisan test:generate "\App\Http\Controllers\IndexController" --feature --unit
```

You can use the `override` option to overwrite existing test files.

```
php artisan test:generate "\App\Http\Controllers\IndexController" --feature --unit --override
```

**You can also publish the configuration file using the following command:**

```
php artisan vendor:publish --tag=test-generator --force
```

Create the own formator for the test generator and set that class in config `test-generator`. You need to implement the `AUnhurian\LaravelTestGenerator\Contracts\FormatorInterface` interface.

Example
-------

[](#example)

You have a controller `IndexController` with the following methods:

```
class IndexController extends Controller
{
    public function __construct(private string $test = '')
    {
    }

    public function test(Request $request, int $id)
    {
        return view('welcome', [
            'data' => $request->all()
        ]);
    }

    public function show(): JsonResponse
    {
        return response()->json([
            'message' => 'success'
        ]);
    }
}
```

You can generate test files for the controller using the following command:

```
php artisan test:generate "\App\Http\Controllers\IndexController" --feature --unit
```

This will generate the following test files:

### Feature Test

[](#feature-test)

It will generate a feature test file for the controller.

```
