PHPackages                             datto/phpunit-entropy - 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. datto/phpunit-entropy

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

datto/phpunit-entropy
=====================

Provides tooling to allow

0.1.1(8y ago)313.1k↑33.3%MITPHPPHP &gt;=5.3.0

Since May 3Pushed 8y ago4 watchersCompare

[ Source](https://github.com/datto/phpunit-entropy)[ Packagist](https://packagist.org/packages/datto/phpunit-entropy)[ Docs](http://datto.com)[ RSS](/packages/datto-phpunit-entropy/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (3)Versions (4)Used By (0)

Datto PHPUnit Entropy
=====================

[](#datto-phpunit-entropy)

Entropy is a library to provide tools for working with randomized testing in PHPUnit as well as for testing systems that make use of PHP's random functions such as `rand` and `shuffle`.

Use cases
---------

[](#use-cases)

### Detect dependent tests

[](#detect-dependent-tests)

Sometimes unit tests require changes to global state, or cover functionality that alters that state. While this is never an ideal situation, this can often result in the creation of inadvertent dependencies on other tests.

Enabling Entropy's test shuffling functionality randomizes the order of your tests, helping to highlight these dependencies.

Entropy's test-shuffling also avoids changing the order of tests using the `@depends` functionality of PHPUnit; future work will work to ensure that shuffling can still occur for these tests when appropriate.

### Randomized testing

[](#randomized-testing)

Sometimes you can find yourself in a situation where the range of inputs for a function is so large that taking a cross-section of those inputs is a more efficient use of your resources. But what happens if that cross-section has holes where your tests might fail?

One way to get around this is to use randomized inputs, where input is generated in such a way as to get a random cross-section of the ranges. In other words, using `rand` or another such non-deterministic approach.

An extension of this, property-based testing is the practice of applying random input to your application or function, and observing that the output adheres to certain rules or has certain properties relative to the input, rather than precise testing of equality to a known result set.

By managing the random seed for your tests, Entropy allows not only the use of these approaches, but also to make them repeatable, either by accepting a fixed seed or recovering it from the last failed run until your test suite passed.

Including in your project
-------------------------

[](#including-in-your-project)

You can add this library to your project using Composer:

```
$ composer require datto/phpunit-entropy
```

Running
-------

[](#running)

Once configured, you can run your test suite as normal; the listener will look after itself. On test error or failure, the seed used will be stored in a temporary file, so that on the next run it will be reused, rather than a new seed generated.

### Defining the seed

[](#defining-the-seed)

The seed for the random number generator is provided from up to four locations, presented here in priority order.

#### Environment variable

[](#environment-variable)

If set, the `SEED` environment variable will be used to override any other settings. It can be set via `export`, but recommended use is to set it for the current run only:

```
SEED=123456 phpunit -c phpunit.xml tests
```

#### Configuration

[](#configuration)

The seed may be fixed by configuration; see the [Configuration](#Configuration)section below.

#### Last run

[](#last-run)

If a test run fails, the seed used is stored in a temporary file. This is then loaded on a subsequent test, and will persist until the suite succeeds again.

#### rand()

[](#rand)

If no seed is set via the above methods, the final method is to use PHP's `rand` function.

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

[](#configuration-1)

### Entropy Test Listener

[](#entropy-test-listener)

Once installed via composer, configuring the test listener is simply a matter of altering your PHPUnit configuration file (often `phpunit.xml`):

```

                                true

                                1234567

                                /tmp/phpentropy-seed

                        true

```

#### Arguments

[](#arguments)

##### seeding

[](#seeding)

###### enabled - boolean

[](#enabled---boolean)

If set to true, the random number generator will be seeded by the listener.

###### seed - integer

[](#seed---integer)

If you set the seed via this argument, only this value will be used to seed the random number generator. See the section on seed priority below.

###### file - string

[](#file---string)

If set, this file will be used to store the last failed random seed; it defaults to `[TMPDIR LOCATION]/phpunit-entropy-seed`.

##### shuffle - boolean

[](#shuffle---boolean)

If set to true, the order in which unit tests are executed will be randomized (except for suites where `@depends` is in use). This is useful in determining and identifying inter-test dependencies.

Future work
-----------

[](#future-work)

- Keep track of subsequent test runs
- Detect changes between runs
- Provide guiding output when tests are shuffled

Developer contact
-----------------

[](#developer-contact)

Christopher Hoult &lt;[choult@datto.com](mailto://choult@datto.com)&gt;

###  Health Score

29

—

LowBetter than 59% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity26

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity50

Maturing project, gaining track record

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

Total

2

Last Release

3056d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/fb044681aa172ced7a03b093bda1f1f1031831133281d3d1e036807d28260c31?d=identicon)[datto-packagist-maintainer](/maintainers/datto-packagist-maintainer)

![](https://www.gravatar.com/avatar/7ab4859289fbfdce0a6a59676bbdabae783908a355d29383251e571ad38fc912?d=identicon)[choult](/maintainers/choult)

---

Tags

phpphpunit

###  Code Quality

TestsPHPUnit

Code StylePHP\_CodeSniffer

### Embed Badge

![Health badge](/badges/datto-phpunit-entropy/health.svg)

```
[![Health](https://phpackages.com/badges/datto-phpunit-entropy/health.svg)](https://phpackages.com/packages/datto-phpunit-entropy)
```

###  Alternatives

[phpspec/prophecy

Highly opinionated mocking framework for PHP 5.3+

8.5k551.7M682](/packages/phpspec-prophecy)[brianium/paratest

Parallel testing for PHP

2.5k118.8M754](/packages/brianium-paratest)[beberlei/assert

Thin assertion library for input validation in business models.

2.4k96.9M570](/packages/beberlei-assert)[mikey179/vfsstream

Virtual file system to mock the real file system in unit tests.

1.4k108.0M2.7k](/packages/mikey179-vfsstream)[orchestra/testbench

Laravel Testing Helper for Packages Development

2.2k39.1M32.1k](/packages/orchestra-testbench)[phpspec/phpspec

Specification-oriented BDD framework for PHP 7.1+

1.9k36.7M3.1k](/packages/phpspec-phpspec)

PHPackages © 2026

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