| Package Data | |
|---|---|
| Maintainer Username: | imanghafoori1 | 
| Maintainer Contact: | imanghafoori1@gmail.com (Iman) | 
| Package Create Date: | 2022-06-21 | 
| Package Last Update: | 2025-02-23 | 
| Language: | PHP | 
| License: | MIT | 
| Last Refreshed: | 2025-10-29 03:00:14 | 
| Package Statistics | |
|---|---|
| Total Downloads: | 561,686 | 
| Monthly Downloads: | 13,085 | 
| Daily Downloads: | 813 | 
| Total Stars: | 129 | 
| Total Watchers: | 2 | 
| Total Forks: | 18 | 
| Total Open Issues: | 5 | 
Mock your eloquent queries without the repository pattern.
You can install the package via Composer:
composer require imanghafoori/eloquent-mockery --dev dev-main
First, you have to define a new connection in your config/database.php and set the driver to 'arrayDB'.
<?php
return [
  
   ...
  
  'connections' => [
     'my_test_connection' => [
         'driver' => 'arrayDB',
         'database' => '',
     ],
     
     ...
  ],
  ...
]
Then you can:
public function test_basic()
{
    config()->set('database.default', 'my_test_connection');
    # ::Arrange:: (Setup Sample Data)
    FakeDB::addRow('users', ['id' => 1, 'username' => 'faky', 'password' => '...']);
    FakeDB::addRow('users', ['id' => 1, 'username' => 'maky', 'password' => '...']);
    # ::Act:: (This query resides in your controller)
    $user = User::where('username', 'faky')->first();   # <=== This does NOT connect to a real DB.
    # ::Assert::
    $this->assert($user->id === 1);
    $this->assert($user->username === 'faky');
}
create query:public function test_basic()
{
    # In setUp:
    FakeDB::mockEloquentBuilder();
    # ::Act::
    $this->post('/create-url', ['some' => 'data' ])
    # ::Assert::
    $user = User::first();
    $this->assertEquals('iman', $user->username);
    # In tearDown
    FakeDB::dontMockEloquentBuilder();
}
tests directory.The MIT License (MIT). Please see License File for more information.
If you find an issue or have a better way to do something, feel free to open an issue, or a pull request.
If you discover any security-related issues, please email imanghafoori1@gmail.com instead of using the issue tracker.