-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
Filesystem API: Add initial tests for WP_Filesystem_Direct
.
#4106
Filesystem API: Add initial tests for WP_Filesystem_Direct
.
#4106
Conversation
3c544dc
to
dda0e95
Compare
// Note: setMethods() is deprecated in PHPUnit 9, but still supported. | ||
->setMethods( array( 'dirlist' ) ) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note:
setMethods()
is deprecated in PHPUnit 9 and removed in PHPUnit 10.- The suitable replacement for this case and others in this PR is
onlyMethods()
, introduced in PHPUnit 8.3.0. - However, as the WP Core test suite runs in PHP 5.6, this uses an earlier version of PHPUnit, so
setMethods()
must be used. - It may be preferable to add a PHP or PHPUnit version check here and run the appropriate method, so that compatibility with PHPUnit 10+ can be achieved without being coupled to the minimum WP Core version run in the test suite, or this could be done later to address all uses of
setMethods()
in the test suite in one go.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Related: Yoast/PHPUnit-Polyfills#58
* | ||
* @covers WP_Filesystem_Direct::chgrp | ||
*/ | ||
class Tests_Filesystem_WpFilesystemDirect_Chgrp extends WP_Filesystem_Direct_UnitTestCase { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Further testing requires more investigation for stable testing. This includes a source change to support detecting root
as the user to prevent test failures in local test runners for methods such as ::owner()
and ::group()
when root
is the user. The results of further investigation, and the above source change will be proposed in separate tickets/PRs.
🔢 Applies elsewhere in the tests / WP_Filesystem_Direct
class.
dda0e95
to
1237eea
Compare
1237eea
to
c855b82
Compare
c855b82
to
76af012
Compare
76af012
to
60af67e
Compare
60af67e
to
29a9c65
Compare
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the Unlinked AccountsThe following contributors have not linked their GitHub and WordPress.org accounts: @[email protected]. Contributors, please read how to link your accounts to ensure your work is properly credited in WordPress releases. Core Committers: Use this line as a base for the props when committing in SVN:
To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
Test using WordPress PlaygroundThe changes in this pull request can previewed and tested using a WordPress Playground instance. WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser. Some things to be aware of
For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation. |
This adds some initial tests for the
WP_Filesystem_Direct
filesystem abstraction class.These tests do not aim to cover all paths, but to add line/branch coverage where source changes are not needed to facilitate testing or resolve bugs. The intention is to make it easier to know how to hit a line/branch when trying to cover paths in future.
This also introduces the
WP_Filesystem_Direct_UnitTestCase
class, which contains shared properties,set_up()/tear_down()
, helpers and common data providers for the tests.To allow constants to be set without affecting other tests in the test suite, some of these tests use the
@runInSeparateProcess
annotation [Ref]. To prevent an exception forSerialization of 'Closure' is not allowed
, the@preserveGlobalState disabled
annotation is also used [Ref].Tests exist for the following methods:
__construct()
get_contents()
get_contents_array()
put_contents()
cwd()
chdir()
chgrp()
chmod()
chown()
getchmod()
copy()
move()
delete()
exists()
is_file()
is_dir()
is_readable()
is_writable()
atime()
mtime()
size()
touch()
mkdir()
rmdir()
dirlist()
Trac ticket: https://core.trac.wordpress.org/ticket/57774