PHPackages                             happyr/service-mocking - 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. happyr/service-mocking

ActiveSymfony-bundle[Testing &amp; Quality](/categories/testing)

happyr/service-mocking
======================

Make it easy to mock services in a built container

1.0.0(1y ago)48253.8k↓26.4%72MITPHPPHP &gt;=8.1

Since Dec 24Pushed 1y ago4 watchersCompare

[ Source](https://github.com/Happyr/service-mocking)[ Packagist](https://packagist.org/packages/happyr/service-mocking)[ GitHub Sponsors](https://github.com/Nyholm)[ RSS](/packages/happyr-service-mocking/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (8)Dependencies (6)Versions (10)Used By (2)

Happyr Service Mocking
======================

[](#happyr-service-mocking)

[![Latest Version](https://camo.githubusercontent.com/6487fe9b56c5c5eb6f47c9c63149a3d58c89fc61177aa02252b69e1e130bec05/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f72656c656173652f4861707079722f736572766963652d6d6f636b696e672e7376673f7374796c653d666c61742d737175617265)](https://github.com/Happyr/service-mocking/releases)[![Total Downloads](https://camo.githubusercontent.com/87168b35626a63eb42161bfea23823fb5c012cc2a5ec71c37eea9fadc768f7ea/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6861707079722f736572766963652d6d6f636b696e672e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/happyr/service-mocking)

You want your tests to run as quick as possible, so you build your container once and let all your tests run on that built container. That is great!

However, when your service container is built, it is immutable. This causes problems when you want to mock a service during a functional test. There is no way for you to change the object in the service container.

Using this bundle, you can mark some services as "mockable", that will allow you to define a new custom behavior for a method in that service. If no custom behavior is defined, the service works as normal.

Install
-------

[](#install)

```
composer require --dev happyr/service-mocking

```

Make sure to enable the bundle for your test environment only:

```
// config/bundles.php
