imanghafoori/eloquent-mockery
| Install | |
|---|---|
composer require imanghafoori/eloquent-mockery |
|
| Latest Version: | v1.0.40 |
| PHP: | ^7.2|^8.0 |
| Laravel: | 5 – 9 |
| Older releases: | 10 · 11 · 12 |
| License: | MIT |
| Last Updated: | Oct 2, 2026 |
| Links: | GitHub · Packagist |
Eloquent Mockery
Mock your eloquent queries without the repository pattern.
Why this package was invented?
- It solves the problem of "slow tests" by removing the interactions with a real database.
- It simplifies the process of writing and running tests since your tests will be "DB Independent".
Installation
You can install the package via Composer:
composer require imanghafoori/eloquent-mockery --dev dev-main
Usage:
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');
}
Mocking a 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();
}
- For more examples take a look at the
testsdirectory.
License
The MIT License (MIT). Please see License File for more information.
:raising_hand: Contributing
If you find an issue or have a better way to do something, feel free to open an issue, or a pull request.
:exclamation: Security
If you discover any security-related issues, please email imanghafoori1@gmail.com instead of using the issue tracker.
Related Packages
Adds modern Laravel Factories to older versions of Laravel
The goal of this package is to enable the rapid creation of objects for the purp...
Provides backwards compatibility for BrowserKit testing in the latest Laravel re...
Version History
| Version | Released | PHP | Laravel | License |
|---|---|---|---|---|
| v1.0.40 | ^7.2| | 5.*| | MIT | |
| v0.2.48 | ^7.2| | 11.*| | MIT | |
| v0.1.48 | ^7.2| | 5.*| | MIT | |
| v0.1.47 | ^7.2| | 5.*| | MIT | |
| v0.1.46 | ^7.2| | 5.*| | MIT | |
| v0.1.45 | ^7.2| | 5.*| | MIT | |
| v0.1.44 | ^7.2| | 5.*| | MIT | |
| v0.1.43 | ^7.2| | 5.*| | MIT | |
| v0.1.42 | ^7.2| | 5.*| | MIT | |
| v0.1.41 | ^7.2| | 5.*| | MIT | |
| v0.1.40 | ^7.2| | 5.*| | MIT | |
| v0.1.39 | ^7.2| | 5.*| | MIT | |
| v0.1.38 | ^7.2| | 5.*| | MIT | |
| v0.1.37 | ^7.2| | 5.*| | MIT | |
| v0.1.36 | ^7.2| | 5.*| | MIT | |
| v0.1.35 | ^7.2| | 5.*| | MIT | |
| v0.1.34 | ^7.2| | 5.*| | MIT | |
| v0.1.33 | ^7.2| | 5.*| | MIT | |
| v0.1.32 | ^7.2| | 5.*| | MIT | |
| v0.1.31 | ^7.2| | 5.*| | MIT | |
| v0.1.30 | ^7.2| | 5.*| | MIT | |
| v0.1.29 | ^7.2| | 5.*| | MIT | |
| v0.1.28 | ^7.2| | 5.*| | MIT | |
| v0.1.27 | ^7.2| | 5.*| | MIT | |
| v0.1.26 | ^7.2| | 5.*| | MIT | |
| v0.1.25 | ^7.2| | 5.*| | MIT | |
| v0.1.24 | ^7.2| | 5.*| | MIT | |
| v0.1.23 | ^7.2| | 5.*| | MIT | |
| v0.1.22 | ^7.2| | 5.*| | MIT | |
| v0.1.21 | ^7.2| | 5.*| | MIT |
Showing the latest 30 of 50. See every release on Packagist