PHPackages                             mgleska/repositorymock - 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. mgleska/repositorymock

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

mgleska/repositorymock
======================

A package to facilitate the testing of classes/methods which uses ORM Repository and ORM Entity objects.

1.1.0(1y ago)033MITPHPPHP &gt;= 8.1

Since May 28Pushed 1y ago1 watchersCompare

[ Source](https://github.com/mgleska/repositorymock)[ Packagist](https://packagist.org/packages/mgleska/repositorymock)[ RSS](/packages/mgleska-repositorymock/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (2)Dependencies (6)Versions (3)Used By (0)

### A package to facilitate the testing of classes/methods which uses ORM Repository and ORM Entity objects.

[](#a-package-to-facilitate-the-testing-of-classesmethods-which-uses-orm-repository-and-orm-entity-objects)

Installation
------------

[](#installation)

```
composer require --dev mgleska/repositorymock:"^1"
```

Features
--------

[](#features)

1. Provides ready-made mocks for functions:

    - `find()`
    - `findOneBy()`
    - `findBy()`
        - by scalar value
        - by list of values
        - by object
    - `save()`
    - `remove()`
2. Allow to create mocks for Entity objects from array of values.

    - simple Entity (without relations)
    - multi-level Entity
        - `Doctrine\ORM\Mapping\OneToOne`
        - `Doctrine\ORM\Mapping\ManyToOne`
        - `Doctrine\ORM\Mapping\OneToMany`
3. Full compatibility with PHPUnit mock. An object of type RepositoryMock can be treated as a regular mock created by PHPUnit.
    For example, you can use `$mockedRepository->method('myCustomMethod')->willReturn(...)`.
4. Provides the `createFakeObject(string $className, array $objData)` method which can be used to create Entity object for use in `willReturn()`.
    Particularly useful for multi-level Entities and those where the `id` field has no setter (because it is autoincrement).
5. Provides the ability to create test scenarios for update/edit and create/delete actions.
    The mock for the `save()` function stores the data sent towards the database. Which gives the possibility to observe the "state of the database" after the tested operation `$sut->action()` is completed.

    - `save()` does:
        - update if entity exists
        - insert with autoincrement for `id`
    - than `getStoreContent()` method allow to make assertions on entities stored in database.

Usage
-----

[](#usage)

1. Mock for simple `find()`.

```
// src/Service/SutService.php

class SutService
{
    public function __construct(
        private readonly Repository $repository,
    ) {
    }

    public function getFirst(): ?Entity
    {
        return $this->repository->find(1);
    }
}
```

```
// tests/Service/SutServiceTest.php

use RepositoryMock\RepositoryMockObject;
use RepositoryMock\RepositoryMockTrait;
...

class SutServiceTest extends TestCase
{
    use RepositoryMockTrait;

    private Sutservice $sut;

    private Repository|RepositoryMockObject $repository;

    protected function setUp(): void
    {
        $this->repository = $this->createRepositoryMock(Repository::class);

        $this->sut = new SutService(
            $this->repository,
        );
    }

    #[Test]
    public function getFirstFound(): void
    {
        $this->repository->loadStore([
            [ // values of selected properties of Entity
                'id' => 1,
                'name' => 'test',
            ],
        ]);

        $result = $this->sut->getFirst();

        $this->assertInstanceOf(Entity::class, $result);
    }

    #[Test]
    public function getFirstNotFound(): void
    {
        $this->repository->loadStore([
            [
                'id' => 22,
                'name' => 'test 22',
            ],
        ]);

        $result = $this->sut->getFirst();

        $this->assertNull($result);
    }
}
```

2. More usage examples in file `tests/SutServiceTest.php`.

###  Health Score

28

—

LowBetter than 54% of packages

Maintenance38

Infrequent updates — may be unmaintained

Popularity8

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity50

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

Total

2

Last Release

566d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/f797d2bf0f4f6b61fe254cb05cadaeae22353b21a0303f945ec476b6fc303a9c?d=identicon)[mgleska](/maintainers/mgleska)

---

Top Contributors

[![mgleska](https://avatars.githubusercontent.com/u/131198655?v=4)](https://github.com/mgleska "mgleska (5 commits)")

###  Code Quality

Static AnalysisPHPStan

Code StylePHP\_CodeSniffer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/mgleska-repositorymock/health.svg)

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

###  Alternatives

[timacdonald/log-fake

A drop in fake logger for testing with the Laravel framework.

4235.9M56](/packages/timacdonald-log-fake)[lchrusciel/api-test-case

Perfect PHPUnit TestCase for JSON/XML API TDD with Symfony.

4115.5M63](/packages/lchrusciel-api-test-case)[jasonmccreary/laravel-test-assertions

A set of helpful assertions when testing Laravel applications.

3513.9M32](/packages/jasonmccreary-laravel-test-assertions)[ergebnis/phpunit-slow-test-detector

Provides facilities for detecting slow tests in phpunit/phpunit.

1468.1M72](/packages/ergebnis-phpunit-slow-test-detector)[typo3/testing-framework

The TYPO3 testing framework provides base classes for unit, functional and acceptance testing.

675.0M775](/packages/typo3-testing-framework)[robiningelbrecht/phpunit-pretty-print

Prettify PHPUnit output

76460.0k15](/packages/robiningelbrecht-phpunit-pretty-print)

PHPackages © 2026

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