Skip to content

Commit

Permalink
Tests: Correct the WP_Test_Stream::mkdir() method.
Browse files Browse the repository at this point in the history
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
  • Loading branch information
SergeyBiryukov committed Oct 24, 2023
1 parent 88ab0a2 commit c438beb
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion tests/phpunit/includes/class-wp-test-stream.php
Original file line number Diff line number Diff line change
Expand Up @@ -198,16 +198,27 @@ public function stream_metadata( $path, $option, $value ) {
* 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;
}

Expand Down

0 comments on commit c438beb

Please sign in to comment.