wordpress-testing-%26-qa by courtneyr-dev/wp-dev-prompts
npx skills add https://github.com/courtneyr-dev/wp-dev-prompts --skill 'WordPress Testing & QA'涵盖单元测试、集成测试、端到端测试、静态分析以及持续集成/持续交付管道的 WordPress 插件与主题测试策略。
在不加载 WordPress 的情况下测试独立的类/函数。执行速度快,无需数据库。
use WP_Mock\Tools\TestCase;
class MyPluginTest extends TestCase {
public function test_format_output() {
WP_Mock::userFunction( 'esc_html' )
->once()
->with( 'test' )
->andReturn( 'test' );
$result = my_format_function( 'test' );
$this->assertEquals( 'test', $result );
}
}
针对实际的 WordPress 环境及数据库进行测试。速度较慢但更全面。
# Install test suite
composer require --dev phpunit/phpunit yoast/phpunit-polyfills
bash bin/install-wp-tests.sh wordpress_test root password localhost latest
class MyPlugin_Integration_Test extends WP_UnitTestCase {
public function test_post_creation() {
$post_id = $this->factory->post->create( [
'post_title' => 'Test Post',
] );
$this->assertGreaterThan( 0, $post_id );
}
public function test_rest_endpoint() {
$request = new WP_REST_Request( 'GET', '/myplugin/v1/items' );
$response = rest_get_server()->dispatch( $request );
$this->assertEquals( 200, $response->get_status() );
}
}
广告位招租
在这里展示您的产品或服务
触达数万 AI 开发者,精准高效
import { test, expect } from '@wordpress/e2e-test-utils-playwright';
test( 'block renders in editor', async ( { admin, editor } ) => {
await admin.createNewPost();
await editor.insertBlock( { name: 'my-plugin/my-block' } );
await expect( editor.canvas.locator( '.wp-block-my-block' ) ).toBeVisible();
} );
<?xml version="1.0"?>
<phpunit
bootstrap="tests/bootstrap.php"
backupGlobals="false"
colors="true"
>
<testsuites>
<testsuite name="unit">
<directory suffix="Test.php">tests/unit</directory>
</testsuite>
<testsuite name="integration">
<directory suffix="Test.php">tests/integration</directory>
</testsuite>
</testsuites>
</phpunit>
{
"require-dev": {
"wp-coding-standards/wpcs": "^3.0",
"phpcompatibility/phpcompatibility-wp": "*",
"dealerdirect/phpcodesniffer-composer-installer": "^1.0"
}
}
<!-- phpcs.xml -->
<ruleset name="My Plugin">
<rule ref="WordPress"/>
<rule ref="WordPress-Extra"/>
<rule ref="WordPress-Docs"/>
<rule ref="PHPCompatibilityWP"/>
<config name="testVersion" value="8.2-"/>
<config name="minimum_wp_version" value="6.9"/>
<file>./includes</file>
<file>./my-plugin.php</file>
</ruleset>
# phpstan.neon
includes:
- vendor/szepeviktor/phpstan-wordpress/extension.neon
parameters:
level: 6
paths:
- includes/
- my-plugin.php
# .github/workflows/ci.yml
jobs:
test:
strategy:
matrix:
php: ['8.2', '8.3', '8.4']
wp: ['6.7', '6.8', '6.9', 'trunk']
steps:
- uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
- run: composer install --no-progress
- run: bash bin/install-wp-tests.sh wordpress_test root '' 127.0.0.1 ${{ matrix.wp }}
- run: vendor/bin/phpunit
lint:
steps:
- run: vendor/bin/phpcs
- run: vendor/bin/phpstan analyse
每周安装量
–
代码仓库
GitHub 星标数
6
首次出现
–
Testing strategies for WordPress plugins and themes covering unit tests, integration tests, E2E tests, static analysis, and CI/CD pipelines.
Test isolated classes/functions without WordPress loaded. Fast execution, no database.
use WP_Mock\Tools\TestCase;
class MyPluginTest extends TestCase {
public function test_format_output() {
WP_Mock::userFunction( 'esc_html' )
->once()
->with( 'test' )
->andReturn( 'test' );
$result = my_format_function( 'test' );
$this->assertEquals( 'test', $result );
}
}
Test against actual WordPress with database. Slower but comprehensive.
# Install test suite
composer require --dev phpunit/phpunit yoast/phpunit-polyfills
bash bin/install-wp-tests.sh wordpress_test root password localhost latest
class MyPlugin_Integration_Test extends WP_UnitTestCase {
public function test_post_creation() {
$post_id = $this->factory->post->create( [
'post_title' => 'Test Post',
] );
$this->assertGreaterThan( 0, $post_id );
}
public function test_rest_endpoint() {
$request = new WP_REST_Request( 'GET', '/myplugin/v1/items' );
$response = rest_get_server()->dispatch( $request );
$this->assertEquals( 200, $response->get_status() );
}
}
import { test, expect } from '@wordpress/e2e-test-utils-playwright';
test( 'block renders in editor', async ( { admin, editor } ) => {
await admin.createNewPost();
await editor.insertBlock( { name: 'my-plugin/my-block' } );
await expect( editor.canvas.locator( '.wp-block-my-block' ) ).toBeVisible();
} );
<?xml version="1.0"?>
<phpunit
bootstrap="tests/bootstrap.php"
backupGlobals="false"
colors="true"
>
<testsuites>
<testsuite name="unit">
<directory suffix="Test.php">tests/unit</directory>
</testsuite>
<testsuite name="integration">
<directory suffix="Test.php">tests/integration</directory>
</testsuite>
</testsuites>
</phpunit>
{
"require-dev": {
"wp-coding-standards/wpcs": "^3.0",
"phpcompatibility/phpcompatibility-wp": "*",
"dealerdirect/phpcodesniffer-composer-installer": "^1.0"
}
}
<!-- phpcs.xml -->
<ruleset name="My Plugin">
<rule ref="WordPress"/>
<rule ref="WordPress-Extra"/>
<rule ref="WordPress-Docs"/>
<rule ref="PHPCompatibilityWP"/>
<config name="testVersion" value="8.2-"/>
<config name="minimum_wp_version" value="6.9"/>
<file>./includes</file>
<file>./my-plugin.php</file>
</ruleset>
# phpstan.neon
includes:
- vendor/szepeviktor/phpstan-wordpress/extension.neon
parameters:
level: 6
paths:
- includes/
- my-plugin.php
# .github/workflows/ci.yml
jobs:
test:
strategy:
matrix:
php: ['8.2', '8.3', '8.4']
wp: ['6.7', '6.8', '6.9', 'trunk']
steps:
- uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
- run: composer install --no-progress
- run: bash bin/install-wp-tests.sh wordpress_test root '' 127.0.0.1 ${{ matrix.wp }}
- run: vendor/bin/phpunit
lint:
steps:
- run: vendor/bin/phpcs
- run: vendor/bin/phpstan analyse
Weekly Installs
–
Repository
GitHub Stars
6
First Seen
–
Spring Boot工程师技能指南:微服务架构、安全加固与云原生开发实战
4,200 周安装
Docnify自动化:通过Rube MCP和Composio工具包实现文档操作自动化
1 周安装
Docmosis自动化集成指南:通过Rube MCP与Composio实现文档生成自动化
1 周安装
Dictionary API自动化教程:通过Rube MCP和Composio实现词典API操作自动化
1 周安装
detrack-automation:自动化追踪技能,集成Claude AI提升开发效率
1 周安装
Demio自动化工具包:通过Rube MCP和Composio实现Demio操作自动化
1 周安装
Deel自动化工具:通过Rube MCP与Composio实现HR与薪资操作自动化
1 周安装