PHPackages                             fr3nch13/cakephp-pta - 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. fr3nch13/cakephp-pta

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

fr3nch13/cakephp-pta
====================

A CakePHP Plugin to emulate a generic App when testing Plugins.

2.4.4(1y ago)29.6k3MITPHPPHP ~7.4||~8.0CI failing

Since Nov 22Pushed 1y ago2 watchersCompare

[ Source](https://github.com/fr3nch13/cakephp-pta)[ Packagist](https://packagist.org/packages/fr3nch13/cakephp-pta)[ Docs](https://github.com/fr3nch13/cakephp-pta)[ RSS](/packages/fr3nch13-cakephp-pta/feed)WikiDiscussions main Synced 6d ago

READMEChangelog (10)Dependencies (15)Versions (34)Used By (3)

CakePHP Test App Plugin
=======================

[](#cakephp-test-app-plugin)

[![Coverage](https://camo.githubusercontent.com/22e1838f6110f53c6b851a95dc2627c84110952b3e4d48c3c1eb96c452effe30/68747470733a2f2f636f6465636f762e696f2f67682f6672336e636831332f63616b657068702d7074612f6272616e63682f6d61737465722f67726170682f62616467652e737667)](https://codecov.io/gh/fr3nch13/cakephp-pta)[![Total Downloads](https://camo.githubusercontent.com/c28ecd2812b0b698053b0537ac94e53f5fd7ba5b4281787ace851c60c98fe3e0/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6672336e636831332f63616b657068702d7074612e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/fr3nch13/cakephp-pta)[![Latest Stable Version](https://camo.githubusercontent.com/497929db3f1a25598097ee7cb91f691c84a0a4aa0056f42da72dc57eb5efee2d/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6672336e636831332f63616b657068702d7074612e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/fr3nch13/cakephp-pta)[![GitHub release](https://camo.githubusercontent.com/9d4af7214bc1166c32b0e53cd9141b7461b0f822dbe7bd46cea4a59527dc3af4/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f72656c656173652f6672336e636831332f63616b657068702d7074612e737667)](https://GitHub.com/fr3nch13/cakephp-pta/releases/)

This CakePHP Plugin is used to emulate a generic App when testing your CakePHP Plugins.

I am using the cakephp/app as that is the up-to-date skeleton app, and many of my plugins share many of the same things. This plugin is meant to keep them dry.

As an example: the `test/bootstrap.php` file. When I need to change/add something to that, I have to do it in over 10 CakePHP plugins. It's easier to just put the common stuff in here, and include the `tests/plugin_bootstrap.php` from here. Similar to how baked plugins do with the core `test/bootstrap.php`.

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

[](#installation)

To use this plugin's bootstrap for other plugins, add the below lines to your `tests/bootstrap.php` near the bottom.

```
// define any constants you need to overwrite above these lines.
$root = dirname(__DIR__);
chdir($root);
require_once $root . '/vendor/fr3nch13/cakephp-pta/tests/plugin_bootstrap.php';
```

Usage
-----

[](#usage)

You no longer need to copy the `tests/test_app` from this project to yours. Instead there are other ways to inject you settings/plugin/etc into this plugin's test application:

### Adding your plugin

[](#adding-your-plugin)

To add your plugin to the test application, you need to update your `test/bootstrap.php` like so:

```
# test/bootstrap.php

// ... code ...

Configure::write('Tests.Plugins', [
    'Namespace/PluginName', // the name of your plugin
    'Fr3nch13/Jira', // Using one of my plusins as an example
]);

// plugins just for the command line
Configure::write('Tests.PluginsCli', [
    'Namespace/PluginName', // the name of your plugin
]);

// ... code ...

require_once $root . '/vendor/fr3nch13/cakephp-pta/tests/plugin_bootstrap.php';
```

### Adding your variables from a .env

[](#adding-your-variables-from-a-env)

In this plugin's `tests/plugin_bootstrap.php` file, it will look for your `.env` or `.env.test` files in 2 places within your plugin:

- At: `tests/.env` or `tests/.env.test`
- At: `config/.env` or `config/.env.test`

See the file [`tests/.env.example`](tests/.env.example) as an example.

If you need to import your variables before including the `plugin_bootstrap.php` like above, then you can do this:

```
# test/bootstrap.php

// ... code ...

$dotenv = new \Symfony\Component\Dotenv\Dotenv();
$dotenv->load(TESTS . '.env');

// ... code ...

require_once $root . '/vendor/fr3nch13/cakephp-pta/tests/plugin_bootstrap.php';
```

### Database settings.

[](#database-settings)

This plugin uses sqlite in memory be default, but if you want to define your own database setting you can do so in your `tests/bootstrap.php` file, before including the `plugin_bootstrap.php` file as the database connection is setup in the `plugin_bootstrap.php` file.

```
# test/bootstrap.php

// ... code ...

Configure::write('Tests.DbConfig', [
    'className' => 'Cake\Database\Connection',
    'driver' => 'Cake\Database\Driver\Mysql',
    'persistent' => false,
    'host' => 'database_hostname',
    'port' => 'non_standard_port_number',
    'username' => 'database_username',
    'password' => 'database_password',
    'database' => 'database_schema',
    'encoding' => 'utf8',
    'timezone' => 'UTC',
    'flags' => [],
    'cacheMetadata' => true,
    'log' => false,
    'quoteIdentifiers' => true,
]);

// ... code ...

require_once $root . '/vendor/fr3nch13/cakephp-pta/tests/plugin_bootstrap.php';
```

### Adding Migrations.

[](#adding-migrations)

You can also define your migrations in your `bootstrap.php` file. This uses the `Migrations\TestSuite\Migrator` tool from [`cakephp/migrations`](https://github.com/cakephp/migrations). The migrations get ran in the [`tests/plugin_bootstrap.php`](tests/plugin_bootstrap.php) file near the bottom.

```
# test/bootstrap.php

// ... code ...

Configure::write('Tests.Migrations', [
    ['plugin' => 'Namespace/PluginName'],
    // just using some of my plugins as an example
    ['plugin' => 'Fr3nch13/Jira'],
    ['plugin' => 'Fr3nch13/Utilities'],
    ['plugin' => 'Fr3nch13/Excel'],
]);

// ... code ...

require_once $root . '/vendor/fr3nch13/cakephp-pta/tests/plugin_bootstrap.php';
```

### Adding Html Helpers

[](#adding-html-helpers)

If you have View/Helpers that you would also like to include, you can define them in your `bootstrap.php` file as well. These get included in [`tests/test_app/src/View/AppView.php`](tests/test_app/src/View/AppView.php)

```
# test/bootstrap.php

// ... code ...

Configure::write('Tests.Helpers', [
    'HelperName' => ['className' => 'Namespace/PluginName.HelperName'],
    // loads the jira helper as an example.
    'Jira' => ['className' => 'Fr3nch13/Jira.Jira'],
]);

// ... code ...

require_once $root . '/vendor/fr3nch13/cakephp-pta/tests/plugin_bootstrap.php';
```

### Adding Middleware

[](#adding-middleware)

You can also define which middlewhere you would like to include. These get included in [`tests/test_app/src/Application.php`](tests/test_app/src/Application.php) in the `middleware()` method.

```
# test/bootstrap.php

// ... code ...

Configure::write('Tests.Middleware', [
    'MiddlewhereName' => [
        'config_key' => 'config_value',
    ],
]);

// ... code ...

require_once $root . '/vendor/fr3nch13/cakephp-pta/tests/plugin_bootstrap.php';
```

### Full `tests/bootstrap.php` example for your plugin:

[](#full-testsbootstrapphp-example-for-your-plugin)

```
#tests/bootstrap.php
