PHPackages                             thomasdominic/eloquent-model-testor - 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. [Database &amp; ORM](/categories/database)
4. /
5. thomasdominic/eloquent-model-testor

AbandonedArchivedLibrary[Database &amp; ORM](/categories/database)

thomasdominic/eloquent-model-testor
===================================

Test easier your Eloquent Models in your Laravel Project

v0.9.2(6y ago)0211[1 issues](https://github.com/domthomas-dev/eloquent-model-testor/issues)MITPHPPHP ^7.4

Since Mar 6Pushed 5y ago1 watchersCompare

[ Source](https://github.com/domthomas-dev/eloquent-model-testor)[ Packagist](https://packagist.org/packages/thomasdominic/eloquent-model-testor)[ Docs](https://github.com/thomasdominic/eloquent-model-testor)[ RSS](/packages/thomasdominic-eloquent-model-testor/feed)WikiDiscussions master Synced 2d ago

READMEChangelog (3)Dependencies (3)Versions (4)Used By (0)

Helper for Testing structures, relations of your models in Laravel
==================================================================

[](#helper-for-testing-structures-relations-of-your-models-in-laravel)

[![Latest Version on Packagist](https://camo.githubusercontent.com/3d23889f4c19d6562fd432281421fdfc3a79301032b4211a3e030d42647888e2/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f74686f6d6173646f6d696e69632f656c6f7175656e742d6d6f64656c2d746573746f722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/thomasdominic/eloquent-model-testor)[![StyleCI](https://camo.githubusercontent.com/ed99f7f980a902f4cbb431b56c4c7b603d5c2f7f68795812a20b84b4a06a3f13/68747470733a2f2f6769746875622e7374796c6563692e696f2f7265706f732f3234353436373737312f736869656c643f6272616e63683d6d6173746572)](https://github.styleci.io/repos/245467771)[![Build Status](https://camo.githubusercontent.com/24443aca8092da5251748ba949ef92e3aa30d273a6ea9bd131ed533b44023097/68747470733a2f2f7472617669732d63692e636f6d2f74686f6d6173646f6d696e69632f656c6f7175656e742d6d6f64656c2d746573746f722e7376673f6272616e63683d6d6173746572)](https://travis-ci.com/thomasdominic/eloquent-model-testor)[![Quality Score](https://camo.githubusercontent.com/87b640ec654a789f5c6c139f11d574554568150905448cb2608d7db89f15c1a5/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f74686f6d6173646f6d696e69632f656c6f7175656e742d6d6f64656c2d746573746f722f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/thomasdominic/eloquent-model-testor)[![Total Downloads](https://camo.githubusercontent.com/5537de82443b4102f48b9015ebbe95f3e722d0a0eb3f18c9c2b7a9f96a02d0bc/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f74686f6d6173646f6d696e69632f656c6f7175656e742d6d6f64656c2d746573746f722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/thomasdominic/models-testor)

This package allows you to test your models about table structures, relations and more

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

[](#installation)

You can install the package via composer:

```
composer require thomasdominic/eloquent-model-testor --dev
```

Usage
-----

[](#usage)

To use this package, you have to generate factories for your models. (See [Factories Documentation](https://laravel.com/docs/6.x/database-testing#writing-factories)) You can generate one test file by model or for several. For your model `MyModel` you can use this command for example:

```
php artisan make:model MyModel -mf
php artisan make:test Models/MyModelTest
```

### Test of structure and of fillable

[](#test-of-structure-and-of-fillable)

With this structure

```
users
    id - integer
    name - string
    other_field - string

```

you can test if you have all the fields you need and if they are fillable.

```
class UserTest extends TestCase
{
    use HasModelTestor;

    public function test_have_user_model()
    {
        $this->modelTestable(User::class)
            ->assertHasColumns(['id','name','other_field'])
            ->assertCanFillables(['name','other_field']);
    }

}
```

### HasMany et BelongsTo

[](#hasmany-et-belongsto)

You can test relations of your models. For example, with this structure

```
categories
    id - integer
    name - string

customers
    id - integer
    name - string
    category_id - integer
    type_id - integer

```

you can use `assertHasHasManyRelations` and `assertHasBelongsToRelations` methods like this

```
class CategoryTest extends TestCase
{

    use HasModelTestor;

    public function test_have_category_model()
    {
        $this->modelTestable(Category::class)
            ->assertHasHasManyRelation(Customer::class);
    }

}

class CustomerTest extends TestCase
{
    use HasModelTestor;

    public function test_have_customer_model()
    {
        $this->modelTestable(Customer::class)
            ->assertHasBelongsToRelation(Category::class);
    }
}
```

If you don't use Laravel naming convention, you may also override the relation and local keys (for belongsTo relation) by passing additional arguments to the `assertHasHasManyRelations` and `assertHasBelongsToRelations` methods

```
    $this->modelTestable(Customer::class)
            ->assertHasBelongsToRelation(Category::class,'category','category_id');

    $this->modelTestable(Category::class)
            ->assertHasHasManyRelation(Customer::class,'customers');
```

If you have several relations, you can chain methods like this:

```
    $this->modelTestable(Customer::class)
            ->assertHasBelongsToRelation(Category::class)
            ->assertHasBelongsToRelation(OtherModel::class);

```

### Many to Many relations

[](#many-to-many-relations)

You can test your ManyToMany relations with the `ManyToManyRelationsTestable` trait.

```
users
    id - integer
    name - string

roles
    id - integer
    name - string

role_user
    user_id - integer
    role_id - integer

```

```
class UserTest extends TestCase
{
     use HasModelTestor;

    public function test_have_user_model()
    {
        $this->modelTestable(User::class)
            ->assertHasManyToManyRelation(Role::class);
    }

}

class RoleTest extends TestCase
{
    use HasModelTestor;

    public function test_have_role_model()
    {
        $this->modelTestable(User::class)
            ->assertHasManyToManyRelation(User::class);
    }

}
```

You can override the relation argument too :

```
    $this->modelTestable(User::class)
            ->assertHasManyToManyRelation(User::class,'users');
```

### Morph Relations

[](#morph-relations)

If you have a Morph Relation,

```
posts
    id - integer
    title - string
    body - text

videos
    id - integer
    title - string
    url - string

comments
    id - integer
    body - text
    commentable_id - integer
    commentable_type - string

```

you can use `assertHasBelongsToMorphRelations` and `assertHasHasManyMorphRelations` methods like this

```
class PostTest extends TestCase
{

    use HasModelTestor;

    public function test_have_post_model()
        {
            $this->modelTestable(Post::class)
                ->assertHasHasManyMorphRelation(Comment::class,'comments');
        }
}

class VideoTest extends TestCase
{
    use HasModelTestor;

    public function test_have_video_model()
        {
            $this->modelTestable(Video::class)
                ->assertHasHasManyMorphRelation(Comment::class,'comments');
        }
}

class CommentTest extends TestCase
{

    use HasModelTestor;

    public function test_have_morph_model_model()
    {
        $this->modelTestable(Comment::class)
           ->assertHasBelongsToMorphRelation(Post::class,'commentable')
           ->assertHasBelongsToMorphRelation(Video::class,'commentable');
    }
}
```

### Pivot and table without Model

[](#pivot-and-table-without-model)

You can test if a table contains columns with the `tableTestable` method

```
class MyPivotTest extends TestCase
{
    public function test_have_table_without_model()
    {
        $this->tableTestable('pivot_table')
            ->assertHasColumns(['first_model_id','second_model_id','other_property']);
    }
}
```

### Testing

[](#testing)

```
composer test
```

### Changelog

[](#changelog)

Please see [CHANGELOG](CHANGELOG.md) for more information about what has changed recently.

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

[](#contributing)

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

### Security

[](#security)

If you discover any security related issues, please email  instead of using the issue tracker.

Credits
-------

[](#credits)

- [Dominic THOMAS](https://github.com/thomasdominic)
- [All Contributors](../../contributors)

License
-------

[](#license)

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

Laravel Package Boilerplate
---------------------------

[](#laravel-package-boilerplate)

This package was generated using the [Laravel Package Boilerplate](https://laravelpackageboilerplate.com).

###  Health Score

23

—

LowBetter than 27% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity7

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity48

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

3

Last Release

2258d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/19ce7305c373d4ab9f6633a2d2ddb3693ae27a1fdd2897244a6e3e4c9760d581?d=identicon)[DomThomas-Dev](/maintainers/DomThomas-Dev)

---

Top Contributors

[![domthomas-dev](https://avatars.githubusercontent.com/u/17202290?v=4)](https://github.com/domthomas-dev "domthomas-dev (44 commits)")

---

Tags

laraveleloquentrelationthomasdominiceloquent-model-testor

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/thomasdominic-eloquent-model-testor/health.svg)

```
[![Health](https://phpackages.com/badges/thomasdominic-eloquent-model-testor/health.svg)](https://phpackages.com/packages/thomasdominic-eloquent-model-testor)
```

###  Alternatives

[tucker-eric/eloquentfilter

An Eloquent way to filter Eloquent Models

1.8k4.8M26](/packages/tucker-eric-eloquentfilter)[watson/validating

Eloquent model validating trait.

9723.3M47](/packages/watson-validating)[reedware/laravel-relation-joins

Adds the ability to join on a relationship by name.

2121.2M13](/packages/reedware-laravel-relation-joins)[cybercog/laravel-love

Make Laravel Eloquent models reactable with any type of emotions in a minutes!

1.2k302.7k1](/packages/cybercog-laravel-love)[cviebrock/eloquent-taggable

Easy ability to tag your Eloquent models in Laravel.

567694.8k3](/packages/cviebrock-eloquent-taggable)[highsolutions/eloquent-sequence

A Laravel package for easy creation and management sequence support for Eloquent models with elastic configuration.

121130.3k](/packages/highsolutions-eloquent-sequence)

PHPackages © 2026

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