PHPackages                             lucaszz/doctrine-database-backup - 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. lucaszz/doctrine-database-backup

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

lucaszz/doctrine-database-backup
================================

Doctrine Database Backup

1.2.3(9y ago)151.1k1MITPHPPHP &gt;=5.4

Since Oct 5Pushed 7y agoCompare

[ Source](https://github.com/Lucaszz/DoctrineDatabaseBackup)[ Packagist](https://packagist.org/packages/lucaszz/doctrine-database-backup)[ RSS](/packages/lucaszz-doctrine-database-backup/feed)WikiDiscussions master Synced 3w ago

READMEChangelog (9)Dependencies (5)Versions (9)Used By (0)

DoctrineDatabaseBackup
======================

[](#doctrinedatabasebackup)

[![Build Status](https://camo.githubusercontent.com/c3573bbc2be5f900e9b6cb9617d612927e31e6e99505b4c088443a262dc3978b/68747470733a2f2f7472617669732d63692e6f72672f6c7a616b727a6577736b692f446f637472696e6544617461626173654261636b75702e737667)](https://travis-ci.org/lzakrzewski/DoctrineDatabaseBackup) [![Latest Stable Version](https://camo.githubusercontent.com/b5b872abad02e9b75e684cd11a40dd1d71b1f9d209ec9b1d3eca60a4b3ebe6c3/68747470733a2f2f706f7365722e707567782e6f72672f6c756361737a7a2f646f637472696e652d64617461626173652d6261636b75702f762f737461626c65)](https://packagist.org/packages/lucaszz/doctrine-database-backup) [![Total Downloads](https://camo.githubusercontent.com/4fe256d2ce7d48e1d9685c4544bb6357518fb0ea6cd328a9ae96d74d61f48522/68747470733a2f2f706f7365722e707567782e6f72672f6c756361737a7a2f646f637472696e652d64617461626173652d6261636b75702f646f776e6c6f616473)](https://packagist.org/packages/lucaszz/doctrine-database-backup) [![Coverage Status](https://camo.githubusercontent.com/182aa06ccf7e5cc3eaacc1fb41d7dd333b5482b6720210a00bd3bc14d5ffe157/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f6c7a616b727a6577736b692f446f637472696e6544617461626173654261636b75702f62616467652e7376673f6272616e63683d6d617374657226736572766963653d676974687562)](https://coveralls.io/github/lzakrzewski/DoctrineDatabaseBackup?branch=master)

DoctrineDatabaseBackup is simple library for speed up tests in your app. It could be used for **PHPUnit** tests or **Behat** tests running from command line. My target was to avoid wasting time for dropping/creating or purging database for each test, so I optimized it.

This library puts contents of database to memory and share it between every tests.

**Notice:** I don't recommend to use this library with large fixtures because it can cause huge memory usage. I prefer to run tests with minimal database setup because it is more readable for me and it have better performance.

Requirements
------------

[](#requirements)

```
  "require": {
    "php": ">=5.4",
    "doctrine/orm": "~2.3",
    "symfony/process": "~2.3"
  },
```

Features
--------

[](#features)

- It supports **SqlitePlatform** and **MySqlPlatform**,
- It can create database backup per PHP process,
- It can purge database in fast way,
- It can restore database from backup before every test,
- It can restore clear database before every test.

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

[](#installation)

Require the library with composer:

```
composer require lzakrzewski/doctrine-database-backup "~1.2"
```

Basic usage (PHPUnit example)
-----------------------------

[](#basic-usage-phpunit-example)

```
/** {@inheritdoc} */
protected function setUp()
{
    parent::setUp();

    $this->entityManager = $this->createEntityManager();

    $backup = new DoctrineDatabaseBackup($this->entityManager);
    $backup->restore();
}
```

This database setup prepares clear database before every test. [Full working example](https://github.com/lzakrzewski/DoctrineDatabaseBackup/blob/master/tests/Integration/BasicPHPUnitUsageExampleTest.php).

Advanced usage (PHPUnit example)
--------------------------------

[](#advanced-usage-phpunit-example)

```
/** {@inheritdoc} */
protected function setUp()
{
    parent::setUp();

    $this->entityManager = $this->createEntityManager();
    $backup = new DoctrineDatabaseBackup($this->entityManager);

    $backup->restore(function (EntityManager $entityManager) {
        //your fixtures
        $entityManager->persist(new TestProduct('Iron', 99));
        $entityManager->flush();
    });
}
```

This database setup database with your fixtures before every test. [Full working example](https://github.com/lzakrzewski/DoctrineDatabaseBackup/blob/master/tests/Integration/AdvancedPHPUnitUsageExampleTest.php).

**Notice:** that before first test of PHP process database should be created.

Behat example
-------------

[](#behat-example)

```
/** @BeforeScenario*/
public function restoreDatabase()
{
    // "getEntityManager" is your own getter for EntityManager
    $backup = new DoctrineDatabaseBackup($this->getEntityManager());
    $backup->restore();
}
```

###  Health Score

32

—

LowBetter than 69% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity23

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity63

Established project with proven stability

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

Recently: every ~65 days

Total

9

Last Release

3531d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/4248462?v=4)[Łukasz Zakrzewski](/maintainers/lzakrzewski)[@lzakrzewski](https://github.com/lzakrzewski)

---

Top Contributors

[![lzakrzewski](https://avatars.githubusercontent.com/u/4248462?v=4)](https://github.com/lzakrzewski "lzakrzewski (80 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/lucaszz-doctrine-database-backup/health.svg)

```
[![Health](https://phpackages.com/badges/lucaszz-doctrine-database-backup/health.svg)](https://phpackages.com/packages/lucaszz-doctrine-database-backup)
```

###  Alternatives

[kimai/kimai

Kimai - Time Tracking

4.7k8.7k1](/packages/kimai-kimai)[sulu/sulu

Core framework that implements the functionality of the Sulu content management system

1.3k1.4M196](/packages/sulu-sulu)[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)[open-dxp/opendxp

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

9317.2k55](/packages/open-dxp-opendxp)[bartlett/php-compatinfo-db

Reference Database of all functions, constants, classes, interfaces on PHP standard distribution and about 110 extensions

1184.5k2](/packages/bartlett-php-compatinfo-db)[forumify/forumify-platform

122.0k12](/packages/forumify-forumify-platform)

PHPackages © 2026

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