PHPackages                             hidayetov/auto-testify - 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. hidayetov/auto-testify

ActiveLaravel-package[Testing &amp; Quality](/categories/testing)

hidayetov/auto-testify
======================

Automatic test generator for Laravel models

1.0.1(1y ago)04MITPHPPHP ^8.1

Since Mar 10Pushed 1y ago1 watchersCompare

[ Source](https://github.com/HidayetHidayetov/auto-testify)[ Packagist](https://packagist.org/packages/hidayetov/auto-testify)[ RSS](/packages/hidayetov-auto-testify/feed)WikiDiscussions master Synced 1mo ago

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

AutoTestify
===========

[](#autotestify)

**AutoTestify** is a powerful Laravel package designed to automatically generate comprehensive test files for your Eloquent models. It simplifies the testing process by creating CRUD (Create, Read, Update, Delete) and uniqueness tests, saving you time and ensuring your models are thoroughly tested.

---

Features
--------

[](#features)

- **Automatic CRUD Tests**: Generates tests for creating, retrieving, updating, and deleting model instances.
- **Uniqueness Testing**: Detects unique fields from the database schema or model configuration and generates corresponding tests.
- **Database Flexibility**: Works with or without a database connection:
    - If migrated and `doctrine/dbal` is installed, detects unique fields from the database.
    - Otherwise, uses the `$unique` property defined in your model.
- **Resilient Design**: Skips database-dependent tests gracefully if no connection is available.
- **Customizable**: Easily extendable for additional test cases or model-specific logic.

---

Requirements
------------

[](#requirements)

- **PHP**: 8.1 or higher
- **Laravel**: 11.0 or higher
- **Optional**: `doctrine/dbal` (for database schema detection)

---

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

[](#installation)

### Step 1: Install via Composer

[](#step-1-install-via-composer)

Add the package to your Laravel project:

```
composer require hidayetov/auto-testify
```

### Step 2: (Optional) Enable Database Schema Detection

[](#step-2-optional-enable-database-schema-detection)

If you want AutoTestify to detect unique fields from your database schema, install `doctrine/dbal`:

```
composer require doctrine/dbal
```

Without this, the package will rely on the `$unique` property in your models.

---

Usage
-----

[](#usage)

### Generating a Test File

[](#generating-a-test-file)

Run the following Artisan command to generate a test file for a specific model:

```
php artisan make:test-model ModelName
```

For example, to generate tests for a `User` model:

```
php artisan make:test-model User
```

This will create `tests/Feature/UserTest.php` with CRUD and uniqueness tests.

### Example Model Configuration

[](#example-model-configuration)

Define `$fillable` and (optionally) `$unique` properties in your model:

```
namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class User extends Model
{
    protected $fillable = ['name', 'email', 'password'];
    protected $unique = ['email']; // Optional if not using database detection
}
```

### Generated Tests

[](#generated-tests)

For the `User` model above, the generated `UserTest.php` might look like this:

```
namespace Tests\Feature;

use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\Hash;
use Tests\TestCase;

class UserTest extends TestCase
{
    use RefreshDatabase;

    public function test_user_can_be_created_with_fillable_fields()
    {
        $attributes = [
            'name' => 'Test Name',
            'email' => 'test@example.com',
            'password' => 'password',
        ];
        $user = \App\Models\User::create($attributes);
        $this->assertEquals($attributes['name'], $user->name);
        $this->assertEquals($attributes['email'], $user->email);
        $this->assertTrue(Hash::check('password', $user->password));
    }

    public function test_user_can_be_retrieved()
    {
        $attributes = [
            'name' => 'Test Name',
            'email' => 'test@example.com',
            'password' => 'password',
        ];
        $user = \App\Models\User::create($attributes);
        $retrieved = \App\Models\User::find($user->id);
        $this->assertNotNull($retrieved);
        $this->assertEquals($attributes['name'], $retrieved->name);
        $this->assertEquals($attributes['email'], $retrieved->email);
        $this->assertTrue(Hash::check('password', $retrieved->password));
    }

    public function test_user_can_be_updated()
    {
        $attributes = [
            'name' => 'Test Name',
            'email' => 'test@example.com',
            'password' => 'password',
        ];
        $user = \App\Models\User::create($attributes);
        $updatedAttributes = [
            'name' => 'Updated Test Name',
            'email' => 'test@example.com',
            'password' => 'newpassword',
        ];
        $user->update($updatedAttributes);
        $this->assertEquals($updatedAttributes['name'], $user->name);
        $this->assertEquals($updatedAttributes['email'], $user->email);
        $this->assertTrue(Hash::check('newpassword', $user->password));
    }

    public function test_user_can_be_deleted()
    {
        $attributes = [
            'name' => 'Test Name',
            'email' => 'test@example.com',
            'password' => 'password',
        ];
        $user = \App\Models\User::create($attributes);
        $user->delete();
        $this->assertDatabaseMissing('users', ['id' => $user->id]);
    }

    public function test_user_email_must_be_unique()
    {
        $attributes = [
            'name' => 'Test Name',
            'email' => 'test@example.com',
            'password' => 'password',
        ];
        \App\Models\User::create($attributes);
        $this->assertDatabaseCount('users', 1);
        $this->expectException(\Illuminate\Database\QueryException::class);
        \App\Models\User::create($attributes);
    }
}
```

---

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

[](#configuration)

### Model Setup

[](#model-setup)

- **`$fillable`**: Required to specify fields that can be mass-assigned.
- **`$unique`**: Optional; define unique fields if not relying on database schema detection.

### Database Detection

[](#database-detection)

Ensure your database is migrated (`php artisan migrate`) and `doctrine/dbal` is installed for automatic unique field detection.

---

Running Tests
-------------

[](#running-tests)

After generating the test files, run your tests with:

```
php artisan test
```

### Example Output

[](#example-output)

```
PASS  Tests\Feature\UserTest
✓ user can be created with fillable fields
✓ user can be retrieved
✓ user can be updated
✓ user can be deleted
✓ user email must be unique

```

---

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

[](#troubleshooting)

- **"No connection could be made" Error**: Ensure your `.env` file is configured correctly and your database server is running.
    - Example `.env` for MySQL: ```
        DB_CONNECTION=mysql
        DB_HOST=127.0.0.1
        DB_PORT=3306
        DB_DATABASE=your_database
        DB_USERNAME=root
        DB_PASSWORD=

        ```
    - Or use SQLite: ```
        DB_CONNECTION=sqlite
        DB_DATABASE=/path/to/database.sqlite

        ```
- **Unique Tests Not Generated**: Define `$unique` in your model or install `doctrine/dbal` and migrate your database.

---

License
-------

[](#license)

This package is open-sourced under the [MIT License](https://github.com/HidayetHidayetov/auto-testify/blob/master/LICENSE).

Author
------

[](#author)

- **Hidayet Hidayetov** - [GitHub](https://github.com/HidayetHidayetov)
- Special thanks to contributors and collaborators!

---

Happy testing with AutoTestify! 🚀

###  Health Score

27

—

LowBetter than 49% of packages

Maintenance45

Moderate activity, may be stable

Popularity3

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity47

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

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

Every ~0 days

Total

2

Last Release

433d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/b8b8321fc265e7c4720cafe92173642fecabd8c87fdf14f19cc2e7113193f3ea?d=identicon)[HidayetHidayetov](/maintainers/HidayetHidayetov)

---

Top Contributors

[![HidayetHidayetov](https://avatars.githubusercontent.com/u/16389174?v=4)](https://github.com/HidayetHidayetov "HidayetHidayetov (20 commits)")

### Embed Badge

![Health badge](/badges/hidayetov-auto-testify/health.svg)

```
[![Health](https://phpackages.com/badges/hidayetov-auto-testify/health.svg)](https://phpackages.com/packages/hidayetov-auto-testify)
```

###  Alternatives

[orchestra/testbench

Laravel Testing Helper for Packages Development

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

Testing helpers for your OpenAPI spec

3021.4M1](/packages/hotmeteor-spectator)[orchestra/workbench

Workbench Companion for Laravel Packages Development

8017.0M43](/packages/orchestra-workbench)[botble/git-commit-checker

Check coding standard &amp; code syntax with Git pre-commit hook.

47186.4k1](/packages/botble-git-commit-checker)[guanguans/laravel-soar

SQL optimizer and rewriter for laravel. - laravel 的 SQL 优化器和重写器。

2227.8k](/packages/guanguans-laravel-soar)[spurwork/spectator

Testing helpers for your OpenAPI spec

3021.5k](/packages/spurwork-spectator)

PHPackages © 2026

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