PHPackages                             mpyw/laravel-database-mock - 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. mpyw/laravel-database-mock

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

mpyw/laravel-database-mock
==========================

Database Mocking Library which mocks PDO underlying Laravel Connection classes

v0.0.1-alpha7(2mo ago)618.9k↑165.3%2MITPHPPHP ^8.2CI passing

Since Aug 27Pushed 1mo ago2 watchersCompare

[ Source](https://github.com/mpyw/laravel-database-mock)[ Packagist](https://packagist.org/packages/mpyw/laravel-database-mock)[ RSS](/packages/mpyw-laravel-database-mock/feed)WikiDiscussions master Synced 2w ago

READMEChangelog (4)Dependencies (14)Versions (8)Used By (2)

Laravel Database Mock [![Build Status](https://github.com/mpyw/laravel-database-mock/actions/workflows/ci.yml/badge.svg?branch=master)](https://github.com/mpyw/laravel-database-mock/actions) [![Coverage Status](https://camo.githubusercontent.com/3f5895c79e142a9b3cca40a0e510c1fe84171153c4d68ce8d32cb2f8b0d53c6e/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f6769746875622f6d7079772f6c61726176656c2d64617461626173652d6d6f636b2f62616467652e7376673f6272616e63683d6d6173746572)](https://coveralls.io/github/mpyw/laravel-database-mock?branch=master)
=======================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================

[](#laravel-database-mock--)

Warning

**Experimental**

Database Mocking Library which mocks `PDO` underlying Laravel Connection classes.

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

[](#requirements)

- PHP: `^8.2`
- Laravel: `^11.0 || ^12.0 || ^13.0 || ^14.0`
- Mockery: `^1.6.12`
- [mpyw/mockery-pdo](https://github.com/mpyw/mockery-pdo): `alpha`

Installing
----------

[](#installing)

```
composer require mpyw/laravel-database-mock:VERSION@alpha
```

Example
-------

[](#example)

### SELECT

[](#select)

```
$pdo = DBMock::mockPdo();
$pdo->shouldSelect('select * from `users`')
    ->shouldFetchAllReturns([[
        'id' => 1,
        'name' => 'John',
        'email' => 'john@example.com',
        'created_at' => '2020-01-01 00:00:00',
        'updated_at' => '2020-01-01 00:00:00',
    ]]);

$this->assertEquals([[
    'id' => 1,
    'name' => 'John',
    'email' => 'john@example.com',
    'created_at' => '2020-01-01T00:00:00.000000Z',
    'updated_at' => '2020-01-01T00:00:00.000000Z',
]], User::all()->toArray());
```

### INSERT

[](#insert)

```
Carbon::setTestNow('2020-01-01 00:00:00');

$pdo = DBMock::mockPdo();
$pdo->shouldInsert(
    'insert into `users` (`name`, `email`, `updated_at`, `created_at`) values (?, ?, ?, ?)',
    ['John', 'john@example.com', '2020-01-01 00:00:00', '2020-01-01 00:00:00']
);
$pdo->expects('lastInsertId')->andReturn(2);

$user = new User();
$user->forceFill(['name' => 'John', 'email' => 'john@example.com'])->save();
$this->assertEquals([
    'id' => 2,
    'name' => 'John',
    'email' => 'john@example.com',
    'created_at' => '2020-01-01T00:00:00.000000Z',
    'updated_at' => '2020-01-01T00:00:00.000000Z',
], $user->toArray());
```

### UPDATE

[](#update)

#### Basic

[](#basic)

```
Carbon::setTestNow('2020-01-02 00:00:00');

$pdo = DBMock::mockPdo();
$pdo->shouldSelect('select * from `users` where `email` = ? limit 1', ['john@example.com'])
    ->shouldFetchAllReturns([[
        'id' => 2,
        'name' => 'John',
        'email' => 'john@example.com',
        'created_at' => '2020-01-01 00:00:00',
        'updated_at' => '2020-01-01 00:00:00',
    ]]);
$pdo->shouldUpdateOne(
    'update `users` set `email` = ?, `users`.`updated_at` = ? where `id` = ?',
    ['john-01@example.com', '2020-01-02 00:00:00', 2]
);

$user = User::query()->where('email', 'john@example.com')->first();
$user->forceFill(['email' => 'john-01@example.com'])->save();
$this->assertEquals([
    'id' => 2,
    'name' => 'John',
    'email' => 'john-01@example.com',
    'created_at' => '2020-01-01T00:00:00.000000Z',
    'updated_at' => '2020-01-02T00:00:00.000000Z',
], $user->toArray());
```

#### Using Read Replica

[](#using-read-replica)

```
Carbon::setTestNow('2020-01-02 00:00:00');

$pdos = DBMock::mockEachPdo();
$pdos->reader()
    ->shouldSelect('select * from `users` where `email` = ? limit 1', ['john@example.com'])
    ->shouldFetchAllReturns([[
        'id' => 2,
        'name' => 'John',
        'email' => 'john@example.com',
        'created_at' => '2020-01-01 00:00:00',
        'updated_at' => '2020-01-01 00:00:00',
    ]]);
$pdos->writer()
    ->shouldUpdateOne(
        'update `users` set `email` = ?, `users`.`updated_at` = ? where `id` = ?',
        ['john-01@example.com', '2020-01-02 00:00:00', 2]
    );

$user = User::query()->where('email', 'john@example.com')->first();
$user->forceFill(['email' => 'john-01@example.com'])->save();
$this->assertEquals([
    'id' => 2,
    'name' => 'John',
    'email' => 'john-01@example.com',
    'created_at' => '2020-01-01T00:00:00.000000Z',
    'updated_at' => '2020-01-02T00:00:00.000000Z',
], $user->toArray());
```

###  Health Score

52

—

FairBetter than 96% of packages

Maintenance90

Actively maintained with recent releases

Popularity31

Limited adoption so far

Community18

Small or concentrated contributor base

Maturity59

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 81.8% 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 ~352 days

Recently: every ~453 days

Total

7

Last Release

67d ago

PHP version history (4 changes)v0.0.1-alpha1PHP ^7.1

v0.0.1-alpha2PHP ^7.1 || ^8.0

v0.0.1-alpha4PHP ^7.3 || ^8.0

v0.0.1-alpha6PHP ^8.2

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/1351893?v=4)[mpyw](/maintainers/mpyw)[@mpyw](https://github.com/mpyw)

---

Top Contributors

[![mpyw](https://avatars.githubusercontent.com/u/1351893?v=4)](https://github.com/mpyw "mpyw (18 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (3 commits)")[![hexium310](https://avatars.githubusercontent.com/u/10758173?v=4)](https://github.com/hexium310 "hexium310 (1 commits)")

---

Tags

databaseeloquentlaravelmockmockeryphpunitmockingtestlaraveldatabasemockeloquentqueryilluminate

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/mpyw-laravel-database-mock/health.svg)

```
[![Health](https://phpackages.com/badges/mpyw-laravel-database-mock/health.svg)](https://phpackages.com/packages/mpyw-laravel-database-mock)
```

###  Alternatives

[mongodb/laravel-mongodb

A MongoDB based Eloquent model and Query builder for Laravel

7.1k8.9M110](/packages/mongodb-laravel-mongodb)[psalm/plugin-laravel

Psalm plugin for Laravel

3345.4M354](/packages/psalm-plugin-laravel)[laravel/ai

The official AI SDK for Laravel.

1.1k4.6M323](/packages/laravel-ai)[yajra/laravel-oci8

Oracle DB driver for Laravel via OCI8

8723.3M27](/packages/yajra-laravel-oci8)[api-platform/laravel

API Platform support for Laravel

58190.1k21](/packages/api-platform-laravel)[calebdw/larastan

Larastan - Discover bugs in your code without running it. A phpstan/phpstan extension for Laravel

16132.2k4](/packages/calebdw-larastan)

PHPackages © 2026

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