#57706 closed defect (bug) (fixed)
REST_Block_Type_Controller_Test::test_get_item_invalid() throws PHP Warning for invalid 'styles' data type
Reported by: | hellofromTonya | Owned by: | hellofromTonya |
---|---|---|---|
Milestone: | 6.2 | Priority: | normal |
Severity: | normal | Version: | |
Component: | Build/Test Tools | Keywords: | has-patch has-unit-tests commit |
Focuses: | Cc: |
Description
The REST_Block_Type_Controller_Test::test_get_item_invalid()
throws a PHP Warning due to the 'styles'
setting not being an array
data type.
Warning: foreach() argument must be of type array|object, string given in wp-includes/class-wp-theme-json.php on line 835
WP_Block_Type
expects the 'styles'
property to be an array. The code in WP_Theme_JSON
(added in #57583 / [55172] expects the property to be an array as it is passed into a foreach()
. But this test sets it to a string.
The PHP Warning alerts the developer of a problem which in this case is an incorrect data type when registering the block type.
This ticket proposes either checking for the PHP Warning OR setting the 'styles'
property to an empty array()
instead.
Change History (7)
This ticket was mentioned in PR #4068 on WordPress/wordpress-develop by @tanjimtc71.
19 months ago
#1
- Keywords has-patch has-unit-tests added; needs-patch removed
#4
@
19 months ago
- Keywords commit added
- Owner set to hellofromTonya
- Status changed from assigned to reviewing
Patch: https://github.com/WordPress/wordpress-develop/pull/4068
This patch does indeed resolve the PHP Warning in the test suites. Ready for commit. I'm prepping it now.
@hellofromTonya commented on PR #4068:
19 months ago
#6
Committed via https://core.trac.wordpress.org/changeset/55342.
Added fix for
REST_Block_Type_Controller_Test::test_get_item_invalid()
which was throwing a PHP warning due to an incorrect data type in the 'styles' property of theWP_Block_Type
.This PR Fixes a PHP Warning in the test caused by the 'styles' property not being an array. The proposed fix sets the 'styles' property to an empty array().
Could you please review the changes and let me know if anything needs to be updated or changed? I would really appreciate your feedback.
Thank you for taking the time to review this.
Trac ticket: https://core.trac.wordpress.org/ticket/57706