Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions WordPress/Tests/WP/AlternativeFunctionsUnitTest.inc
Original file line number Diff line number Diff line change
Expand Up @@ -147,3 +147,27 @@ file_get_contents(
// Not using plugin_dir_path() for reasons.
$url
); // Warning.

/*
* Safeguard correct handling of all types of namespaced function calls
*/
\curl_init();
MyNamespace\curl_init();
\MyNamespace\curl_init();
namespace\curl_init(); // The sniff should start flagging this once it can resolve relative namespaces.

/*
* Safeguard correct handling of namespaced parameters passed to file_get_contents().
*
* Note: the sniff should flag the examples using a fully qualified namespaced name and partially
* qualified name, but currently does not. This will be addressed via
* https://github.com/WordPress/WordPress-Coding-Standards/issues/2603.
*/
file_get_contents(\wp_upload_dir()['path'] . 'subdir/file.inc');
file_get_contents(MyNamespace\wp_upload_dir()['path'] . 'subdir/file.inc');
file_get_contents(\MyNamespace\wp_upload_dir()['path'] . 'subdir/file.inc');
file_get_contents(namespace\wp_upload_dir()['path'] . 'subdir/file.inc');
file_get_contents(\ABSPATH . 'wp-admin/css/some-file.css');
file_get_contents(MyNamespace\ABSPATH . 'wp-admin/css/some-file.css');
file_get_contents(\MyNamespace\ABSPATH . 'wp-admin/css/some-file.css');
file_get_contents(namespace\ABSPATH . 'wp-admin/css/some-file.css');
Comment on lines +159 to +173
Copy link
Member

Choose a reason for hiding this comment

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

I wonder if it wouldn't be better to add these tests in the commit which addresses #2603 ? That way, the tests and the fix would be in the same commit (=atomic), making it more straight-forward in the future to understand the history of changes in the sniff.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

That was my original plan. Maybe I misunderstood what you said when we discussed this on Monday, but I thought you had suggested including those tests together with the rest of the namespaced names tests above. I'm happy to remove them from this PR and leave them for when #2603 is addressed.

1 change: 1 addition & 0 deletions WordPress/Tests/WP/AlternativeFunctionsUnitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ public function getWarningList() {
131 => 1,
142 => 1,
146 => 1,
154 => 1,
);
}
}