rask/wp-test-framework
Composer 安装命令:
composer require --dev rask/wp-test-framework
包简介
Extracted library from WordPress PHPUnit framework to aid in integration testing of plugins and themes
关键字:
README 文档
README
Extracted and librarized version of WordPress core's PHPUnit test framework to help with writing integration tests in WordPress plugins and themes.
The test framework is fetched from https://develop.svn.wordpress.org/trunk/tests/phpunit/ and is stored in src/phpunit (with minor changes to make it work better as a Composer package).
The sources are updated when needed, so there may be minor differences between the core framework and this extracted library version. Let the maintainers know if there are bigger changes which need to be merged here.
Installation
This library should be installed as a Composer dependency inside your plugin or theme:
$ composer require --dev rask/wp-test-framework
WordPress testing installation setup
You need to have a WordPress instance downloaded locally into a directory where your user account can load and execute PHP code from:
$ cd /home/you/wordpress
$ wp-cli core download
Next, you do not need to install WP in there but instead you need a wp-tests-config.php file to be available. It is similar to a regular wp-config.php but is solely for testing purposes.
You can find an example configuration at https://develop.svn.wordpress.org/trunk/wp-tests-config-sample.php. Copy the contents into the WordPress root
directory (ABSPATH) and set up the configuration for your system (databases, etc.).
Your plugin/theme can (and probably should) live outside the WordPress testing installation.
Setting up PHPUnit for your plugin/theme
Inside your plugin/theme directory you need to setup PHPUnit. Any regular-ish phpunit.xml configuration should work. In your PHPUnit bootstrap file you should load the WordPress test framework as such:
<?php
require_once './vendor/autoload.php';
\rask\WpTestFramework\Framework::load();
Then you should load your plugin or theme. In the same bootstrap file you can do the following:
<?php
require_once './vendor/autoload.php';
\rask\WpTestFramework\Framework::load();
// Load your plugin
require_once dirname(__DIR__) . '/my-plugin.php';
// You can also add WP configuration here if you need to
Now your plugin tests are bootstrapped to use the test framework and your test cases can now act as integration tests that use the whole WordPress stack. In other words you can run tests just like WordPress core tests are run!
Running your tests
You need to define an environment variable that contains a filesystem path (absolute or relative) to the WordPress testing installation you created earlier. The environment variable name is
WP_TESTS_INSTALLATION
You can use the environment variable with PHPUnit as follows:
$ WP_TESTS_INSTALLATION=/home/you/wordpress phpunit
Now you should see the WordPress get loaded and installed and you can start writing tests against the WordPress stack.
Contributing
The upstream test framework might need mirroring from time to time so feel free to ping the maintainers in case a refresh is needed.
Submitting code is OK as long as it fits the purpose of this library and works. Documentation is also very welcome.
If something does not work as expected be sure to raise an issue.
Other notes
Thanks for the WordPress team for the test framework.
License
As the source framework and WordPress in general is GPLv2+, this library uses GPLv3+. See LICENSE.md.
rask/wp-test-framework 适用场景与选型建议
rask/wp-test-framework 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 3.33k 次下载、GitHub Stars 达 4, 最近一次更新时间为 2018 年 02 月 15 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「testing」 「phpunit」 「wordpress」 「tests」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 rask/wp-test-framework 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 rask/wp-test-framework 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 rask/wp-test-framework 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
HiDev plugin for PHPUnit
Testing Suite For Lumen like Laravel does.
A cli tool which generates unit tests.
The PHP SDK for Checkmango
PHPUnit DbUnit Native Array-based Fixtures
The testing extension of TYPO3voilà.
统计信息
- 总下载量: 3.33k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 4
- 点击次数: 14
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: GPL-3.0-or-later
- 更新时间: 2018-02-15