ContextHelper::is_in_isset_or_empty(): add basic tests#2725
Conversation
| $obj?->key_exists( 'key', /* testNullsafeObjectMethod */ $array ); | ||
| MyClass::array_key_exists( 'key', /* testStaticMethod */ $array ); | ||
| key_exists( 'key', my_function( /* testNestedFunctionCall */ $array ) ); | ||
|
|
There was a problem hiding this comment.
How about the negative test of just bare $value too?
There was a problem hiding this comment.
Thanks for the review, @GaryJones. I added the bare $value negative test you suggested. I also added a nested valid function call test similar to the one you suggested in the review of #2721 and renamed testNestedFunctionCall to testNestedNonTargetFunctionCall to better contrast with the new positive case.
| $obj?->key_exists( 'key', /* testNullsafeObjectMethod */ $array ); | ||
| MyClass::array_key_exists( 'key', /* testStaticMethod */ $array ); | ||
| key_exists( 'key', my_function( /* testNestedNonTargetFunctionCall */ $array ) ); | ||
|
|
There was a problem hiding this comment.
How about adding these ("no false positives") tests too ?
Foo::isset();
Some\Ns\empty();
And maybe one or two variations, don't need to be silly comprehensive as the tokenizer wouldn't tokenize the above as T_ISSET/T_EMPTY (which is why this isn't specifically tested in PHPCSUtils and all the more reason we should have a few of these tests here).
There was a problem hiding this comment.
I thought about it, but then opted not to add the tests precisely because PHPCS doesn't tokenize the above as T_ISSET/T_EMPTY. That said, those tests will not hurt, and I added a new commit with them.
* upstream/develop: (223 commits) ContextHelper::is_in_type_test(): add tests (WordPress#2721) WPDBTrait::is_wpdb_method_call(): improve docblock description (WordPress#2719) ContextHelper::is_in_array_comparison(): add basic tests (WordPress#2726) ContextHelper::is_in_isset_or_empty(): add basic tests (WordPress#2725) WP/I18n: add tests for namespaced names WP/GetMetaSingle: add tests for namespaced names WP/DeprecatedParameterValues: add tests for namespaced names WP/DeprecatedParameterValues: move syntax error test to its own file WP/DeprecatedParameterValues: rename test case file WP/DeprecatedParameters: add tests for namespaced names FormattingFunctionsHelper::is_formatting_function(): add tests (WordPress#2713) UnslashingFunctionsHelper::is_unslashing_function(): add tests (WordPress#2715) GH Actions: Bump crate-ci/typos from 1.44.0 to 1.45.0 in the action-runners group (WordPress#2717) GH Actions: Bump codecov/codecov-action from 5.5.3 to 6.0.0 GH Actions: Bump ramsey/composer-install from 3.1.1 to 4.0.0 GH Actions: Bump the action-runners group with 2 updates Security/ValidatedSanitizedInput: add tests for namespaced names Apply suggestion from PR review WP/EnqueuedResourceParameters: add tests for namespaced names (WordPress#2675) GH Actions: Bump crate-ci/typos in the action-runners group ...
Description
In preparation for supporting PHPCS 4.0, this PR adds unit tests for the
ContextHelper::is_in_isset_or_empty()method.Suggested changelog entry
N/A