Make WordPress Core

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 $exclude parameter.
  • Correct behaviour for non-existent or unreadable directories.
  • Support for the pre_recurse_dirsize filter 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

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.

#2 @wildworks
4 weeks ago

  • Milestone 7.1Awaiting Review

Since 7.1 Beta 1 has already been released and these functions were not newly introduced with the 7.1 release, I'd like to remove the milestone.

Note: See TracTickets for help on using tickets.