PHPackages                             precision-soft/symfony-phpunit - 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. precision-soft/symfony-phpunit

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

precision-soft/symfony-phpunit
==============================

Mockery-based mock container and test utilities for Symfony PHPUnit

v3.4.4(2w ago)02.1k6MITPHPPHP &gt;=8.2

Since Sep 17Pushed 2w agoCompare

[ Source](https://github.com/precision-soft/symfony-phpunit)[ Packagist](https://packagist.org/packages/precision-soft/symfony-phpunit)[ Docs](https://github.com/precision-soft/symfony-phpunit)[ RSS](/packages/precision-soft-symfony-phpunit/feed)WikiDiscussions main Synced 2d ago

READMEChangelog (10)Dependencies (34)Versions (29)Used By (6)

Symfony Phpunit
===============

[](#symfony-phpunit)

[![PHP >= 8.2](https://camo.githubusercontent.com/8f0af9c5395ae4ef8ba7a7ad65fa61c44927ea9c3eb3be91a13c678254f29bd4/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f7068702d253345253344382e322d383839324246)](https://www.php.net/)[![PHPStan Level 8](https://camo.githubusercontent.com/44dc5f71fec76653887c975fe3db546a82ff603d094798eb6414a38369db1f44/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f7068707374616e2d6c6576656c253230382d627269676874677265656e)](https://phpstan.org/)[![Code Style PER-CS2.0](https://camo.githubusercontent.com/5cbab3b5c635536159b4d0a5ef49ebc70fcc20757f82d5f83bc251d872914301/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f636f64652532307374796c652d5045522d2d4353322e302d626c7565)](https://www.php-fig.org/per/coding-style/)[![License MIT](https://camo.githubusercontent.com/f8df3091bbe1149f398a5369b2c39e896766f9f6efba3477c63e9b4aa940ef14/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d677265656e)](LICENSE)

A Mockery-based testing library for Symfony applications that simplifies mock creation, dependency injection, and test setup through a declarative `MockDto` configuration pattern.

**You may fork and modify it as you wish**.

Any suggestions are welcomed.

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

[](#requirements)

- PHP &gt;= 8.2
- Mockery 1.\*
- Symfony PHPUnit Bridge 7.\*

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

[](#installation)

```
composer require --dev precision-soft/symfony-phpunit
```

Core Concepts
-------------

[](#core-concepts)

### MockDto

[](#mockdto)

`MockDto` is the central configuration object that describes how a mock should be created.

```
use Mockery\MockInterface;
use PrecisionSoft\Symfony\Phpunit\Container\MockContainer;
use PrecisionSoft\Symfony\Phpunit\Mock\ManagerRegistryMock;
use PrecisionSoft\Symfony\Phpunit\MockDto;

new MockDto(
    class: CreateService::class,
    construct: [
        ManagerRegistryMock::class,
        new MockDto(FooRepository::class),
        'staticDependency',
    ],
    partial: true,
    onCreate: static function (MockInterface $mockInterface, MockContainer $mockContainer): void {
    },
);
```

**Parameters:**

ParameterTypeDefaultDescription`class``string`-FQCN of the class or interface to mock`construct``?array``null`Constructor arguments; `null` bypasses constructor, `[]` calls constructor with no args`partial``bool``false`If `true`, creates a partial mock via `makePartial()``onCreate``?Closure``null`Callback invoked after mock creation for setup### MockDtoInterface

[](#mockdtointerface)

Any class that implements `MockDtoInterface` must provide a static `getMockDto()` method. This allows classes (including test cases and reusable mock definitions) to declare their mock configuration.

```
