PHPackages                             folsh/phpunit-dynamic-fixture - 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. folsh/phpunit-dynamic-fixture

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

folsh/phpunit-dynamic-fixture
=============================

Dynamic setUp to create an appropriate context in your tests

0.2.0(11y ago)1346MITPHP

Since Aug 25Pushed 7y ago1 watchersCompare

[ Source](https://github.com/folsh/phpunit-dynamic-fixture)[ Packagist](https://packagist.org/packages/folsh/phpunit-dynamic-fixture)[ RSS](/packages/folsh-phpunit-dynamic-fixture/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (1)Versions (2)Used By (0)

[![SensioLabsInsight](https://camo.githubusercontent.com/efc43a379bf560be09557872280c873045a2854cac96226745947f3481d32e7b/68747470733a2f2f696e73696768742e73656e73696f6c6162732e636f6d2f70726f6a656374732f62333837366638622d383634652d346264632d386465362d3039303266653562653162342f6d696e692e706e67)](https://insight.sensiolabs.com/projects/b3876f8b-864e-4bdc-8de6-0902fe5be1b4)[![Build Status](https://camo.githubusercontent.com/79f11dd8a49e04101034277bcb0a3f03348339162f43c6951e2c2c25ba88c47e/68747470733a2f2f6170692e7472617669732d63692e6f72672f4e696b6f6d732f706870756e69742d64796e616d69632d666978747572652e706e67)](https://api.travis-ci.org/Nikoms/phpunit-dynamic-fixture)[![Scrutinizer Quality Score](https://camo.githubusercontent.com/7fe13c1f4e5fd87c98143672b2a136eec1a66480b61613b082c9a082a19e6d9d/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f4e696b6f6d732f706870756e69742d64796e616d69632d666978747572652f6261646765732f7175616c6974792d73636f72652e706e67)](https://scrutinizer-ci.com/g/Nikoms/phpunit-dynamic-fixture/)[![Code Coverage](https://camo.githubusercontent.com/8b6eb26a8a68f184cd61f1c5231be1339798fc787f82eae5c373616b0392a7c6/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f4e696b6f6d732f706870756e69742d64796e616d69632d666978747572652f6261646765732f636f7665726167652e706e67)](https://scrutinizer-ci.com/g/Nikoms/phpunit-dynamic-fixture/)

DynamicFixture
==============

[](#dynamicfixture)

Thanks to annotations, this library allows you to call dynamic/custom "setUp" methods before each one of your test. It eases the understanding of your test because you explicitly set which context/variables you will use. It also can speed up your tests as you only initialize what they need.

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

[](#installation)

### Composer

[](#composer)

Simply add this to your `composer.json` file:

```
"require": {
    "folsh/phpunit-dynamic-fixture": "dev-master"
}
```

Then run `php composer.phar install`

PhpUnit configuration
---------------------

[](#phpunit-configuration)

To activate the plugin. Add the listener to your phpunit.xml(.dist) file:

```

    ...

```

Usage
-----

[](#usage)

Use the annotation "@setUpContext" to call the specified method(s) just before the test. Of course, you can add as many annotations as you want.

```
class MyTest extends PHPUnit_Framework_TestCase {

    private $name;

    /**
     * Must be public
     */
    public function setUpName()
    {
        $this->name = 'Nicolas';
    }

    public function initContext()
    {
        //...
    }

    /**
     * @setUpContext setUpName
     * @setUpContext initContext
     * @setUpContext ...
     *
     */
    public function testSetUpName()
    {
        //$this->name is "Nicolas"
    }
}
```

Params
------

[](#params)

If you want to add some parameters in your function, add them between brackets. Warning: at this time, you can only add simple types (see exemples) Types accepted:

- string
- json
- array (single level)
- numeric (convert in string !)

```
class MyTest extends PHPUnit_Framework_TestCase {

    private $name1;
    private $name2;
    private $list;

    /**
     * Must be public
     */
    public function setUpNames($name1, $name2)
    {
        $this->name1 = $name1;
        $this->name2 = $name2;
    }

    public function initContext()
    {
        //...
    }

    /**
     * @setUpContext setUpNames("Nicolas", "Cedric")
     */
    public function testSetUpNames()
    {
        //$this->name1 is "Nicolas"
        //$this->name2 is "Cedric"
    }
}
```

```
class MyTest extends PHPUnit_Framework_TestCase {

    private $list;

    /**
     * Must be public
     */
    public function setUpArray(array $list)
    {
        $this->list = $list;
    }

    public function initContext()
    {
        //...
    }

    /**
     * @setUpContext setUpArray(["Nicolas", "Cedric"])
     */
    public function testSetUpArray()
    {
        //$this->list is array("Nicolas", "Cedric")
    }
}
```

Customize
---------

[](#customize)

If you don't like the name of the annotation, you can change it by passing a new one in the constructor:

```

        myCustomSetUp

```

###  Health Score

26

—

LowBetter than 43% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity13

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity53

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 96.6% 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

Unknown

Total

1

Last Release

4284d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/740718bba1fe2796ab49595c942f204413faec418f469c696df5060121605151?d=identicon)[folsh](/maintainers/folsh)

---

Top Contributors

[![Nikoms](https://avatars.githubusercontent.com/u/375867?v=4)](https://github.com/Nikoms "Nikoms (28 commits)")[![GrahamCampbell](https://avatars.githubusercontent.com/u/2829600?v=4)](https://github.com/GrahamCampbell "GrahamCampbell (1 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/folsh-phpunit-dynamic-fixture/health.svg)

```
[![Health](https://phpackages.com/badges/folsh-phpunit-dynamic-fixture/health.svg)](https://phpackages.com/packages/folsh-phpunit-dynamic-fixture)
```

###  Alternatives

[phpspec/prophecy

Highly opinionated mocking framework for PHP 5.3+

8.5k551.7M682](/packages/phpspec-prophecy)[vimeo/psalm

A static analysis tool for finding errors in PHP applications

5.8k77.5M6.7k](/packages/vimeo-psalm)[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)

PHPackages © 2026

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