Skip to content

Conversation

rodrigoprimo
Copy link
Collaborator

This PR adds tests for cases where the WordPress.WP.GlobalsVariableOverride sniff is not able to resolve the value of $GLOBALS keys. It also includes a separate commit moving a parse error test to a separate file.

// This has to be the last test in the file!
list( $tab, $tabs
/*
* $GLOBALS with non-string key, unable to determine if it is a global variable override or not.
Copy link
Member

Choose a reason for hiding this comment

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

Ahum... it's definitely a global variable override, we just don't know whether it is one we should flag.

Suggested change
* $GLOBALS with non-string key, unable to determine if it is a global variable override or not.
* $GLOBALS with non-string key, unable to determine which variable is being overridden.

Comment on lines +317 to +324
$GLOBALS[ "some{$name}" ] = 'test'; // Ok.
$GLOBALS[ $obj->global_name ] = 'test'; // Ok.
$GLOBALS[ MyClass::GLOBAL_NAME ] = 'test'; // Ok.
$GLOBALS[ GLOBAL_NAME_CONSTANT ] = 'test'; // Ok.
$GLOBALS[ get_my_global_name() ] = 'test'; // Ok.
$GLOBALS[ MyNamespace\get_my_global_name() ] = 'test'; // Ok.
$GLOBALS[ \MyNamespace\get_my_global_name() ] = 'test'; // Ok.
$GLOBALS[ namespace\get_my_global_name() ] = 'test'; // Ok.
Copy link
Member

Choose a reason for hiding this comment

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

Please wrap this test code within a simple function declaration to prevent it potentially affecting other tests in the file. (I vaguely remember we had issues with this in the past, better to prevent new ones in the future ;-) )

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants