PHPackages                             nojimage/cakephp-test-datasource-switcher - 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. nojimage/cakephp-test-datasource-switcher

ActiveCakephp-plugin[Testing &amp; Quality](/categories/testing)

nojimage/cakephp-test-datasource-switcher
=========================================

TestDatasourceSwitcher plugin for CakePHP 3

v1.0.1(7y ago)15.0kMITPHPPHP &gt;=5.4.16

Since Oct 25Pushed 6y ago1 watchersCompare

[ Source](https://github.com/nojimage/cakephp-TestDatasourceSwitcher)[ Packagist](https://packagist.org/packages/nojimage/cakephp-test-datasource-switcher)[ RSS](/packages/nojimage-cakephp-test-datasource-switcher/feed)WikiDiscussions master Synced 1w ago

READMEChangelog (1)Dependencies (3)Versions (4)Used By (0)

TestDatasourceSwitcher plugin for CakePHP 3.x
=============================================

[](#testdatasourceswitcher-plugin-for-cakephp-3x)

 [ ![Software License](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265) ](LICENSE.txt) [ ![Build Status](https://camo.githubusercontent.com/c589ab0067aaa3797626db2cb39f92aa93caf26a21d2d47499cf9bd6ac01f8f5/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f6e6f6a696d6167652f63616b657068702d5465737444617461736f7572636553776974636865722f6d61737465722e7376673f7374796c653d666c61742d737175617265) ](https://travis-ci.org/nojimage/cakephp-TestDatasourceSwitcher) [ ![Codecov](https://camo.githubusercontent.com/f5d6774fb62d32d7df5854dedba8142b621785b4da1cd2d7c7d66ecf9f16fd2d/68747470733a2f2f696d672e736869656c64732e696f2f636f6465636f762f632f6769746875622f6e6f6a696d6167652f63616b657068702d5465737444617461736f7572636553776974636865722e7376673f7374796c653d666c61742d737175617265) ](https://codecov.io/gh/nojimage/cakephp-TestDatasourceSwitcher) [ ![Latest Stable Version](https://camo.githubusercontent.com/a1b589db291c16b1fd90ee696d748411aef662ddb27cda7badefc2a3b69b9c3e/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6e6f6a696d6167652f63616b657068702d746573742d64617461736f757263652d73776974636865722e7376673f7374796c653d666c61742d737175617265) ](https://packagist.org/packages/nojimage/cakephp-test-datasource-switcher)

Switching datasouce connections to `test`, when the request have a specific Cookie.

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

[](#installation)

You can install this plugin into your CakePHP application using [composer](http://getcomposer.org).

The recommended way to install composer packages is:

```
composer require --dev nojimage/cakephp-test-datasource-switcher

```

CakePHP &gt;= 3.3 in `src/Application.php`

```
    public function middleware($middlewareQueue)
    {
        $middlewareQueue
            // Catch any exceptions in the lower layers,
            // and make an error page/response
            ->add(ErrorHandlerMiddleware::class)

            // vvv ADD THIS LINE vvv
            ->add(new \TestDatasourceSwitcher\Middleware\DatasourceSwitchMiddleware())

            // Handle plugin/theme assets like CakePHP normally does.
            ->add(AssetMiddleware::class)

            // Add routing middleware.
            ->add(new RoutingMiddleware($this));

        return $middlewareQueue;
    }

```

CakePHP &lt;= 3.2 in `config/bootstrap.php`

```
if (Configure::read('debug')) {
    \Cake\Routing\DispatcherFactory::add(new \TestDatasourceSwitcher\Routing\Filter\Switcher(['priority' => 1]));
}

```

Usage
-----

[](#usage)

eg. For the Codeception functional testcases.
(This sample is always connect to 'test' datasouces.

```
class FunctionalHelper extends \Codeception\Module
{

    public function _before(TestCase $test)
    {
        $driver = $this->getModule('WebDriver');
        /* @var $dirver WebDriver */
        $driver->amOnPage('/');
        $driver->setCookie('__cakephp_test_connection', '1');
    }

(...snip...)

```

License
-------

[](#license)

This software is released under the MIT License.

Copyright (c) 2015 ELASTIC Consultants Inc.

###  Health Score

30

—

LowBetter than 62% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity20

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity60

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

Total

2

Last Release

2608d ago

### Community

Maintainers

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

---

Top Contributors

[![nojimage](https://avatars.githubusercontent.com/u/100564?v=4)](https://github.com/nojimage "nojimage (22 commits)")

---

Tags

cakephpswitching-datasouce-connections

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/nojimage-cakephp-test-datasource-switcher/health.svg)

```
[![Health](https://phpackages.com/badges/nojimage-cakephp-test-datasource-switcher/health.svg)](https://phpackages.com/packages/nojimage-cakephp-test-datasource-switcher)
```

###  Alternatives

[cakephp/bake

Bake plugin for CakePHP

11211.7M189](/packages/cakephp-bake)[dereuromark/cakephp-tools

A CakePHP plugin containing lots of useful and reusable tools

336972.2k49](/packages/dereuromark-cakephp-tools)[dereuromark/cakephp-queue

The Queue plugin for CakePHP provides deferred task execution.

309914.0k25](/packages/dereuromark-cakephp-queue)[dereuromark/cakephp-ide-helper

CakePHP IdeHelper Plugin to improve auto-completion

1902.3M39](/packages/dereuromark-cakephp-ide-helper)[dereuromark/cakephp-tinyauth

A CakePHP plugin to handle user authentication and authorization the easy way.

131237.3k12](/packages/dereuromark-cakephp-tinyauth)[dereuromark/cakephp-setup

A CakePHP plugin containing lots of useful management tools

35184.7k2](/packages/dereuromark-cakephp-setup)

PHPackages © 2026

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