2017 © Pedro Peláez
 

cakephp-plugin cakephp-test-datasource-switcher

TestDatasourceSwitcher plugin for CakePHP 3

image

nojimage/cakephp-test-datasource-switcher

TestDatasourceSwitcher plugin for CakePHP 3

  • Wednesday, October 25, 2017
  • by nojimage
  • Repository
  • 1 Watchers
  • 0 Stars
  • 282 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 2 Versions
  • 34 % Grown

The README.md

TestDatasourceSwitcher plugin for CakePHP 3.x

Software License Build Status Codecov Latest Stable Version , (*1)

Switching datasouce connections to test, when the request have a specific Cookie., (*2)

Installation

You can install this plugin into your CakePHP application using composer., (*3)

The recommended way to install composer packages is:, (*4)

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

CakePHP >= 3.3 in src/Application.php, (*5)

    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 <= 3.2 in config/bootstrap.php, (*6)

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

Usage

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

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

This software is released under the MIT License., (*8)

Copyright (c) 2015 ELASTIC Consultants Inc. https://elasticconsultants.com/, (*9)

http://opensource.org/licenses/mit-license.php, (*10)

The Versions

25/10 2017

dev-master

9999999-dev

TestDatasourceSwitcher plugin for CakePHP 3

  Sources   Download

MIT

The Requires

 

The Development Requires

25/10 2017

v1.0.0

1.0.0.0

TestDatasourceSwitcher plugin for CakePHP 3

  Sources   Download

MIT

The Requires

 

The Development Requires