Make WordPress Core


Ignore:
Timestamp:
11/04/2021 03:22:47 PM (3 years ago)
Author:
hellofromTonya
Message:

Coding Standards: Add visibility to methods in tests/phpunit/tests/.

Adds a public visibility to test fixtures, tests, data providers, and callbacks methods.

Adds a private visibility to helper methods within test classes.

Renames callbacks and helpers that previously started with a _ prefix. Why? For consistency and to leverage using the method visibility. Further naming standardizations is beyond the scope of this commit.

Props costdev, jrf, hellofromTonya.
Fixes #54177.

File:
1 edited

Legend:

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

    r51869 r52010  
    1616         * @ticket 19879
    1717         */
    18         function test_get_dirsize_cache_in_recurse_dirsize_mock() {
    19             $blog_id = self::factory()->blog->create();
    20             switch_to_blog( $blog_id );
    21 
    22             /*
    23              * Our comparison of space relies on an initial value of 0. If a previous test has failed
    24              * or if the `src` directory already contains a directory with site content, then the initial
    25              * expectation will be polluted. We create sites until an empty one is available.
    26              */
    27             while ( 0 !== get_space_used() ) {
    28                 restore_current_blog();
    29                 $blog_id = self::factory()->blog->create();
    30                 switch_to_blog( $blog_id );
    31             }
    32 
    33             // Clear the dirsize cache.
    34             delete_transient( 'dirsize_cache' );
    35 
    36             // Set the dirsize cache to our mock.
    37             set_transient( 'dirsize_cache', $this->_get_mock_dirsize_cache_for_site( $blog_id ) );
     18        public function test_get_dirsize_cache_in_recurse_dirsize_mock() {
     19            $blog_id = self::factory()->blog->create();
     20            switch_to_blog( $blog_id );
     21
     22            /*
     23             * Our comparison of space relies on an initial value of 0. If a previous test has failed
     24             * or if the `src` directory already contains a directory with site content, then the initial
     25             * expectation will be polluted. We create sites until an empty one is available.
     26             */
     27            while ( 0 !== get_space_used() ) {
     28                restore_current_blog();
     29                $blog_id = self::factory()->blog->create();
     30                switch_to_blog( $blog_id );
     31            }
     32
     33            // Clear the dirsize cache.
     34            delete_transient( 'dirsize_cache' );
     35
     36            // Set the dirsize cache to our mock.
     37            set_transient( 'dirsize_cache', $this->get_mock_dirsize_cache_for_site( $blog_id ) );
    3838
    3939            $upload_dir = wp_upload_dir();
     
    6565         * @ticket 19879
    6666         */
    67         function test_clean_dirsize_cache_file_input_mock() {
     67        public function test_clean_dirsize_cache_file_input_mock() {
    6868            $blog_id = self::factory()->blog->create();
    6969            switch_to_blog( $blog_id );
     
    8787
    8888            // Set the dirsize cache to our mock.
    89             set_transient( 'dirsize_cache', $this->_get_mock_dirsize_cache_for_site( $blog_id ) );
     89            set_transient( 'dirsize_cache', $this->get_mock_dirsize_cache_for_site( $blog_id ) );
    9090
    9191            $this->assertArrayHasKey( $cache_key_prefix . '/1/1', get_transient( 'dirsize_cache' ) );
     
    113113         * @ticket 19879
    114114         */
    115         function test_clean_dirsize_cache_folder_input_mock() {
     115        public function test_clean_dirsize_cache_folder_input_mock() {
    116116            $blog_id = self::factory()->blog->create();
    117117            switch_to_blog( $blog_id );
     
    135135
    136136            // Set the dirsize cache to our mock.
    137             set_transient( 'dirsize_cache', $this->_get_mock_dirsize_cache_for_site( $blog_id ) );
     137            set_transient( 'dirsize_cache', $this->get_mock_dirsize_cache_for_site( $blog_id ) );
    138138
    139139            $this->assertArrayHasKey( $cache_key_prefix . '/1/1', get_transient( 'dirsize_cache' ) );
     
    161161         * @ticket 19879
    162162         */
    163         function test_get_dirsize_cache_in_recurse_dirsize_upload() {
     163        public function test_get_dirsize_cache_in_recurse_dirsize_upload() {
    164164            $blog_id = self::factory()->blog->create();
    165165            switch_to_blog( $blog_id );
     
    207207         * @ticket 19879
    208208         */
    209         function test_pre_recurse_dirsize_filter() {
    210             add_filter( 'pre_recurse_dirsize', array( $this, '_filter_pre_recurse_dirsize' ) );
     209        public function test_pre_recurse_dirsize_filter() {
     210            add_filter( 'pre_recurse_dirsize', array( $this, 'filter_pre_recurse_dirsize' ) );
    211211
    212212            $upload_dir = wp_upload_dir();
    213213            $this->assertSame( 1042, recurse_dirsize( $upload_dir['path'] ) );
    214214
    215             remove_filter( 'pre_recurse_dirsize', array( $this, '_filter_pre_recurse_dirsize' ) );
    216         }
    217 
    218         function _filter_pre_recurse_dirsize() {
     215            remove_filter( 'pre_recurse_dirsize', array( $this, 'filter_pre_recurse_dirsize' ) );
     216        }
     217
     218        public function filter_pre_recurse_dirsize() {
    219219            return 1042;
    220220        }
    221221
    222         function _get_mock_dirsize_cache_for_site( $site_id ) {
     222        private function get_mock_dirsize_cache_for_site( $site_id ) {
    223223            $prefix = wp_upload_dir()['basedir'];
    224224
     
    240240         * @ticket 51913
    241241         */
    242         function test_5_5_transient_structure_compat() {
    243             $blog_id = self::factory()->blog->create();
    244             switch_to_blog( $blog_id );
    245 
    246             /*
    247              * Our comparison of space relies on an initial value of 0. If a previous test has failed
    248              * or if the `src` directory already contains a directory with site content, then the initial
    249              * expectation will be polluted. We create sites until an empty one is available.
    250              */
    251             while ( 0 !== get_space_used() ) {
    252                 restore_current_blog();
    253                 $blog_id = self::factory()->blog->create();
    254                 switch_to_blog( $blog_id );
    255             }
    256 
    257             // Clear the dirsize cache.
    258             delete_transient( 'dirsize_cache' );
    259 
    260             // Set the dirsize cache to our mock.
    261             set_transient( 'dirsize_cache', $this->_get_mock_5_5_dirsize_cache( $blog_id ) );
     242        public function test_5_5_transient_structure_compat() {
     243            $blog_id = self::factory()->blog->create();
     244            switch_to_blog( $blog_id );
     245
     246            /*
     247             * Our comparison of space relies on an initial value of 0. If a previous test has failed
     248             * or if the `src` directory already contains a directory with site content, then the initial
     249             * expectation will be polluted. We create sites until an empty one is available.
     250             */
     251            while ( 0 !== get_space_used() ) {
     252                restore_current_blog();
     253                $blog_id = self::factory()->blog->create();
     254                switch_to_blog( $blog_id );
     255            }
     256
     257            // Clear the dirsize cache.
     258            delete_transient( 'dirsize_cache' );
     259
     260            // Set the dirsize cache to our mock.
     261            set_transient( 'dirsize_cache', $this->get_mock_5_5_dirsize_cache( $blog_id ) );
    262262
    263263            $upload_dir = wp_upload_dir();
     
    282282
    283283            // Set the dirsize cache to our mock.
    284             set_transient( 'dirsize_cache', $this->_get_mock_5_5_dirsize_cache( $blog_id ) );
     284            set_transient( 'dirsize_cache', $this->get_mock_5_5_dirsize_cache( $blog_id ) );
    285285
    286286            /*
     
    301301        }
    302302
    303         function _get_mock_5_5_dirsize_cache( $site_id ) {
     303        private function get_mock_5_5_dirsize_cache( $site_id ) {
    304304            $prefix = untrailingslashit( wp_upload_dir()['basedir'] );
    305305
Note: See TracChangeset for help on using the changeset viewer.