Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: update PHPUnit testing README.md with corrections #62065 #7389

Open
wants to merge 1 commit into
base: trunk
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions tests/phpunit/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# PHPUnit Tests

PHPUnit is the official testing framework chosen by the core team to test our PHP code.

This documentation will assume you have a local development environment of your own choosing. For other testing workflows, such as Docker, see the [PHP: PHP Unit](https://make.wordpress.org/core/handbook/testing/automated-testing/phpunit/) handbook page.

## Setup

1. Check out the wordpress-develop repository

git clone git://develop.git.wordpress.org/ wordpress-develop
Comment on lines +9 to +11

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
1. Check out the wordpress-develop repository
git clone git://develop.git.wordpress.org/ wordpress-develop
1. Check out the [`wordpress-develop` repository](https://github.com/WordPress/wordpress-develop):
git clone git@github.com:WordPress/wordpress-develop.git

I wonder if this should instead refer to the Github repo, as PRs there are the typical way to contribute patches and tests.

cd wordpress-develop

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
cd wordpress-develop
cd wordpress-develop

For this and the git clone line above it, please wrap with three backticks instead of spaces (for example).


2. Run `composer update --with-all-dependencies`

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
2. Run `composer update --with-all-dependencies`
2. Run `composer update --with-all-dependencies`.

Nit.

3. Create a clean MySQL database and user. **DO NOT USE AN EXISTING DATABASE** or you will lose data, guaranteed.
4. Copy `wp-tests-config-sample.php` to `wp-tests-config.php`, edit it to include your testing database credentials.
5. Run the tests from the repository root:
- To execute a particular test:

$ vendor/bin/phpunit tests/phpunit/tests/test_case.php
- To execute all tests:

$ vendor/bin/phpunit
Comment on lines +18 to +23

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
- To execute a particular test:
$ vendor/bin/phpunit tests/phpunit/tests/test_case.php
- To execute all tests:
$ vendor/bin/phpunit
- To execute a particular test:
vendor/bin/phpunit tests/phpunit/tests/test_case.php
- To execute all tests:
vendor/bin/phpunit

Suggest dropping the terminal prompt character. For these commands, please substitute the block formatting spaces by wrapping with three backticks for consistency with other docs (I'm unsure how to add these within a backticked suggestion block 😅).


## Notes:

Test cases live in the `tests` subdirectory. All files in that directory will be included by default. Extend the `WP_UnitTestCase` class to ensure your test is run.

`phpunit` will initialize and install a (more or less) complete running copy of WordPress each time it is run. This makes it possible to run functional interface and module tests against a fully working database and codebase, as opposed to pure unit tests with mock objects and stubs. Pure unit tests may be used also, of course.

Changes to the test database will be rolled back as tests are finished, to ensure a clean start next time the tests are run.

`phpunit` is intended to run at the command line, not via a web server.
23 changes: 0 additions & 23 deletions tests/phpunit/README.txt

This file was deleted.

Loading