#42065 closed enhancement (fixed)
Implement `assertNotWPError` in test suite
Reported by: |
|
Owned by: |
|
---|---|---|---|
Milestone: | 5.1 | Priority: | normal |
Severity: | normal | Version: | |
Component: | Build/Test Tools | Keywords: | has-patch |
Focuses: | Cc: |
Description
WP_Error
often returns useful information about why a function is failed.
However, an assertion like $this->assertNotInstanceOf( 'WP_Error', $file );
isn't helpful to the test runner because it doesn't communicate the information conveyed by the WP_Error
object.
Currently, someone running the test has to add some var_dump()
debug (or similar) to read the contents of the returned error object.
It would be helpful to have an assertNotWPError
assertion that communicated the contents of the WP_Error
object when it actually is one.
Inspired by #42064
Attachments (1)
Change History (8)
#3
@
7 years ago
- Keywords needs-patch added
- Summary changed from Introduce `assertNotWPError` in test suite to Implement `assertNotWPError` in test suite
Yep definitely.
#4
@
7 years ago
- Keywords has-patch added; needs-patch removed
42065.diff changes:
$this->assertNotInstanceOf( 'WP_Error', ... )
to
$this->assertNotWPError( ... )
in the test files:
- tests/phpunit/tests/post/formats.php
- tests/phpunit/tests/customize/manager.php
- tests/phpunit/tests/customize/nav-menu-setting.php
- tests/phpunit/tests/image/editorImagick.php
- tests/phpunit/tests/image/editorGd.php
- tests/phpunit/tests/image/functions.php
- tests/phpunit/tests/admin/includesPost.php
- tests/phpunit/tests/ajax/CustomizeManager.php
- tests/phpunit/includes/testcase-rest-post-type-controller.php
This is the method's definition:
function assertNotWPError( $actual, $message = '' ) { if ( is_wp_error( $actual ) && '' === $message ) { $message = $actual->get_error_message(); } $this->assertNotInstanceOf( 'WP_Error', $actual, $message ); }
where we see how the WP_Error
error message is passed on to the $message
argument of the assertNotInstandeOf
method.
It's already there but there are a bunch of places in core that don't use it.