PHPackages                             jefferson-lima/fixture-factory - 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. [Utility &amp; Helpers](/categories/utility)
4. /
5. jefferson-lima/fixture-factory

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

jefferson-lima/fixture-factory
==============================

1.0.0(6y ago)09MITPHPCI failing

Since May 10Pushed 5y ago1 watchersCompare

[ Source](https://github.com/jefferson-lima/fixture-factory)[ Packagist](https://packagist.org/packages/jefferson-lima/fixture-factory)[ RSS](/packages/jefferson-lima-fixture-factory/feed)WikiDiscussions master Synced 3w ago

READMEChangelogDependencies (12)Versions (5)Used By (0)

Fixture Factory
===============

[](#fixture-factory)

Generates fixture objects to be used in tests.

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

[](#installation)

```
composer require jefferson-lima/fixture-factory

```

Usage
-----

[](#usage)

Fixture Factory uses the metadata of your class properties to generate values for them. The value generated for a property is derived from its `@var` tag. Thus, first you must annotate your properties with their types:

```
MyClass {

  /** @var string */
  public $foo;

  public $bar;
}

```

The properties without a `@var` tag, or with and invalid one, will be ignored.

Then you can use the `FixtureFactory` to create a fixture for your class:

```
$myFixture = FixtureFactory::createFixture(MyClass::class);

```

Fixture Factory uses [Faker](https://github.com/fzaninotto/Faker) to generate values.

### Supported types

[](#supported-types)

Currently, the supported types are `string`, `int`, `bool`, `float`. Objects are supported, as long as a concrete class is provided. Abstract classes or interfaces are not supported as it's not possible to determine the concrete implementation that should be used. Nested objects will be generated recursively.

### Overriding attributes

[](#overriding-attributes)

It's possible to override attributes by passing an array as a second argument to the `createFixture`method:

```
$myFixture = FixtureFactory::createFixture(MyClass::class, ['foo' => 'bar']);

```

### Circular references

[](#circular-references)

Care must be taken with circular references, they must be avoided or overridden, otherwise an exception will be thrown. One example of circular reference is shown below:

```
class Foo {
  /** @var Bar */
  private $bar;
}

class Bar {
  /** @var Foo */
  private $foo;
}

```

A circular reference can be broken by overriding one attribute:

```
$myFixture = FixtureFactory::createFixture(MyClass::class, ['bar' => null]);

```

Doctrine annotations can also be used to resolve circular references, for example:

```
class Foo {
  /**
   * @var Bar
   * @OneToOne(targetEntity="Bar", inversedBy="foo")
   */
  private $bar;
}

class Bar {
  /**
   * @var Foo
   * @OneToOne(targetEntity="Foo", mappedBy="bar")
   */
  private $foo;
}

```

In this case, it's possible to identify that `foo` points to `bar`, and that `bar` points back at it.

### Symfony constraints

[](#symfony-constraints)

It's also possible to use [Symfony validation constraints](https://symfony.com/doc/current/reference/constraints.html#basic-constraints)to narrow down the values generated for your properties. These are the currently supported constraints listed by order of precedence:

Strings:

- [@Regex](https://symfony.com/doc/current/reference/constraints/Regex.html)
- [@Uuid](https://symfony.com/doc/current/reference/constraints/Uuid.html)
- [@Email](https://symfony.com/doc/current/reference/constraints/Email.html)
- [@Url](https://symfony.com/doc/current/reference/constraints/Url.html)
- [@Date](https://symfony.com/doc/current/reference/constraints/Date.html)
- [@DateTime](https://symfony.com/doc/current/reference/constraints/DateTime.html)
- [@Choice](https://symfony.com/doc/current/reference/constraints/Choice.html)
- [@Length](https://symfony.com/doc/current/reference/constraints/Length.html)
- [@NotBlank](https://symfony.com/doc/current/reference/constraints/NotBlank.html)

Some constraints can't be applied simultaneously. In this case, the constraint with higher precedence is applied. For example:

```
/**
 * @Length(min=255)
 * @Email
 */
private $email;

```

In this case, the `@Email` constraint is applied, and the `@Length` will be ignored.

### Doctrine Associations

[](#doctrine-associations)

The following Doctrine associations are supported:

- [@OneToOne](https://www.doctrine-project.org/projects/doctrine-orm/en/2.7/reference/association-mapping.html#one-to-one-unidirectional)
- [@OneToMany](https://www.doctrine-project.org/projects/doctrine-orm/en/2.7/reference/association-mapping.html#one-to-many-unidirectional-with-join-table)
- [@ManyToOne](https://www.doctrine-project.org/projects/doctrine-orm/en/2.7/reference/association-mapping.html#many-to-one-unidirectional)
- [@ManyToMany](https://www.doctrine-project.org/projects/doctrine-orm/en/2.7/reference/association-mapping.html#many-to-many-unidirectional)

For many side of the associations an ArrayCollection with two elements is created.

License
-------

[](#license)

This project is licensed under the MIT License - see the [LICENSE.md](LICENSE.md) file for details

###  Health Score

25

—

LowBetter than 36% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity4

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity59

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

Total

2

Last Release

2193d ago

Major Versions

0.1.0 → 1.0.02020-06-24

### Community

Maintainers

![](https://www.gravatar.com/avatar/8b70310546d40c8c65cfe9b7a5ad813d25f61798ed4e722f299e362eee038585?d=identicon)[jefferson-lima](/maintainers/jefferson-lima)

---

Top Contributors

[![jefferson-lima](https://avatars.githubusercontent.com/u/7573519?v=4)](https://github.com/jefferson-lima "jefferson-lima (40 commits)")

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StylePHP CS Fixer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/jefferson-lima-fixture-factory/health.svg)

```
[![Health](https://phpackages.com/badges/jefferson-lima-fixture-factory/health.svg)](https://phpackages.com/packages/jefferson-lima-fixture-factory)
```

###  Alternatives

[easycorp/easyadmin-bundle

Admin generator for Symfony applications

4.3k17.5M376](/packages/easycorp-easyadmin-bundle)[rcsofttech/audit-trail-bundle

Enterprise-grade, high-performance Symfony audit trail bundle. Automatically track Doctrine entity changes with split-phase architecture, multiple transports (HTTP, Queue, Doctrine), and sensitive data masking.

1155.2k](/packages/rcsofttech-audit-trail-bundle)[pimcore/pimcore

Content &amp; Product Management Framework (CMS/PIM/E-Commerce)

3.8k3.8M462](/packages/pimcore-pimcore)[oro/platform

Business Application Platform (BAP)

642140.7k104](/packages/oro-platform)[web-auth/webauthn-framework

FIDO2/Webauthn library for PHP and Symfony Bundle.

51390.8k2](/packages/web-auth-webauthn-framework)[open-dxp/opendxp

Content &amp; Product Management Framework (CMS/PIM)

9317.2k55](/packages/open-dxp-opendxp)

PHPackages © 2026

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