Make WordPress Core

Changeset 56998

Timestamp:
10/24/2023 11:32:42 AM (10 months ago)
Author:
SergeyBiryukov
Message:

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: PHP Manual: streamWrapper::mkdir().

Follow-up to [49230].

Props david.binda, sadizaman, rajinsharwar, SergeyBiryukov.
Fixes #59406.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/includes/class-wp-test-stream.php

    r55017 r56998  
    199199     *
    200200     * @see streamWrapper::mkdir
     201
     202
     203
     204
     205
    201206     */
    202207    public function mkdir( $path, $mode, $options ) {
    203208        $this->open( $path );
     209
    204210        $plainfile = rtrim( $this->file, '/' );
    205211
    206         if ( isset( WP_Test_Stream::$data[ $this->bucket ][ $file ] ) ) {
    207             return false;
    208         }
     212        // Check if a file or directory with the same name already exists.
     213        if ( isset( WP_Test_Stream::$data[ $this->bucket ][ $plainfile ] )
     214            || isset( WP_Test_Stream::$data[ $this->bucket ][ $plainfile . '/' ] )
     215        ) {
     216            return false;
     217        }
     218
    209219        $dir_ref = & $this->get_directory_ref();
    210220        $dir_ref = 'DIRECTORY';
     221
    211222        return true;
    212223    }
Note: See TracChangeset for help on using the changeset viewer.