PHPackages                             firehed/mocktrine - 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. firehed/mocktrine

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

firehed/mocktrine
=================

PHPUnit Doctrine mocking tools

0.7.0(2y ago)514.8k↓33.3%[7 issues](https://github.com/Firehed/mocktrine/issues)[3 PRs](https://github.com/Firehed/mocktrine/pulls)MITPHPPHP ^7.4 || ^8.0CI passing

Since Oct 8Pushed 1mo agoCompare

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

READMEChangelog (7)Dependencies (9)Versions (17)Used By (0)

Mocktrine
=========

[](#mocktrine)

A Doctrine mocking library for testing

[![Latest Stable Version](https://camo.githubusercontent.com/d49a5f0f837f2ef85cc7c245470cf17b0b1fe32a801cab74c4358e97e1fba44b/68747470733a2f2f706f7365722e707567782e6f72672f666972656865642f6d6f636b7472696e652f76)](//packagist.org/packages/firehed/mocktrine)[![License](https://camo.githubusercontent.com/1f192963ce129f09f47f58bbb6661193ca9c806bddcc5e452f14b9b75e405b58/68747470733a2f2f706f7365722e707567782e6f72672f666972656865642f6d6f636b7472696e652f6c6963656e7365)](//packagist.org/packages/firehed/mocktrine)[![Test](https://github.com/Firehed/mocktrine/workflows/Test/badge.svg)](https://github.com/Firehed/mocktrine/actions?query=workflow%3ATest)[![Static analysis](https://github.com/Firehed/mocktrine/workflows/Static%20analysis/badge.svg)](https://github.com/Firehed/mocktrine/actions?query=workflow%3A%22Static+analysis%22)[![Lint](https://github.com/Firehed/mocktrine/workflows/Lint/badge.svg)](https://github.com/Firehed/mocktrine/actions?query=workflow%3ALint)

Usage
-----

[](#usage)

In your unit tests that need an Entity Manager, use a `new \Firehed\Mocktrine\InMemoryEntityManager`. Done!

Any object with Doctrine's entity annotations (`@Entity`, `@Id`, `@Column`, etc) should work without modification.

This library aims to provide as much type information as possible, so that static analysis tools (such as PHPStan) work well without additional plugins.

### Mapping support

[](#mapping-support)

As of version 0.5, any mapping driver supported by Doctrine can be used with this library. The `InMemoryEntityManager` accepts the driver as an optional parameter.

```
- $em = new Mocktrine\InMemoryEntityManager();
+ $em = new Mocktrine\InMemoryEntityManager(
+     \Doctrine\ORM\Mapping\Driver\AttributeDriver(['src/Model']),
+ );
```

You can also grab the value directly from your Doctrine config:

```
$config = Setup::createAnnotationMetadataDriverConfiguration(...)
$driver = $config->getMetadataDriverImpl();
$em = new Mocktrine\InMemoryEntityManager($driver)
```

If a driver is not provided, it will default to either `SimpleAnnotationReader` or `AnnotationReader` that's used via `Setup::createAnnotationMetadataConfiguration`. The former will be preferred, but the class has been removed in `doctrine/annotations:2.0`; if your local dependencies allow that version then the latter will be used.

It is RECOMMENDED to always explicitly provide a driver, as that best matches Doctrine's own setup behavior. Future versions of this library may make this required.

Supported features
------------------

[](#supported-features)

The following methods on Doctrine's `EntityManagerInterface` should all work as expected:

- find
- persist
- remove
- merge
- flush
- getRepository
- getCache (will always return `null`)
- isOpen (will always return `true`)

All methods on the `ObjectRepository` (for various findBy operations) should also work, as well as the non-interface `count($criteria)` method. `ObjectRepository` also implements the `Selectable` interface (as `EntityRepository` does, which is the returned type from `EntityManager`), so it's also possible to use the `matching(Criteria)` method.

The following methods are **not** supported at this time:

- clear
- detach
- refresh
- getClassMetadata
- getMetadataFactory
- initializeObject
- contains
- getConnection
- getExpressionBuilder
- beginTransaction
- transactional
- commit
- rollback
- createQuery
- createNamedQuery
- createNativeQuery
- createNamedNativeQuery
- getReference
- getPartialReference
- close
- copy
- lock
- getEventManager
- getConfiguration
- getUnitOfWork
- getHydrator
- newHydrator
- getProxyFactory
- getFilters
- isFiltersStateClean
- hasFilters

###  Health Score

39

—

LowBetter than 86% of packages

Maintenance39

Infrequent updates — may be unmaintained

Popularity29

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity66

Established project with proven stability

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

Recently: every ~285 days

Total

9

Last Release

840d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/354842?v=4)[Eric Stern](/maintainers/Firehed)[@Firehed](https://github.com/Firehed)

---

Top Contributors

[![Firehed](https://avatars.githubusercontent.com/u/354842?v=4)](https://github.com/Firehed "Firehed (47 commits)")

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StylePHP\_CodeSniffer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/firehed-mocktrine/health.svg)

```
[![Health](https://phpackages.com/badges/firehed-mocktrine/health.svg)](https://phpackages.com/packages/firehed-mocktrine)
```

###  Alternatives

[sylius/sylius

E-Commerce platform for PHP, based on Symfony framework.

8.4k5.6M651](/packages/sylius-sylius)[phpbench/phpbench

PHP Benchmarking Framework

2.0k13.0M627](/packages/phpbench-phpbench)[sulu/sulu

Core framework that implements the functionality of the Sulu content management system

1.3k1.3M152](/packages/sulu-sulu)[ec-cube/ec-cube

EC-CUBE EC open platform.

78527.0k1](/packages/ec-cube-ec-cube)[sonata-project/entity-audit-bundle

Audit for Doctrine Entities

644989.8k1](/packages/sonata-project-entity-audit-bundle)[liip/test-fixtures-bundle

This bundles enables efficient loading of Doctrine fixtures in functional test-cases for Symfony applications

1798.3M42](/packages/liip-test-fixtures-bundle)

PHPackages © 2026

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