PHPackages                             vierge-noire/cakephp-test-migrator - 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. vierge-noire/cakephp-test-migrator

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

vierge-noire/cakephp-test-migrator
==================================

Migration helper for the CakePHP Test Suite Light

v2.5(4y ago)12251.9k↓23%31MITPHP

Since Oct 5Pushed 2y ago2 watchersCompare

[ Source](https://github.com/vierge-noire/cakephp-test-migrator)[ Packagist](https://packagist.org/packages/vierge-noire/cakephp-test-migrator)[ RSS](/packages/vierge-noire-cakephp-test-migrator/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (10)Dependencies (5)Versions (23)Used By (1)

cakephp-test-migrator
=====================

[](#cakephp-test-migrator)

A tool to run migrations prior to running tests

The Migrator
------------

[](#the-migrator)

#### For CakePHP 3.x

[](#for-cakephp-3x)

composer require --dev vierge-noire/cakephp-test-migrator "^1.0"

#### For CakePHP 4.x

[](#for-cakephp-4x)

composer require --dev vierge-noire/cakephp-test-migrator "^2.0"

#### For CakePHP 4.3+

[](#for-cakephp-43)

The migrator was integrated into the migration plugin (see the [doc](https://book.cakephp.org/migrations/3/en/index.html#using-migrations-for-tests)). The present package will not be further maintained.

### Introduction

[](#introduction)

CakePHP fixtures handle the test DB schema in a paralell manner to the default DB. On the one hand you will write migrations for your default DB. On the other hand you either hard coded describe the schema structure in your fixtures, or meme the default DB. The later is simpler, but it forces you to have two DBs. And in CI tools, you will have to run the migrations on your default DB, and the fixtures meme the default DB. So why not running migrations directly on the test DB?

With the CakePHP Test Migrator, the schema of both default and test DB are handled exactly in the same way. You do not necessarily need a default DB. Tables are not dropped between test suites, which speeds up your tests. And migrations are part of the whole testing process: they get indirectly tested.

### Setting

[](#setting)

The package proposes a tool to run your [migrations](https://book.cakephp.org/migrations/3/en/index.html) once prior to the tests. In order to do so, you may place the following in your `tests/bootstrap.php`:

```
\CakephpTestMigrator\Migrator::migrate();
```

This command will ensure that your migrations are well run and keeps the test DB(s) up to date. Since tables are truncated but never dropped by the present package's fixture manager, migrations will be run strictly when needed, namely only after a new migration was created by the developer.

The `Migrator`approach presents the following advantages:

- it improves the speed of the test suites by avoiding the creation and dropping of tables between each test case classes,
- it eases the maintenance of your tests, since regular and test DBs are managed the same way,
- it indirectly tests your migrations.

You may pass `true` as the second argument for a verbose output on the console.

### Options

[](#options)

nametypedefaultdescriptionverbose*bool*`false`Print info about migrations donetruncate*bool*`true`Truncate all tables after migrations are done. You can call `truncate()` manuallyYou can pass a boolean as options, it will be used as `verbose`

```
\CakephpTestMigrator\Migrator::migrate([], true);
// is the same as
\CakephpTestMigrator\Migrator::migrate([], ['verbose' => true]);
```

### Multiple migrations settings

[](#multiple-migrations-settings)

You can pass the various migrations directly in the Migrator instantiation:

```
\CakephpTestMigrator\Migrator::migrate([
    ['connection' => 'test', 'source' => 'TestFolder'],
    ['plugin' => 'FooPlugin', 'connection' => 'FooConnection'],
    ['source' => 'BarFolder'],
    ...
 ], ['verbose' => true]);
```

You can also pass the various migrations directly in your Datasource configuration, under the key `migrations`:

```
// In config/app.php
'test' => [
    'className' => Connection::class,
    'driver' => Mysql::class,
    'persistent' => false,
    'timezone' => 'UTC',
    'flags' => [],
    'cacheMetadata' => true,
    'quoteIdentifiers' => false,
    'log' => false,
    'migrations' => [
        ['plugin' => 'FooPlugin'],
        ['source' => 'BarFolder'],
    ],
],
```

You can set `migrations` simply to `true` if you which to use the default migration settings.

### Migrations status

[](#migrations-status)

Information on a connection's migration status will be obtained as follows:

```
$migrator = Migrator::migrate();
$connectionsWithModifiedStatus = $migrator->getConnectionsWithModifiedStatus();
```

the method `getConnectionsWithModifiedStatus` returning a list of the connections with down migrations prior to running the migrations.

### Data truncation

[](#data-truncation)

Use **truncate** option to truncate (or not) after migrations are done. This is useful if you need to do other tasks in the test suite bootstrap

```
$migrator = Migrator::migrate([], ['truncate' => false]);
// do something with the migrated database (bake fixtures, etc)
$migrator->truncate();
```

### What happens if I switch branches?

[](#what-happens-if-i-switch-branches)

If you ever switched to a branch with nonexistent up migrations, you've moved to a branch in a past state. The `Migrator` will automatically drop the tables where needed, and re-run the migrations. Switching branches therefore does not require any intervention on your side.

### What if I do not use migrations?

[](#what-if-i-do-not-use-migrations)

The `Migrator::dump()` will help you import any schema from one or several sql file. Run for example:

```
Migrator::dump('test', 'path/to/file.sql')
```

or with multiples files

```
Migrator::dump('test', [
    'path1/to/file1.sql',
    'path2/to/file2.sql',
])
```

or for a verbose output

```
Migrator::dump('test', 'path/to/file.sql', true)
```

The first argument is the name of the connection, the second the file(s) to dump, the third the verbosity (boolean).

This method will however drop the schema prior to recreating it, which presents a significant loss of performance in comparison to the migration-based solution.

### Trouble shooting

[](#trouble-shooting)

It might be required, right after you installed or updated the plugin, to drop and recreate your test database. If the problem persists, feel free to open an issue.

Authors
-------

[](#authors)

- Juan Pablo Ramirez
- Nicolas Masson

Support
-------

[](#support)

Contact us at  for professional assistance.

You like our work? [![ko-fi](https://camo.githubusercontent.com/1fedf764fa06114b797ee53e7506df10880abed6766f854202d758df1707969d/68747470733a2f2f7777772e6b6f2d66692e636f6d2f696d672f676974687562627574746f6e5f736d2e737667)](https://ko-fi.com/L3L52P9JA)

License
-------

[](#license)

The CakephpTestMigrator plugin is offered under an [MIT license](https://opensource.org/licenses/mit-license.php).

Copyright 2020 Juan Pablo Ramirez and Nicolas Masson

Licensed under The MIT License Redistributions of files must retain the above copyright notice.

###  Health Score

39

—

LowBetter than 86% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity42

Moderate usage in the ecosystem

Community14

Small or concentrated contributor base

Maturity64

Established project with proven stability

 Bus Factor1

Top contributor holds 97.4% 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 ~20 days

Recently: every ~30 days

Total

18

Last Release

1702d ago

Major Versions

v1.1.1 → v2.1.12020-12-01

v1.1.3 → v2.1.32021-03-12

v1.2 → v2.32021-05-24

v1.3 → v2.42021-07-26

v1.5 → v2.52021-09-19

### Community

Maintainers

![](https://www.gravatar.com/avatar/84e140c6ff1a150dcd07a173e442d4e15b2acb44a091249046fb448fabf04b0e?d=identicon)[pabloelcolombiano](/maintainers/pabloelcolombiano)

---

Top Contributors

[![pabloelcolombiano](https://avatars.githubusercontent.com/u/23249541?v=4)](https://github.com/pabloelcolombiano "pabloelcolombiano (37 commits)")[![LordSimal](https://avatars.githubusercontent.com/u/9105243?v=4)](https://github.com/LordSimal "LordSimal (1 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/vierge-noire-cakephp-test-migrator/health.svg)

```
[![Health](https://phpackages.com/badges/vierge-noire-cakephp-test-migrator/health.svg)](https://phpackages.com/packages/vierge-noire-cakephp-test-migrator)
```

###  Alternatives

[phpspec/prophecy

Highly opinionated mocking framework for PHP 5.3+

8.5k551.7M682](/packages/phpspec-prophecy)[brianium/paratest

Parallel testing for PHP

2.5k118.8M754](/packages/brianium-paratest)[instaclick/php-webdriver

PHP WebDriver for Selenium 2

43661.8M22](/packages/instaclick-php-webdriver)[spatie/phpunit-snapshot-assertions

Snapshot testing with PHPUnit

69617.9M510](/packages/spatie-phpunit-snapshot-assertions)[szepeviktor/phpstan-wordpress

WordPress extensions for PHPStan

3287.8M898](/packages/szepeviktor-phpstan-wordpress)[dms/phpunit-arraysubset-asserts

This package provides ArraySubset and related asserts once deprecated in PHPUnit 8

14327.7M294](/packages/dms-phpunit-arraysubset-asserts)

PHPackages © 2026

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