Make WordPress Core


Ignore:
Timestamp:
09/01/2022 03:26:29 PM (3 years ago)
Author:
SergeyBiryukov
Message:

Site Health: Some documentation and test improvements for WP_Site_Health:

  • Add a @coversDefaultClass annotation to address @covers ::get_test_page_cache" is invalid notices.
  • Rename data providers to start with the data_ prefix and match the test method names, for consistency.
  • Move data providers next to the test methods they are used in.
  • Move ::get_test_page_cache() closer to ::get_test_persistent_object_cache(), for a bit more predictable placement.
  • Fix a typo in ::get_test_persistent_object_cache() description.

Follow-up to [53955], [54043], [54044], [54045].

See #56041.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/site-health.php

    r54045 r54047  
    33/**
    44 * @group site-health
     5 *
     6 * @coversDefaultClass WP_Site_Health
    57 */
    68class Tests_Site_Health extends WP_UnitTestCase {
     
    111113    /**
    112114     * @ticket 56041
    113      * @dataProvider data_page_cache_test
     115     * @dataProvider data_get_page_cache
    114116     * @covers ::get_test_page_cache()
    115117     * @covers ::get_page_cache_detail()
     
    203205
    204206    /**
    205      * @group ms-excluded
    206      * @ticket 56040
    207      */
    208     public function test_object_cache_default_thresholds() {
    209         $wp_site_health = new WP_Site_Health();
    210 
    211         $this->assertFalse(
    212             $wp_site_health->should_suggest_persistent_object_cache()
    213         );
    214     }
    215 
    216 
    217     /**
    218      * @group ms-required
    219      * @ticket 56040
    220      */
    221     public function test_object_cache_default_thresholds_on_multisite() {
    222         $wp_site_health = new WP_Site_Health();
    223         $this->assertTrue(
    224             $wp_site_health->should_suggest_persistent_object_cache()
    225         );
    226     }
    227 
    228     /**
    229      * @ticket 56040
    230      */
    231     public function test_object_cache_thresholds_check_can_be_bypassed() {
    232         $wp_site_health = new WP_Site_Health();
    233         add_filter( 'site_status_should_suggest_persistent_object_cache', '__return_true' );
    234 
    235         $this->assertTrue(
    236             $wp_site_health->should_suggest_persistent_object_cache()
    237         );
    238     }
    239 
    240     /**
    241      * @dataProvider thresholds
    242      * @ticket 56040
    243      */
    244     public function test_object_cache_thresholds( $threshold, $count ) {
    245         $wp_site_health = new WP_Site_Health();
    246         add_filter(
    247             'site_status_persistent_object_cache_thresholds',
    248             function ( $thresholds ) use ( $threshold, $count ) {
    249                 return array_merge( $thresholds, array( $threshold => $count ) );
    250             }
    251         );
    252 
    253         $this->assertTrue(
    254             $wp_site_health->should_suggest_persistent_object_cache()
    255         );
    256     }
    257 
    258     /**
    259      * Gets response data for get_test_page_cache().
     207     * Data provider for test_get_page_cache().
     208     *
     209     * Gets response data for WP_Site_Health::get_test_page_cache().
     210     *
    260211     * @ticket 56041
    261212     *
    262213     * @return array[]
    263214     */
    264     public function data_page_cache_test() {
     215    public function data_get_page_cache() {
    265216        $recommended_label = 'Page cache is not detected but the server response time is OK';
    266217        $good_label        = 'Page cache is detected and the server response time is good';
     
    409360
    410361    /**
    411      * Data provider.
    412      *
     362     * @group ms-excluded
    413363     * @ticket 56040
    414364     */
    415     public function thresholds() {
     365    public function test_object_cache_default_thresholds() {
     366        $wp_site_health = new WP_Site_Health();
     367
     368        $this->assertFalse(
     369            $wp_site_health->should_suggest_persistent_object_cache()
     370        );
     371    }
     372
     373
     374    /**
     375     * @group ms-required
     376     * @ticket 56040
     377     */
     378    public function test_object_cache_default_thresholds_on_multisite() {
     379        $wp_site_health = new WP_Site_Health();
     380        $this->assertTrue(
     381            $wp_site_health->should_suggest_persistent_object_cache()
     382        );
     383    }
     384
     385    /**
     386     * @ticket 56040
     387     */
     388    public function test_object_cache_thresholds_check_can_be_bypassed() {
     389        $wp_site_health = new WP_Site_Health();
     390        add_filter( 'site_status_should_suggest_persistent_object_cache', '__return_true' );
     391
     392        $this->assertTrue(
     393            $wp_site_health->should_suggest_persistent_object_cache()
     394        );
     395    }
     396
     397    /**
     398     * @dataProvider data_object_cache_thresholds
     399     * @ticket 56040
     400     */
     401    public function test_object_cache_thresholds( $threshold, $count ) {
     402        $wp_site_health = new WP_Site_Health();
     403        add_filter(
     404            'site_status_persistent_object_cache_thresholds',
     405            function ( $thresholds ) use ( $threshold, $count ) {
     406                return array_merge( $thresholds, array( $threshold => $count ) );
     407            }
     408        );
     409
     410        $this->assertTrue(
     411            $wp_site_health->should_suggest_persistent_object_cache()
     412        );
     413    }
     414
     415    /**
     416     * Data provider for test_object_cache_thresholds().
     417     *
     418     * @ticket 56040
     419     */
     420    public function data_object_cache_thresholds() {
    416421        return array(
    417422            array( 'comments_count', 0 ),
Note: See TracChangeset for help on using the changeset viewer.