Opened 3 months ago
Last modified 3 months ago
#57774 reviewing defect (bug)
Add some initial PHPUnit tests for `WP_Filesystem_Direct`
Reported by: |
|
Owned by: |
|
---|---|---|---|
Milestone: | 6.3 | Priority: | normal |
Severity: | normal | Version: | 2.5 |
Component: | Filesystem API | Keywords: | has-patch has-unit-tests |
Focuses: | Cc: |
Description
This is a tests-only ticket.
WP_Filesystem_Direct
is, by far, the most used filesystem abstraction class.
While some PHPUnit tests exist for a WP_Filesystem_MockFS
class, this ticket aims to add PHPUnit tests for the WP_Filesystem_Direct
class itself.
The other filesystem abstraction classes, WP_Filesystem_FTPext
, WP_Filesystem_ftpsockets
and WP_Filesystem_SSH2
, do not have PHPUnit test runner configurations. While in future, we may reuse many of the same tests across filesystem abstraction classes, this ticket specifically targets WP_Filesystem_Direct
.
Change History (5)
This ticket was mentioned in PR #4106 on WordPress/wordpress-develop by @costdev.
3 months ago
#1
- Keywords has-unit-tests added
#2
@
3 months ago
PR 4106 is ready for review.
Line coverage: 74.56%
Branch coverage: 76.83%
To cover more lines/branches, source changes are needed to facilitate testing/fix bugs. This will be done in separate tickets.
#3
@
3 months ago
- Owner changed from costdev to hellofromTonya
- Status changed from assigned to reviewing
Self-assigning for review and commit consideration.
This ticket was mentioned in Slack in #core by mukeshpanchal27. View the logs.
3 months ago
#5
@
3 months ago
- Milestone changed from 6.2 to 6.3
This ticket was discussed in the bug scrub.
While this is a tests-only ticket and can be committed at any time, we're approaching RC1 and the PR is awaiting review, so I'm going to move this ticket to the 6.3 milestone.
Should it be reviewed and ready for committed prior to 6.2 RC1, feel free to bring it back into the 6.2 milestone for commit.
Additional props: @mukesh27
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