Opened 4 weeks ago
Last modified 4 weeks ago
#65654 new enhancement
Tests: Add PHPUnit tests for get_dirsize()
| Reported by: | pbearne | Owned by: | |
|---|---|---|---|
| Priority: | normal | Milestone: | Awaiting Review |
| Component: | General | Version: | |
| Severity: | normal | Keywords: | has-patch has-unit-tests |
| Cc: | Focuses: | tests |
Description
The get_dirsize() function in wp-includes/functions.php calculates the total size of a directory in bytes. It relies on recurse_dirsize() to perform the actual calculation and supports features like excluding specific subdirectories and enforcing a maximum execution time.
Currently, this function lacks dedicated unit test coverage in the core suite. This patch introduces a new test class Tests_Functions_GetDirsize to verify:
- Accurate size calculation for directories containing files and subdirectories.
- Proper handling of the
$excludeparameter. - Correct behaviour for non-existent or unreadable directories.
- Support for the
pre_recurse_dirsizefilter to short-circuit calculation. - Basic verification of the transient-based caching mechanism (
dirsize_cache).
Change History (2)
This ticket was mentioned in PR #12570 on WordPress/wordpress-develop by @pbearne.
4 weeks ago
#1
- Keywords has-patch has-unit-tests added
Note:
See TracTickets
for help on using tickets.
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)
This PR adds unit tests for get_dirsize() and recurse_dirsize() in wp-includes/functions.php.
The implementation uses isolated temporary directories within the test environment to ensure reliable execution across different platforms and Docker setups.
Changes:
•tests/phpunit/tests/functions/getDirsize.php: Covers the high-level get_dirsize() API.
•tests/phpunit/tests/functions/recurseDirsize.php: Covers the recursive logic, including exclusions, filtering, and caching.
Trac ticket: https://core.trac.wordpress.org/ticket/65654
AI Disclosure:
•AI assistance: Yes
•Tool(s): Junie (JetBrains)
•Model(s): gemini-3-flash-preview
•Used for: Code analysis, test implementation, and environment-specific troubleshooting.