ackintosh / wptestcase
此包已被弃用,不再维护。未建议替代包。
WordPress 测试工具。
dev-master
2013-07-27 13:29 UTC
Requires
- php: >=5.3.0
- phpunit/phpunit: 3.7.*
- symfony/yaml: ~2.0
This package is auto-updated.
Last update: 2022-04-16 04:48:27 UTC
README
#WPTestCase
WordPress 插件开发测试工具,具有 fixture 功能,基于 PHPUnit。
http://phpunit.de/manual/3.7/en/index.html
##安装 composer.json
{
"require": {
"ackintosh/wptestcase": "dev-master"
}
}
$ php composer.phar install
##用法
- 安装此工具。
$ cd wordpress/wp-content/plugins
$ php composer.phar install
- 设置测试用的表,更改前缀为 'wptest_'。
- 准备 YAML 编写的 fixture 文件。
post_fixture.yml
- post_title: Test post title 1 post_content: Test post content 1 post_status: publish - post_title: Test post title 2 post_content: Test post content 2 post_status: publish
可用参数与 'wp_insert_post' 函数相同。
- 编写测试代码。
class SamplePluginTest extends Ackintosh\WPTestCase { // The table prefix for testing can be changed. // protected $test_prefix = 'wptest_'; public function test_insert_post() { // Loading data. $this->setPostFixture(__DIR__ . '/post_fixture.yml'); // We can get the post data that inserted by the fixture function. $posts = get_posts(); // Can use all features in PHPUnit. $this->assertEquals($expect, $result); } }
- 运行测试。
$ vendor/bin/phpunit
##要求
- PHP 5.3 或更高版本