From c438bebad1530fcef443be35061bf67024dde6a7 Mon Sep 17 00:00:00 2001 From: Sergey Biryukov Date: Tue, 24 Oct 2023 11:32:42 +0000 Subject: [PATCH] Tests: Correct the `WP_Test_Stream::mkdir()` method. The method attempted to check if there is already a file with the same name, however the conditional used an undefined variable. This commit prevents directory creation if a file or directory with the same name already exists, bringing consistency with the PHP `mkdir()` implementation. Includes adding missing documentation for the method. Reference: [https://www.php.net/manual/en/streamwrapper.mkdir.php PHP Manual: streamWrapper::mkdir()]. Follow-up to [49230]. Props david.binda, sadizaman, rajinsharwar, SergeyBiryukov. Fixes #59406. git-svn-id: https://develop.svn.wordpress.org/trunk@56998 602fd350-edb4-49c9-b593-d223f7449a82 --- tests/phpunit/includes/class-wp-test-stream.php | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/tests/phpunit/includes/class-wp-test-stream.php b/tests/phpunit/includes/class-wp-test-stream.php index 11997507d0..17d930b586 100644 --- a/tests/phpunit/includes/class-wp-test-stream.php +++ b/tests/phpunit/includes/class-wp-test-stream.php @@ -198,16 +198,27 @@ class WP_Test_Stream { * Creates a directory. * * @see streamWrapper::mkdir + * + * @param string $path Directory which should be created. + * @param int $mode The value passed to mkdir(). + * @param int $options A bitwise mask of values, such as STREAM_MKDIR_RECURSIVE. + * @return bool True on success, false on failure. */ public function mkdir( $path, $mode, $options ) { $this->open( $path ); + $plainfile = rtrim( $this->file, '/' ); - if ( isset( WP_Test_Stream::$data[ $this->bucket ][ $file ] ) ) { + // Check if a file or directory with the same name already exists. + if ( isset( WP_Test_Stream::$data[ $this->bucket ][ $plainfile ] ) + || isset( WP_Test_Stream::$data[ $this->bucket ][ $plainfile . '/' ] ) + ) { return false; } + $dir_ref = & $this->get_directory_ref(); $dir_ref = 'DIRECTORY'; + return true; }