SuperAPI AI 工具集

wp-playground

测试与质量

查看项目

更新于 10-15 23:48

技能介绍

用途:无需完整环境即可启动一次性 WordPress,用于测试插件/主题、本地运行或迭代 Blueprint、生成可复现快照、切换 WP/PHP 版本复现问题、用 Xdebug 调试、无数据库运行 PHPUnit、对真实 WordPress 写 Playwright E2E 测试,以及通过 runCLI 在 CI 中自动化。

主要能力:CLI 提供 server、run-blueprint、build-snapshot 等;支持 --auto-mount 自动挂载并安装插件/主题,--mount 多挂载,--wp/--php 指定版本,--xdebug 调试,--port 端口。计划实例为临时性、基于 SQLite,不可指向生产数据。

必要用法:需 Node.js ≥ 20.18 与 npm/npx。快速启动:cd 插件或主题根目录后执行 npx @wp-playground/cli@latest server --auto-mount,默认 http://localhost:9400。运行 Blueprint:npx @wp-playground/cli@latest run-blueprint --blueprint=<file-or-url>。生成快照:npx @wp-playground/cli@latest build-snapshot --blueprint=<file> --outfile=./site.zip。浏览器方式可用 playground.wordpress.net 的 URL 片段或 blueprint-url 参数,以及 Blueprint Editor。

PHPUnit:npx @wp-playground/cli@latest php --auto-mount -- /wordpress/wp-content/plugins/MY_PLUGIN/vendor/bin/phpunit -c /wordpress/wp-content/plugins/MY_PLUGIN/phpunit.xml.dist,需项目通过 Composer 安装 PHPUnit。Playwright 可安装 @playwright/test 与 @wp-playground/cli,在测试中调用 runCLI 启动服务器。

限制与排查:Node 版本过低、挂载未生效、Blueprint 无法读取本地资源、端口冲突等各有对应参数;需要 PHP 扩展或原生数据库访问时 Playground 可能不适用,应回退到完整 WP 栈或 wp-env/Docker。更多细节参见上游文档。