Make WordPress Core


Ignore:
Timestamp:
07/23/2022 02:56:51 PM (2 years ago)
Author:
SergeyBiryukov
Message:

Cache API: Make the placement of wp_cache_flush_group() more consistent.

Includes:

  • Placing WP_Object_Cache::flush_group() next to ::flush().
  • Placing wp_cache_supports_group_flush() next to wp_cache_flush_group().
  • Placing the wp_cache_flush_group() unit test next to the ::flush() method test.
  • Removing test name from assertion messages, as it is already mentioned directly above in case of failure.
  • Adjusting function descriptions per the documentation standards.

Follow-up to [52706], [53763].

See #55647, #4476.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/cache.php

    r53763 r53767  
    128128        // If there is no value get returns false.
    129129        $this->assertFalse( $this->cache->get( $key ) );
     130    }
     131
     132    /**
     133     * @ticket 4476
     134     * @ticket 9773
     135     *
     136     * @covers ::wp_cache_flush_group
     137     */
     138    public function test_wp_cache_flush_group() {
     139        $key = 'my-key';
     140        $val = 'my-val';
     141
     142        wp_cache_set( $key, $val, 'group-test' );
     143        wp_cache_set( $key, $val, 'group-kept' );
     144
     145        $this->assertSame( $val, wp_cache_get( $key, 'group-test' ), 'group-test should contain my-val' );
     146
     147        if ( wp_using_ext_object_cache() ) {
     148            $this->setExpectedIncorrectUsage( 'wp_cache_flush_group' );
     149        }
     150
     151        $results = wp_cache_flush_group( 'group-test' );
     152
     153        if ( wp_using_ext_object_cache() ) {
     154            $this->assertFalse( $results );
     155        } else {
     156            $this->assertTrue( $results );
     157            $this->assertFalse( wp_cache_get( $key, 'group-test' ), 'group-test should return false' );
     158            $this->assertSame( $val, wp_cache_get( $key, 'group-kept' ), 'group-kept should still contain my-val' );
     159        }
    130160    }
    131161
     
    416446        $this->assertSame( $expected, $found );
    417447    }
    418 
    419     /**
    420      * @ticket 4476
    421      * @ticket 9773
    422      *
    423      * test wp_cache_flush_group
    424      *
    425      * @covers ::wp_cache_flush_group
    426      */
    427     public function test_wp_cache_flush_group() {
    428         $key = 'my-key';
    429         $val = 'my-val';
    430 
    431         wp_cache_set( $key, $val, 'group-test' );
    432         wp_cache_set( $key, $val, 'group-kept' );
    433 
    434         $this->assertSame( $val, wp_cache_get( $key, 'group-test' ), 'test_wp_cache_flush_group: group-test should contain my-val' );
    435 
    436         if ( wp_using_ext_object_cache() ) {
    437             $this->setExpectedIncorrectUsage( 'wp_cache_flush_group' );
    438         }
    439 
    440         $results = wp_cache_flush_group( 'group-test' );
    441 
    442         if ( wp_using_ext_object_cache() ) {
    443             $this->assertFalse( $results );
    444         } else {
    445             $this->assertTrue( $results );
    446             $this->assertFalse( wp_cache_get( $key, 'group-test' ), 'test_wp_cache_flush_group: group-test should return false' );
    447             $this->assertSame( $val, wp_cache_get( $key, 'group-kept' ), 'test_wp_cache_flush_group: group-kept should still contain my-val' );
    448         }
    449     }
    450448}
Note: See TracChangeset for help on using the changeset viewer.