Skip to content

Commit d24ce0c

Browse files
authored
Merge pull request #582 from wp-cli/copilot/create-behat-tests-doc
2 parents 26d6676 + 7afe7e2 commit d24ce0c

6 files changed

Lines changed: 540 additions & 11 deletions

File tree

bin/handbook-manifest.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,12 @@
1111
"markdown_source": "https:\/\/github.com\/wp-cli\/handbook\/blob\/main\/references\/behat-steps.md",
1212
"parent": "references"
1313
},
14+
"behat-tests": {
15+
"title": "Writing Behat Tests for WP-CLI",
16+
"slug": "behat-tests",
17+
"markdown_source": "https:\/\/github.com\/wp-cli\/handbook\/blob\/main\/guides\/behat-tests.md",
18+
"parent": "guides"
19+
},
1420
"bug-reports": {
1521
"title": "Bug Reports",
1622
"slug": "bug-reports",

contributions/pull-requests.md

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -118,9 +118,11 @@ To fix the errors and warnings that can be automatically fixed:
118118

119119
### Functional tests
120120

121-
WP-CLI uses [Behat](https://behat.org/) as its functional test suite. Stability between releases is an important contact WP-CLI makes with its users. Functional tests are different than unit tests in that they execute the entire WP-CLI command, and ensure they always work as expected.
121+
WP-CLI uses [Behat](https://behat.org/) for functional testing. Functional tests ensure commands work as expected by executing them end-to-end.
122122

123-
Every repository has a `features/` directory with one or more [YAML](https://yaml.org/)-formatted `*.feature` files. Here's an example of what you might see:
123+
For a comprehensive guide on writing and running Behat tests, see **[Writing Behat Tests](https://make.wordpress.org/cli/handbook/guides/behat-tests/)**.
124+
125+
Here's a quick example of what a Behat test looks like:
124126

125127
```yml
126128
Feature: Manage WordPress options
@@ -143,14 +145,6 @@ In this example:
143145
- `When` causes an event to occur.
144146
- `Then` asserts what's expected after the event is complete.
145147

146-
In a slightly more human-friendly form:
147-
148-
> I have a WordPress installation. When I run `wp option get home`, then the output from the command should be 'https://example.org'.
149-
150-
Essentially, WP-CLI's functional test suite lets you _describe how a command should work_, and then run that description as a functional test.
151-
152-
Notably, Behat is simply the framework for writing these tests. We've written our own custom `Given`, `When`, and `Then` step definitions ([example](https://github.com/wp-cli/wp-cli-tests/blob/560ed5ca2776b6b3b66c79a6e6dc62904ae20b3b/src/Context/GivenStepDefinitions.php#L105-L110), [example](https://github.com/wp-cli/wp-cli-tests/blob/560ed5ca2776b6b3b66c79a6e6dc62904ae20b3b/src/Context/WhenStepDefinitions.php#L34-L42)).
153-
154148
#### Creating a test database
155149

156150
Before running the functional tests, you'll need a MySQL (or MariaDB) user called `wp_cli_test` with the password `password1` that has full privileges on the MySQL database `wp_cli_test`.

guides.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
* **[Quick start](https://make.wordpress.org/cli/handbook/guides/quick-start/)** - Where to begin after you've installed WP-CLI for the first time.
55
* **[Running commands remotely](https://make.wordpress.org/cli/handbook/guides/running-commands-remotely/)** - Learn how to remotely control multiple servers at once.
66
* **[Commands cookbook](https://make.wordpress.org/cli/handbook/guides/commands-cookbook/)** - The full 101 how commands work, writing your own, and sharing them with the world.
7+
* **[Writing Behat Tests](https://make.wordpress.org/cli/handbook/guides/behat-tests/)** - How to write and run Behat tests for WP-CLI commands and packages.
78
* **[Common issues and their fixes](https://make.wordpress.org/cli/handbook/guides/common-issues/)** - In case of fire, break glass.
89
* **[External resources](https://make.wordpress.org/cli/handbook/guides/external-resources/)** - Blog posts, slides and videos from users.
910
* **[Force output to a specific locale](https://make.wordpress.org/cli/handbook/guides/force-output-specific-locale/)** - Localisation issue

0 commit comments

Comments
 (0)