PHPackages                             dolly/dolly - 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. [Database &amp; ORM](/categories/database)
4. /
5. dolly/dolly

ActiveLibrary[Database &amp; ORM](/categories/database)

dolly/dolly
===========

A thin library for easily creating database fixtures at runtime during tests.

0.3.1(7y ago)0387MITPHPPHP ^7.0.0

Since Mar 30Pushed 7y ago1 watchersCompare

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

READMEChangelog (4)Dependencies (2)Versions (5)Used By (0)

Dolly - Lightweight database fixture library
============================================

[](#dolly---lightweight-database-fixture-library)

Dolly is a very lightweight *PHP library* that makes creating fixtures for testing database applications easier. It supports SQL based bakends, sequences, has one and has many associations.

The user defines factories, which serve as blueprints with default values for the rows to be created in the database. During tests, factories can be used to actually insert rows in the database.

This is heavily inspired by [factory\_bot](https://github.com/thoughtbot/factory_bot), but not nearly as feature rich.

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

[](#installation)

Install the latest version with composer

```
composer require --dev dolly/dolly
```

Basic Usage
-----------

[](#basic-usage)

```
use Dolly\Factory;
use Dolly\Storage;

// Implement the Storage interface, providing the connection to your database
// In a real scenario this should be a thin wrapper to your app database connection, so that it can be shared
// across tests

class MyStorage implements Storage {
	protected $pdo;

	public function __construct()
	{
		$this->pdo = new PDO(
			'mysql:host=HOSTNAME;dbname=DATABASE_NAME',
			USERNAME,
			PASSWORD,
			array(PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8")
		);
		$this->pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
	}

	public function query($query)
	{
		$this->pdo->query($query);
		return true;
	}

	public function quote($value)
	{
		return $this->pdo->quote($value);
	}

	public function getLastInsertId()
	{
		return $this->pdo->lastInsertId();
	}
}

// Setup the storage for all factories
$storage = new MyStorage();
Factory::setup(array('storage' => $storage));

// Create a basic user factory, which will use the users sql table
// Note the factory name "user", gets mapped to the "users" table
// The SQL table name can be overriden for each factory if this is not desired
Factory::define('user', array(
	'username' => 'Test',
	'email' => 'test@example.com',
	'password' => '123456'
));

// To insert a row in the db, simply call the create method
$user = Factory::create('user');

$user->username; // Equals Test
$user->email; // Equals test@example.com
$user->password; // Equals 123456

// You can, of course, override some of the default factory values
$user = Factory::create('user', array('username' => 'ModifiedUsername', 'email' => 'mod@example.com'));
```

###  Health Score

24

—

LowBetter than 32% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity12

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity48

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

Total

4

Last Release

2577d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/b51af26ea880fa8b1630fdc7670b7f0137635eeda79d23379e377a7a3e17a04e?d=identicon)[ablagoev](/maintainers/ablagoev)

---

Top Contributors

[![ablagoev](https://avatars.githubusercontent.com/u/1012269?v=4)](https://github.com/ablagoev "ablagoev (13 commits)")

---

Tags

factoryfixturesdatabasetests

###  Code Quality

TestsPHPUnit

Code StylePHP\_CodeSniffer

### Embed Badge

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

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

###  Alternatives

[spatie/laravel-backup

A Laravel package to backup your application

6.0k21.8M191](/packages/spatie-laravel-backup)[scienta/doctrine-json-functions

A set of extensions to Doctrine that add support for json query functions.

58523.9M36](/packages/scienta-doctrine-json-functions)[webonaute/doctrine-fixtures-generator-bundle

Generate Fixture from your existing data in your database. You can specify the Entity name and the IDs you want to import in your fixture.

67184.1k](/packages/webonaute-doctrine-fixtures-generator-bundle)

PHPackages © 2026

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