PHPackages                             dkplus/formica - 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. dkplus/formica

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

dkplus/formica
==============

Formica allows to easily use the builder pattern in your projects e.g. to setup your test data.

v0.1.1(9y ago)0116MITPHP

Since Sep 21Pushed 9y ago1 watchersCompare

[ Source](https://github.com/Dkplus/Formica)[ Packagist](https://packagist.org/packages/dkplus/formica)[ RSS](/packages/dkplus-formica/feed)WikiDiscussions master Synced 3d ago

READMEChangelog (2)Dependencies (3)Versions (3)Used By (0)

Formica
=======

[](#formica)

[![SensioLabsInsight](https://camo.githubusercontent.com/9d8d020589cd41f87b38ee9d4913625f62c4e796939dbb15bc6adc1cb884becc/68747470733a2f2f696e73696768742e73656e73696f6c6162732e636f6d2f70726f6a656374732f62303532633234302d653032642d343431332d393462652d3533356530396465306533632f6d696e692e706e67)](https://insight.sensiolabs.com/projects/b052c240-e02d-4413-94be-535e09de0e3c)[![Build Status](https://camo.githubusercontent.com/29f5145387cbc0086de54ea45814d2e872a2d333231dc3eee88ffa058852b83a/68747470733a2f2f7472617669732d63692e6f72672f446b706c75732f466f726d6963612e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/Dkplus/Formica)

Formica allows to easily use the builder pattern in your projects e.g. to setup your test data.

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

[](#installation)

Formica can be easily installed by running `composer require dkplus/formica`.

Quick start
-----------

[](#quick-start)

Lets assume that you have a class `Acme\Issue` for which you want to have a builder for. It has some properties and can be constructed through a named constructor.

```
namespace Acme;

class Issue
{
    // …

    public static function bug(string $id, string $title, string $text): self
    {
        // …
    }

    // …
}
```

For a builder you need another class `Acme\IssueBuilder` which extends the base builder:

```
namespace Acme;

use Dkplus\Formica\Builder;

/**
 * @method IssueBuilder withTitle(string $title)
 * @method IssueBuilder withText(string $text)
 */
class IssueBuilder extends Builder
{
    public static function aBug()
    {
        return new self([
            '74738ff5-5367-5958-9aee-98fffdcd1876',
            'title' => 'It does not work',
            'text' => 'A long error text',
        ], 'bug');
    }
}
```

You can use the builder like this:

```
$issue = IssueBuilder::aBug()->withTitle('Another title')->build();
```

Explanations
------------

[](#explanations)

The `Dkplus\Formica\Builder` expects three arguments:

- The default arguments that should be passed to the constructing method.
- The name of the static method that should be used to construct the object. If `null` is given it will use the constructor of the object.
- The class of the object. If `null` is given it will try to guess the class by using the class of the builder and stripping the last 7 characters. So if you name your builders `Builder` you don't need to pass the class.

While the constructor of `Dkplus\Formica\Builder` is public, I advise to create a static method that calls it and sets the default values.

All arguments that have been given with a key can be overriden by one of `withX()` or `andX()` methods (both providing a fluent interface).

If you want some autocompletion I suggest to put some annotations on top of your builder (see the example above).

###  Health Score

25

—

LowBetter than 35% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity10

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity54

Maturing project, gaining track record

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

Total

2

Last Release

3571d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/332fa213a52cc7607fb381af6d196f51f073f97ebdb113e4db9bde55663018ce?d=identicon)[\[-UFO-\]Melkor](/maintainers/[-UFO-]Melkor)

---

Top Contributors

[![UFOMelkor](https://avatars.githubusercontent.com/u/571106?v=4)](https://github.com/UFOMelkor "UFOMelkor (8 commits)")

---

Tags

testbuildersetuptest data

###  Code Quality

Code StylePHP\_CodeSniffer

### Embed Badge

![Health badge](/badges/dkplus-formica/health.svg)

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

###  Alternatives

[mockery/mockery

Mockery is a simple yet flexible PHP mock object framework

10.7k526.2M26.7k](/packages/mockery-mockery)[hamcrest/hamcrest-php

This is the PHP port of Hamcrest Matchers

7.0k513.4M122](/packages/hamcrest-hamcrest-php)[nelmio/alice

Expressive fixtures generator

2.5k45.2M165](/packages/nelmio-alice)[zenstruck/foundry

A model factory library for creating expressive, auto-completable, on-demand dev/test fixtures with Symfony and Doctrine.

79613.7M145](/packages/zenstruck-foundry)[php-mock/php-mock

PHP-Mock can mock built-in PHP functions (e.g. time()). PHP-Mock relies on PHP's namespace fallback policy. No further extension is needed.

37419.9M124](/packages/php-mock-php-mock)[brain/monkey

Mocking utility for PHP functions and WordPress plugin API

34214.3M470](/packages/brain-monkey)

PHPackages © 2026

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