PHPackages                             mpyw/mockery-pdo - 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/mockery-pdo

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

mpyw/mockery-pdo
================

BDD-style PDO Mocking Library for Mockery

v0.0.1-alpha9(4mo ago)310.9k↓41.4%2[1 issues](https://github.com/mpyw/mockery-pdo/issues)1MITPHPPHP ^8.2CI passing

Since Aug 26Pushed 4mo ago4 watchersCompare

[ Source](https://github.com/mpyw/mockery-pdo)[ Packagist](https://packagist.org/packages/mpyw/mockery-pdo)[ RSS](/packages/mpyw-mockery-pdo/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (3)Dependencies (2)Versions (10)Used By (1)

Mockery PDO [![Build Status](https://github.com/mpyw/mockery-pdo/actions/workflows/ci.yml/badge.svg?branch=master)](https://github.com/mpyw/mockery-pdo/actions) [![Coverage Status](https://camo.githubusercontent.com/610dbb126099b749ff4e1961a738cb1f8dad01c75c3583d132bfefc81ff8e293/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f6769746875622f6d7079772f6d6f636b6572792d70646f2f62616467652e7376673f6272616e63683d6d6173746572)](https://coveralls.io/github/mpyw/mockery-pdo?branch=master)
===========================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================

[](#mockery-pdo--)

Warning

**Experimental**

BDD-style PDO Mocking Library for [`mockery/mockery`](https://github.com/mockery/mockery)

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

[](#requirements)

- PHP: `^8.2`
- Mockery: `^1.6.12`

Note

Older versions have outdated dependency requirements. If you cannot prepare the latest environment, please refer to past releases.

Installing
----------

[](#installing)

```
composer require mpyw/mockery-pdo:VERSION@alpha
```

Example
-------

[](#example)

### SELECT

[](#select)

#### Basic

[](#basic)

```
$pdo = (new MockeryPDO())->mock();

$pdo->shouldPrepare('select * from users where email = :email and active = :active')
    ->shouldBind()
        ->value('email', 'John')
        ->boolValue('active', true)
    ->shouldExecute()
    ->shouldFetchAllReturns([['id' => 1, 'name' => 'John', 'active' => 1]]);

$this->assertInstanceOf(
    PDOStatement::class,
    $stmt = $pdo->prepare('select * from users where email = :email and active = :active')
);

$this->assertTrue($stmt->bindValue('email', 'John'));
$this->assertTrue($stmt->bindValue('active', 'John', PDO::PARAM_BOOL));
$this->assertTrue($stmt->execute());

$this->assertSame(
    [['id' => 1, 'name' => 'John', 'active' => 1]],
    $stmt->fetchAll()
);
```

#### Bind values on `execute()` call

[](#bind-values-on-execute-call)

```
$pdo = (new MockeryPDO())->mock();

$pdo->shouldPrepare('select * from users where email = ? and active = ?')
    ->shouldExecute(['John', '1'])
    ->shouldFetchAllReturns([['id' => 1, 'name' => 'John', 'active' => 1]]);

$this->assertInstanceOf(
    PDOStatement::class,
    $stmt = $pdo->prepare('select * from users where email = ? and active = ?')
);
$this->assertTrue($stmt->execute(['John', '1']));

$this->assertSame(
    [['id' => 1, 'name' => 'John', 'active' => 1]],
    $stmt->fetchAll()
);
```

#### Progressively fetch rows

[](#progressively-fetch-rows)

```
$pdo = (new MockeryPDO())->mock();

$pdo->shouldPrepare('select * from users where email = :email and active = :active')
    ->shouldBind()
        ->value('email', 'John')
        ->boolValue('active', true)
    ->shouldExecute()
    ->shouldStartFetching()
        ->fetchReturns((object)['id' => 1, 'name' => 'John', 'active' => 1])
            ->with(PDO::FETCH_OBJ)
        ->fetchEnds();

$this->assertInstanceOf(
    PDOStatement::class,
    $stmt = $pdo->prepare('select * from users where email = :email and active = :active')
);

$this->assertTrue($stmt->bindValue('email', 'John'));
$this->assertTrue($stmt->bindValue('active', 'John', PDO::PARAM_BOOL));
$this->assertTrue($stmt->execute());

$this->assertEquals((object)['id' => 1, 'name' => 'John', 'active' => 1], $stmt->fetch(PDO::FETCH_OBJ));
$this->assertFalse($stmt->fetch());
$this->assertFalse($stmt->fetch());
$this->assertFalse($stmt->fetch());
```

### INSERT

[](#insert)

```
$pdo = (new MockeryPDO())->mock();

$pdo->shouldPrepare('insert into users(email, active) values (?, ?)')
    ->shouldExecute(['John', '1'])
    ->shouldRowCountReturns(1);

$this->assertInstanceOf(
    PDOStatement::class,
    $stmt = $pdo->prepare('insert into users(email, active) values (?, ?)')
);
$this->assertTrue($stmt->execute(['John', '1']));
$this->assertSame(1, $stmt->rowCount());
```

###  Health Score

46

—

FairBetter than 93% of packages

Maintenance68

Regular maintenance activity

Popularity30

Limited adoption so far

Community13

Small or concentrated contributor base

Maturity59

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 ~244 days

Recently: every ~477 days

Total

9

Last Release

140d ago

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

v0.0.1-alpha5PHP ^7.1 || ^8.0

v0.0.1-alpha7PHP ^7.3 || ^8.0

v0.0.1-alpha9PHP ^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 (22 commits)")

---

Tags

mockerypdophptestingmockingtestdatabaseBDDmockerymockpdo

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/mpyw-mockery-pdo/health.svg)

```
[![Health](https://phpackages.com/badges/mpyw-mockery-pdo/health.svg)](https://phpackages.com/packages/mpyw-mockery-pdo)
```

###  Alternatives

[mockery/mockery

Mockery is a simple yet flexible PHP mock object framework

10.7k497.0M23.6k](/packages/mockery-mockery)[brain/monkey

Mocking utility for PHP functions and WordPress plugin API

33812.5M350](/packages/brain-monkey)[php-mock/php-mock

PHP-Mock can mock built-in PHP functions (e.g. time()). PHP-Mock relies on PHP's namespace fallback policy. No further extension is needed.

36918.1M98](/packages/php-mock-php-mock)[php-mock/php-mock-mockery

Mock built-in PHP functions (e.g. time()) with Mockery. This package relies on PHP's namespace fallback policy. No further extension is needed.

392.1M96](/packages/php-mock-php-mock-mockery)[polishsymfonycommunity/symfony-mocker-container

Provides base Symfony dependency injection container enabling service mocking.

1468.0M237](/packages/polishsymfonycommunity-symfony-mocker-container)[php-mock/php-mock-phpunit

Mock built-in PHP functions (e.g. time()) with PHPUnit. This package relies on PHP's namespace fallback policy. No further extension is needed.

1718.2M399](/packages/php-mock-php-mock-phpunit)

PHPackages © 2026

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