fr3nch13/cakephp-pta
Composer 安装命令:
composer require fr3nch13/cakephp-pta
包简介
A CakePHP Plugin to emulate a generic App when testing Plugins.
README 文档
README
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
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
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
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
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/.envortests/.env.test - At:
config/.envorconfig/.env.test
See the file 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.
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.
You can also define your migrations in your bootstrap.php file. This uses the Migrations\TestSuite\Migrator tool from cakephp/migrations.
The migrations get ran in the 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
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
# 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
You can also define which middlewhere you would like to include.
These get included in 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:
#tests/bootstrap.php <?php declare(strict_types=1); /** * Test suite bootstrap. * * These are the specific settings for this plugin. * This uses fr3nch13/cakephp-pta to provide a generic application for testing. * Setting passed to cakephp-pta's bootstrap and application are defined here. */ use Cake\Core\Configure; // Configure your stuff here for the plugin_bootstrap.php below. define('TESTS', __DIR__ . DS); $dotenv = new \Symfony\Component\Dotenv\Dotenv(); $dotenv->load(TESTS . '.env'); Configure::write('Tests.DbConfig', [ 'className' => 'Cake\Database\Connection', 'driver' => 'Cake\Database\Driver\Mysql', 'persistent' => false, 'host' => env('CI_HOST', null), 'username' => env('CI_USERNAME', null), 'password' => env('CI_PASSWORD', null), 'database' => env('CI_DATABASE', null), 'encoding' => 'utf8', 'timezone' => 'UTC', 'flags' => [], 'cacheMetadata' => true, 'log' => false, 'quoteIdentifiers' => true, 'url' => env('DATABASE_URL', null), ]); Configure::write('Tests.Plugins', [ 'Namespace/PluginName', ]); Configure::write('Tests.Migrations', [ ['plugin' => 'Namespace/PluginName'], ]); Configure::write('Tests.Helpers', [ 'HelperName' => ['className' => 'Namespace/PluginName.HelperName'], ]); ////// Ensure we can setup an environment for the Test Application instance. $root = dirname(__DIR__); chdir($root); require_once $root . '/vendor/fr3nch13/cakephp-pta/tests/plugin_bootstrap.php';
Version compatibility
The major versions are locked to the major versions of CakePHP.
- PTA 1.x is locked to CakePHP ^3.8
- PTA 2.x is locked to CakePHP ^4.0 and requires php 7.3 or higher.
fr3nch13/cakephp-pta 适用场景与选型建议
fr3nch13/cakephp-pta 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 9.57k 次下载、GitHub Stars 达 2, 最近一次更新时间为 2019 年 11 月 22 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「plugin」 「cakephp」 「app」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 fr3nch13/cakephp-pta 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 fr3nch13/cakephp-pta 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 fr3nch13/cakephp-pta 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
CakePHP 4.x AdminLTE Theme.
Make your bundle an application
Email Toolkit Plugin for CakePHP
Rhino, a CMS and Application-Framework plugin for CakePHP
A CakePHP plugin for sending mail via SparkPost's REST API
A CakePHP behavior to validate foreign keys
统计信息
- 总下载量: 9.57k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 2
- 点击次数: 6
- 依赖项目数: 3
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2019-11-22