PHPackages                             third-engine/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. [Testing &amp; Quality](/categories/testing)
4. /
5. third-engine/factory

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

third-engine/factory
====================

Provides object creation that makes mocking and good unit testing easy.

1.0.0(10y ago)0104MITPHP &gt;=5.3.3

Since Nov 21Compare

[ Source](https://github.com/ThirdEngine/Factory)[ Packagist](https://packagist.org/packages/third-engine/factory)[ Docs](https://github.com/ThirdEngine/Factory)[ RSS](/packages/third-engine-factory/feed)WikiDiscussions Synced today

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

factory
=======

[](#factory)

Factory is used to create objects in a standard way that allow for easy replacement with test double from unit tests. This has only been tested with phpunit, but there isn't a reason it should not be able to work with other unit testing frameworks.

// This is equivalent to $newObject = new NewObjectClass(); in your normal code execution $newObject = Factory::createNewObject(NewObjectClass::class); $newObject-&gt;standardOperations();

Then when you are in a unit test, there is a simple method to replace $newObject with a test double.

// $newObjectMock is already a mock object, and you want it to take the place of $newObject Factory::injectObject(NewObjectClass::class, $newObjectMock);

In many cases, your constructors will take parameters. With Factory, it is simple to pass parameters to object constructors.

// This is equivalent to $newObject = new NewObjectClass($someOtherObject); $newObject = Factory::createNewObject(NewObjectClass::class, \[$someOtherObject\]); $newObject-&gt;standardOperations();

Then when you are in a unit test, everything works the same way. $newObjectMock is already a mock object. Factory::injectObject(NewObjectClass::class, $newObjectMock);

Factory also supports being able to create different instances of the same object. Many times you will need to create the same object in multiple methods.

$newObject1 = Factory::createNewObject(NewObjectClass::class);

// a little while later 4newObject2 = Factory::createNewObject(NewObjectClass::class);

// In your test, assuming $newObject1Mock and $newObject2Mock are mock objects already. Use a zero-based index // to order the injections you want. Factory::injectObject(NewObjectClass::class, $newObject1Mock, 0); Factory::injectObject(NewObjectClass::class, $newObject2Mock, 1);

###  Health Score

25

—

LowBetter than 35% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity9

Limited adoption so far

Community2

Small or concentrated contributor base

Maturity58

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

Unknown

Total

1

Last Release

3874d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/4466618?v=4)[Tony Vance](/maintainers/tonyvance)[@tonyvance](https://github.com/tonyvance)

---

Tags

unitfactory

### Embed Badge

![Health badge](/badges/third-engine-factory/health.svg)

```
[![Health](https://phpackages.com/badges/third-engine-factory/health.svg)](https://phpackages.com/packages/third-engine-factory)
```

###  Alternatives

[pestphp/pest

The elegant PHP Testing Framework.

11.6k72.2M19.4k](/packages/pestphp-pest)[drupal/core-dev

require-dev dependencies from drupal/drupal; use in addition to drupal/core-recommended to run tests from drupal/core.

2022.6M324](/packages/drupal-core-dev)[diablomedia/phpunit-pretty-printer

A PHPUnit result printer that shows per-file test progress and execution times

80536.3k5](/packages/diablomedia-phpunit-pretty-printer)[elliotchance/concise

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

45224.0k4](/packages/elliotchance-concise)[http-interop/http-factory-tests

Unit tests for HTTP factories

12257.2k40](/packages/http-interop-http-factory-tests)

PHPackages © 2026

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