PHPackages                             gealex/doublit - 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. gealex/doublit

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

gealex/doublit
==============

Doublit : A simple tool to test your class dependencies in PhpUnit

v2.1.5(6y ago)088↓75%1MITPHPPHP &gt;=7.0

Since Jul 21Pushed 6y ago1 watchersCompare

[ Source](https://github.com/gealex/doublit)[ Packagist](https://packagist.org/packages/gealex/doublit)[ Docs](https://github.com/gealex/doublit)[ RSS](/packages/gealex-doublit/feed)WikiDiscussions master Synced yesterday

READMEChangelogDependencies (1)Versions (20)Used By (1)

Doublit - Double and test PHP classes easily in PhpUnit
=======================================================

[](#doublit---double-and-test-php-classes-easily-in-phpunit)

[![Build Status](https://camo.githubusercontent.com/9c2dd7960e6253db6929c015ac1db5c15be1cb72f1ccf7684026145b3da722eb/68747470733a2f2f7472617669732d63692e6f72672f6765616c65782f646f75626c69742e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/gealex/doublit)

Doublit can help you to test your PHP classes by generating doubles that look like the original classes but can be manipulated and tested (sort of a copy of a class). These doubles then can then be used instead of the original classes for your test. Doublit can create doubles of any kind of class, interface or trait.

See full documentation at

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

[](#installation)

Add the line `"gealex/doublit": "~2.1.0"` in the `"require-dev"` section of your composer.json file :

```
{
    "require-dev": {
        "gealex/doublit": "~2.1.0"
    }
}

```

And run the following command :

```
$ composer update

```

This will install the latest version of Doublit with the required PhpUnit package.

Creating a double
-----------------

[](#creating-a-double)

A double is called a "dummy" when all the methods of the original class are overwritten to return `null`. To get a "dummy" double instance, use the `dummy` method :

```
```php
// Get a double instance of type "dummy" for class "MyClass"
$my_double = Doublit::dummy(MyClass::class)->getInstance();
```

```

A double is called a "mock" when all the methods of the original class are overwritten to behave the same as in the original class. To get a "mock" double instance, use the `mock` method :

```
```php
// Get a double instance of type "mock" for class "MyClass"
$my_double = Doublit::mock(MyClass::class)->getInstance();
```

```

For more details : [Read the doc on creating doubles](doc/creating_doubles.md)

Testing a double
----------------

[](#testing-a-double)

To test how many times a double method is called, use the `count` method :

```
```php
// Test that the method "myMethod" is called a least one time
$double::_method('myMethod')->count('>=1');
```

```

To test the values of the arguments passed to a double method, use the `args` method :

```
```php
// Test that the arguments passed to method "myMethod" are "value1" and "value2"
$double::_method('myMethod')->args(['value1', 'value2']);
```

```

To change the return value of a method, use the `stub` method. :

```
```php
// Make method "myMethod" return "hello"
$my_double::_method('myMethod')->stub('hello');
```

```

For more details : [Read the doc on testing doubles](doc/testing_doubles.md)

Configuration
-------------

[](#configuration)

You define the configuration for a specific double using the 2nd argument of the `dummy` and `mock` methods :

```
```php
// Get double instance with config
$my_double = Doublit::dummy(MyClass::class, [
    'allow_final_doubles' => true,
    'allow_non_existent_classes' => true
])->getInstance();
```

```

Here is a list of all available config parameters :

- `allow_final_doubles` : Set this parameter to `false` to stop Doublit from trying to make doubles of final classes/methods.
- `allow_protected_methods` : Set this parameter to `false` to disallow testing protected methods.
- `allow_non_existent_classes` : Set this parameter to `false` to disallow alias doubles of non existent classes.
- `test_unexpected_methods` : Set this parameter to `true` to automatically receive an assertion error whenever an unexpected method is called.

For more details : [Read the doc on configuration](doc/configuration.md)

About
-----

[](#about)

### License

[](#license)

Doublit is licensed under the [MIT license](https://opensource.org/licenses/MIT).

### Author

[](#author)

Alexandre Geiswiller - .

For more details : [Read the doc on about](doc/about.md)

###  Health Score

29

—

LowBetter than 60% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity9

Limited adoption so far

Community9

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

Total

18

Last Release

2535d ago

Major Versions

v1.0.7 → v2.02019-02-24

PHP version history (2 changes)v1.0PHP &gt;=7

v2.1.5PHP &gt;=7.0

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/11295288?v=4)[gealex](/maintainers/gealex)[@gealex](https://github.com/gealex)

---

Top Contributors

[![gealex](https://avatars.githubusercontent.com/u/11295288?v=4)](https://github.com/gealex "gealex (45 commits)")

---

Tags

mockmockingphpphpunittesttest-doublestestingtesting-toolsunit-testunit-testingphptestingphpunittestunit testingmockdoubles

### Embed Badge

![Health badge](/badges/gealex-doublit/health.svg)

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

###  Alternatives

[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)[blastcloud/guzzler

Supercharge your app or SDK with a testing library specifically for Guzzle.

272419.3k35](/packages/blastcloud-guzzler)[donatj/mock-webserver

Simple mock web server for unit testing

1382.5M80](/packages/donatj-mock-webserver)[elliotchance/concise

Concise is test framework for using plain English and minimal code, built on PHPUnit.

45223.8k4](/packages/elliotchance-concise)[robiningelbrecht/phpunit-pretty-print

Prettify PHPUnit output

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

Hammock is a stand-alone mocking library for Hacklang.

27445.5k](/packages/quizlet-hammock)

PHPackages © 2026

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