title: "Behat 步骤" post_status: publish comment_status: open taxonomy: category: - wp-cli-handbook post_tag: - References - Repos - Data
Behat 步骤
WP-CLI 使用基于 Behat 的测试框架,并提供一组自定义步骤定义来编写功能测试。
Behat 步骤文档随每次版本发布从 WP-CLI 代码库生成。如需改进建议,请提交拉取请求。
Given
- Given an empty directory - 创建一个空目录。
- Given /^an? (empty|non-existent) ([^\s]+) directory$/ - 创建或删除一个特定目录。
- Given an empty cache - 清空 WP-CLI 缓存目录。
- Given /^an? ([^\s]+) (file|cache file):$/ - 使用给定内容创建一个文件。
- Given /^"([^"]+)" replaced with "([^"]+)" in the ([^\s]+) file$/ - 使用正则表达式在文件中搜索并替换字符串。
- Given /^that HTTP requests to (.*?) will respond with:$/ - 模拟对给定 URL 的 HTTP 请求。
- Given WP files - 下载 WordPress 文件但不安装。
- Given wp-config.php - 使用 `wp config create` 创建一个 wp-config.php 文件。
- Given a database - 创建一个空数据库。
- Given a WP install(ation) - 安装 WordPress。
- Given a WP install(ation) in :subdir - 在给定目录中安装 WordPress。
- Given a WP install(ation) with Composer - 使用 Composer 安装 WordPress。
- Given a WP install(ation) with Composer and a custom vendor directory :vendor_directory - 使用 Composer 和一个自定义的 vendor 目录安装 WordPress。
- Given /^a WP multisite (subdirectory|subdomain)?\s?(install|installation)$/ - 安装 WordPress 多站点。
- Given these installed and active plugins: - 安装并激活一个或多个插件。
- Given a custom wp-content directory - 配置自定义的 `wp-content` 目录。
- Given download: - 将多个文件下载到指定目标位置。
- Given /^save (STDOUT|STDERR) ([\'].+[^\'])?\s?as \{(\w+)\}$/ - 将 STDOUT 或 STDERR 的内容存储到变量中。
- Given /^a new Phar with (?:the same version|version "([^"]+)")$/ - 使用指定版本构建一个新的 WP-CLI Phar 文件。
- Given /^a downloaded Phar with (?:the same version|version "([^"]+)")$/ - 从 GitHub 下载指定版本的 WP-CLI Phar 文件。
- Given /^save the (.+) file ([\'].+[^\'])?as \{(\w+)\}$/ - 将指定文件的内容存储到变量中。
- Given a misconfigured WP_CONTENT_DIR constant directory - 修改 wp-config.php 文件,将 `WP_CONTENT_DIR` 设置为空字符串。
- Given a dependency on current wp-cli - 将 `wp-cli/wp-cli` 添加为 Composer 依赖项。
- Given a PHP built-in web server - 在当前目录启动 PHP 内置 Web 服务器。
- Given a PHP built-in web server to serve :subdir - 在指定子目录中启动 PHP 内置 Web 服务器。
When
- When /^I launch in the background `([^`]+)`$/ - 在后台启动给定的命令。
- When /^I (run|try) `([^`]+)`$/ - 运行或尝试给定的命令。
- When /^I (run|try) `([^`]+)` from '([^\s]+)'$/ - 在子目录中运行或尝试给定的命令。
- When /^I (run|try) the previous command again$/ - 再次运行或尝试上一个命令。
Then
- Then /^the return code should( not)? be (\d+)$/ - 期望上一个命令返回特定的退出码。
- Then /^(STDOUT|STDERR) should( strictly)? (be|contain|not contain):$/ - 检查 STDOUT 或 STDERR 的内容。
- Then /^(STDOUT|STDERR) should be a number$/ - 期望 STDOUT 或 STDERR 是数值。
- Then /^(STDOUT|STDERR) should not be a number$/ - 期望 STDOUT 或 STDERR 不是数值。
- Then /^STDOUT should be a table containing rows:$/ - 期望 STDOUT 是一个包含给定行的表格。
- Then /^STDOUT should end with a table containing rows:$/ - 期望 STDOUT 以一个包含给定行的表格结尾。
- Then /^STDOUT should be JSON containing:$/ - 期望 STDOUT 包含有效的 JSON 输出。
- Then /^STDOUT should be a JSON array containing:$/ - 期望 STDOUT 包含有效的 JSON 数组输出。
- Then /^STDOUT should be CSV containing:$/ - 期望 STDOUT 是包含特定值的 CSV。
- Then /^STDOUT should be YAML containing:$/ - 期望 STDOUT 是包含特定内容的 YAML。
- Then /^(STDOUT|STDERR) should be empty$/ - 期望 STDOUT 或 STDERR 为空。
- Then /^(STDOUT|STDERR) should not be empty$/ - 期望 STDOUT 或 STDERR 不为空。
- Then /^(STDOUT|STDERR) should be a version string (<|<=|>|>=|==|=|!=|<>) ([+\w.{}-]+)$/ - 期望 STDOUT 或 STDERR 是一个版本字符串,并与给定的版本进行比较。
- Then /^the (.+) (file|directory) should( strictly)? (exist|not exist|be:|contain:|not contain:)$/ - 期望某个文件或目录(不)存在或(不)包含特定内容。
- Then /^the contents of the (.+) file should( not)? match (((\/.+\/)|(#.+#))([a-z]+)?)$/ - 使用正则表达式匹配文件内容。
- Then /^(STDOUT|STDERR) should( not)? match (((\/.+\/)|(#.+#))([a-z]+)?)$/ - 使用正则表达式匹配 STDOUT 或 STDERR。
- Then /^an email should (be sent|not be sent)$/ - 期望发送(或不发送)一封电子邮件。
- Then the HTTP status code should be :code - 期望访问 `http://localhost:8080` 时的 HTTP 状态码。