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

[Style Engine]: Defensive guarding for when style does not define the 'individual' property #43122

Merged

Conversation

hellofromtonya
Copy link
Contributor

@hellofromtonya hellofromtonya commented Aug 10, 2022

Closes #43121

What?

This PR adds defensive guarding to protect against when the style $property_keys do not define the 'individual' property.

Why?

Prevents a PHP Notice "Undefined index: individual" from being thrown in WP_Style_Engine::get_css_declarations() when a style is not an 'individual'.

How?

It bails out early by not iterating through the array of $style_value. Why? None of that style is individual.

Testing

  • Step 1: Turn on WP_DEBUG and run the PHPUnit tests. How?

Add the following code about loading Composer deps in the phpunit/bootstrap.php file:

// Test with WordPress debug mode (default).
if ( ! defined( 'WP_DEBUG' ) ) {
	define( 'WP_DEBUG', true );
}
  • Step 2: Locally run the PHPUnit tests before applying this patch. Notice the following PHP Notice:
WP_Style_Engine_Test::test_generate_get_styles with data set "invalid_classnames_options" (array(array(array('friends'), array('tasty'))), array(), array())
Undefined index: individual

/var/www/html/wp-content/plugins/gutenberg/packages/style-engine/class-wp-style-engine.php:422
/var/www/html/wp-content/plugins/gutenberg/packages/style-engine/class-wp-style-engine.php:338
/var/www/html/wp-content/plugins/gutenberg/packages/style-engine/class-wp-style-engine.php:562
/var/www/html/wp-content/plugins/gutenberg/packages/style-engine/phpunit/class-wp-style-engine-test.php:37
phpvfscomposer:///var/www/html/wp-content/plugins/gutenberg/vendor/phpunit/phpunit/phpunit:[52](https://github.com/WordPress/gutenberg/runs/7756878353?check_suite_focus=true#step:7:53)
  • Step 3: Apply this patch.

  • Step 4: Run the PHPUnit tests again. The above PHP Notice is resolved.

Notes:

PR #41302 turns on debug mode for testing PHP notices and deprecations.

@hellofromtonya hellofromtonya added [Type] Bug An existing feature does not function as intended [Package] Style Engine /packages/style-engine labels Aug 10, 2022
@hellofromtonya hellofromtonya self-assigned this Aug 10, 2022
Copy link
Member

@ramonjd ramonjd left a comment

Choose a reason for hiding this comment

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

Tested with WP_DEBUG set to true

In trunk I see the warning:

14) WP_Style_Engine_Test::test_generate_get_styles with data set "invalid_classnames_options" (array(array(array('friends'), array('tasty'))), array(), array())
Undefined index: individual

/var/www/html/wp-content/plugins/gutenberg/packages/style-engine/class-wp-style-engine.php:423
/var/www/html/wp-content/plugins/gutenberg/packages/style-engine/class-wp-style-engine.php:334
/var/www/html/wp-content/plugins/gutenberg/packages/style-engine/class-wp-style-engine.php:563
/var/www/html/wp-content/plugins/gutenberg/packages/style-engine/phpunit/class-wp-style-engine-test.php:37
phpvfscomposer:///var/www/html/wp-content/plugins/gutenberg/vendor/phpunit/phpunit/phpunit:52

With the new check, it's gone 🪄

Thanks for catching @hellofromtonya

@ramonjd ramonjd merged commit 59004cd into trunk Aug 10, 2022
@ramonjd ramonjd deleted the fix/php-notice-undefined-index-individual-style-engine branch August 10, 2022 22:02
@github-actions github-actions bot added this to the Gutenberg 14.0 milestone Aug 10, 2022
@andrewserong andrewserong added the Backport to Gutenberg Minor Release Pull request that needs to be backported to a Gutenberg minor release label Aug 15, 2022
@andrewserong
Copy link
Contributor

Cherry-picked into the 13.9.0 RC 3 (https://github.com/WordPress/gutenberg/releases/tag/v13.9.0-rc.3)

@andrewserong andrewserong removed the Backport to Gutenberg Minor Release Pull request that needs to be backported to a Gutenberg minor release label Aug 15, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Package] Style Engine /packages/style-engine [Type] Bug An existing feature does not function as intended
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Style Engine] PHP Notice: Undefined index: 'individual'
3 participants