Make WordPress Core


Ignore:
Timestamp:
07/02/2023 10:33:18 AM (15 months ago)
Author:
SergeyBiryukov
Message:

Upgrade/Install: Initialize the local $checkout variable in WP_Automatic_Updater::is_vcs_checkout().

This avoids an Undefined variable $checkout PHP warning if all of the directories checked for access are disallowed due to the PHP open_basedir restrictions.

Follow-up to [55425].

Props jqz, costdev, audrasjb.
Fixes #58563.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/admin/wpAutomaticUpdater.php

    r55425 r56124  
    707707        );
    708708    }
     709
     710    /**
     711     * Tests that `WP_Automatic_Updater::is_vcs_checkout()` returns `false`
     712     * when none of the checked directories are allowed.
     713     *
     714     * @ticket 58563
     715     *
     716     * @covers WP_Automatic_Updater::is_vcs_checkout
     717     */
     718    public function test_is_vcs_checkout_should_return_false_when_no_directories_are_allowed() {
     719        $updater_mock = $this->getMockBuilder( 'WP_Automatic_Updater' )
     720            // Note: setMethods() is deprecated in PHPUnit 9, but still supported.
     721            ->setMethods( array( 'is_allowed_dir' ) )
     722            ->getMock();
     723
     724        /*
     725         * As none of the directories should be allowed, simply mocking `WP_Automatic_Updater`
     726         * and forcing `::is_allowed_dir()` to return `false` removes the need to run the test
     727         * in a separate process due to setting the `open_basedir` PHP directive.
     728         */
     729        $updater_mock->expects( $this->any() )->method( 'is_allowed_dir' )->willReturn( false );
     730
     731        $this->assertFalse( $updater_mock->is_vcs_checkout( get_temp_dir() ) );
     732    }
    709733}
Note: See TracChangeset for help on using the changeset viewer.