mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2025-10-16 12:05:38 +00:00
Introduces `wp_trigger_error()` as a wrapper around PHP's native `trigger_error()`. As a wrapper, it's lean and not opinionated about the message. It accepts an E_USER family error level, meaning it is not limited to only notices. Where `_doing_it_wrong()` intends to loudly alert developers "Hey you're doing it wrong - fix it", `wp_trigger_error()` is not opinionated and does not add wording. Rather, it passes the given message to `trigger_error()`. `wp_trigger_error()` is meant for every `trigger_error()` instance. It can be used: * in `_doing_it_wrong()` and each `_deprecated_*()` function. * for PHP 8.x deprecations. * for PHP error parity. * for less severe "doing it wrong" instance that do not require bailing out. * when a component or extension is not available on the server * for instances where it's not clear if a plugin's or theme's code is the root cause. * and more. Technical details: * Does not trigger the error if `WP_DEBUG` is not `true`. * Includes `wp_trigger_error_run` action to allow hooking in for backtracing and deeper debug. * Accepts an E_USER error level, but defaults to `E_USER_NOTICE`. * Requires a function name, though can be an empty string. As the output message generated by `trigger_error()` references the file and line number where it was invoked, passing the function's name provides more information where the error/warning/notice/deprecation happened. It's intended to help with debug. * A WordPress version number is not included. * As messages can appear in the browser, the message is escaped using `esc_html()`. As noted in [https://www.php.net/manual/en/function.trigger-error.php the PHP manual]: "HTML entities in message are not escaped. Use htmlentities() on the message if the error is to be displayed in a browser." References: * [https://www.php.net/manual/en/function.trigger-error.php PHP manual for `trigger_error()`]. * [https://www.php.net/manual/en/errorfunc.constants.php E_USER constants (error level) in the PHP manual]. Props azaozz, hellofromTonya, flixos90, costdev, peterwilsoncc, oglekler, mukesh27. See #57686. git-svn-id: https://develop.svn.wordpress.org/trunk@56530 602fd350-edb4-49c9-b593-d223f7449a82 |
||
|---|---|---|
| .. | ||
| data | ||
| includes | ||
| tests | ||
| multisite.xml | ||
| README.txt | ||
| wp-mail-real-test.php | ||
The short version:
1. Create a clean MySQL database and user. DO NOT USE AN EXISTING DATABASE or you will lose data, guaranteed.
2. Copy wp-tests-config-sample.php to wp-tests-config.php, edit it and include your database name/user/password.
3. $ svn up
4. Run the tests from the "trunk" directory:
To execute a particular test:
$ phpunit tests/phpunit/tests/test_case.php
To execute all tests:
$ phpunit
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.