Make WordPress Core

Changeset 51186


Ignore:
Timestamp:
06/20/2021 12:24:31 AM (4 years ago)
Author:
SergeyBiryukov
Message:

Tests: Use more appropriate assertions in clean_dirsize_cache() tests.

Follow-up to [49212], [49616], [49628], [49630].

See #52625.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/multisite/cleanDirsizeCache.php

    r49744 r51186  
    6666
    6767            // No cache match on non existing directory should return false.
    68             $this->assertSame( false, recurse_dirsize( $upload_dir['basedir'] . '/does_not_exist' ) );
     68            $this->assertFalse( recurse_dirsize( $upload_dir['basedir'] . '/does_not_exist' ) );
    6969
    7070            // Cleanup.
     
    102102            set_transient( 'dirsize_cache', $this->_get_mock_dirsize_cache_for_site( $blog_id ) );
    103103
    104             $this->assertSame( true, array_key_exists( $cache_key_prefix . '/1/1', get_transient( 'dirsize_cache' ) ) );
    105             $this->assertSame( true, array_key_exists( $cache_key_prefix . '/2/1', get_transient( 'dirsize_cache' ) ) );
    106             $this->assertSame( true, array_key_exists( $cache_key_prefix . '/2', get_transient( 'dirsize_cache' ) ) );
     104            $this->assertArrayHasKey( $cache_key_prefix . '/1/1', get_transient( 'dirsize_cache' ) );
     105            $this->assertArrayHasKey( $cache_key_prefix . '/2/1', get_transient( 'dirsize_cache' ) );
     106            $this->assertArrayHasKey( $cache_key_prefix . '/2', get_transient( 'dirsize_cache' ) );
    107107
    108108            // Invalidation should also respect the directory tree up.
     
    110110            clean_dirsize_cache( $upload_dir['basedir'] . '/2/1/file.dummy' );
    111111
    112             $this->assertSame( false, array_key_exists( $cache_key_prefix . '/2/1', get_transient( 'dirsize_cache' ) ) );
    113             $this->assertSame( false, array_key_exists( $cache_key_prefix . '/2', get_transient( 'dirsize_cache' ) ) );
     112            $this->assertArrayNotHasKey( $cache_key_prefix . '/2/1', get_transient( 'dirsize_cache' ) );
     113            $this->assertArrayNotHasKey( $cache_key_prefix . '/2', get_transient( 'dirsize_cache' ) );
    114114
    115115            // Other cache paths should not be invalidated.
    116             $this->assertSame( true, array_key_exists( $cache_key_prefix . '/1/1', get_transient( 'dirsize_cache' ) ) );
     116            $this->assertArrayHasKey( $cache_key_prefix . '/1/1', get_transient( 'dirsize_cache' ) );
    117117
    118118            // Cleanup.
     
    150150            set_transient( 'dirsize_cache', $this->_get_mock_dirsize_cache_for_site( $blog_id ) );
    151151
    152             $this->assertSame( true, array_key_exists( $cache_key_prefix . '/1/1', get_transient( 'dirsize_cache' ) ) );
    153             $this->assertSame( true, array_key_exists( $cache_key_prefix . '/2/1', get_transient( 'dirsize_cache' ) ) );
    154             $this->assertSame( true, array_key_exists( $cache_key_prefix . '/2', get_transient( 'dirsize_cache' ) ) );
     152            $this->assertArrayHasKey( $cache_key_prefix . '/1/1', get_transient( 'dirsize_cache' ) );
     153            $this->assertArrayHasKey( $cache_key_prefix . '/2/1', get_transient( 'dirsize_cache' ) );
     154            $this->assertArrayHasKey( $cache_key_prefix . '/2', get_transient( 'dirsize_cache' ) );
    155155
    156156            // Invalidation should also respect the directory tree up.
     
    158158            clean_dirsize_cache( $upload_dir['basedir'] . '/2/1' );
    159159
    160             $this->assertSame( false, array_key_exists( $cache_key_prefix . '/2/1', get_transient( 'dirsize_cache' ) ) );
    161             $this->assertSame( false, array_key_exists( $cache_key_prefix . '/2', get_transient( 'dirsize_cache' ) ) );
     160            $this->assertArrayNotHasKey( $cache_key_prefix . '/2/1', get_transient( 'dirsize_cache' ) );
     161            $this->assertArrayNotHasKey( $cache_key_prefix . '/2', get_transient( 'dirsize_cache' ) );
    162162
    163163            // Other cache paths should not be invalidated.
    164             $this->assertSame( true, array_key_exists( $cache_key_prefix . '/1/1', get_transient( 'dirsize_cache' ) ) );
     164            $this->assertArrayHasKey( $cache_key_prefix . '/1/1', get_transient( 'dirsize_cache' ) );
    165165
    166166            // Cleanup.
     
    207207            // `dirsize_cache` should now be filled after upload and recurse_dirsize() call.
    208208            $cache_path = untrailingslashit( $upload_dir['path'] );
    209             $this->assertSame( true, is_array( get_transient( 'dirsize_cache' ) ) );
     209            $this->assertInternalType( 'array', get_transient( 'dirsize_cache' ) );
    210210            $this->assertSame( $size, get_transient( 'dirsize_cache' )[ $cache_path ] );
    211211
     
    281281             * exist on disk, so the function should fail.
    282282             */
    283             $this->assertSame( false, recurse_dirsize( $upload_dir['basedir'] . '/2/1' ) );
     283            $this->assertFalse( recurse_dirsize( $upload_dir['basedir'] . '/2/1' ) );
    284284
    285285            /*
     
    305305
    306306            // No cache match on non existing directory should return false.
    307             $this->assertSame( false, recurse_dirsize( $upload_dir['basedir'] . '/does_not_exist' ) );
     307            $this->assertFalse( recurse_dirsize( $upload_dir['basedir'] . '/does_not_exist' ) );
    308308
    309309            // Cleanup.
Note: See TracChangeset for help on using the changeset viewer.