Make WordPress Core


Ignore:
Timestamp:
11/30/2017 11:09:33 PM (8 years ago)
Author:
pento
Message:

Code is Poetry.
WordPress' code just... wasn't.
This is now dealt with.

Props jrf, pento, netweb, GaryJ, jdgrimes, westonruter, Greg Sherwood from PHPCS, and everyone who's ever contributed to WPCS and PHPCS.
Fixes #41057.

File:
1 edited

Legend:

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

    r40347 r42343  
    2222        global $wp_object_cache;
    2323        $cache_class = get_class( $wp_object_cache );
    24         $cache = new $cache_class();
     24        $cache       = new $cache_class();
    2525        $cache->add_global_groups( array( 'global-cache-test', 'users', 'userlogins', 'usermeta', 'user_meta', 'useremail', 'userslugs', 'site-transient', 'site-options', 'blog-lookup', 'blog-details', 'rss', 'global-posts', 'blog-id-cache', 'networks', 'sites', 'site-details' ) );
    2626        return $cache;
     
    2828
    2929    function test_miss() {
    30         $this->assertEquals( NULL, $this->cache->get( 'test_miss' ) );
     30        $this->assertEquals( null, $this->cache->get( 'test_miss' ) );
    3131    }
    3232
     
    3535        $val = 'val';
    3636
    37         $this->cache->add($key, $val);
    38         $this->assertEquals($val, $this->cache->get($key));
     37        $this->cache->add( $key, $val );
     38        $this->assertEquals( $val, $this->cache->get( $key ) );
    3939    }
    4040
     
    4444
    4545        // you can store zero in the cache
    46         $this->cache->add($key, $val);
    47         $this->assertEquals($val, $this->cache->get($key));
     46        $this->cache->add( $key, $val );
     47        $this->assertEquals( $val, $this->cache->get( $key ) );
    4848    }
    4949
     
    5252        $val = null;
    5353
    54         $this->assertTrue( $this->cache->add($key, $val) );
     54        $this->assertTrue( $this->cache->add( $key, $val ) );
    5555        // null is converted to empty string
    56         $this->assertEquals( '', $this->cache->get($key) );
     56        $this->assertEquals( '', $this->cache->get( $key ) );
    5757    }
    5858
    5959    function test_add() {
    60         $key = __FUNCTION__;
     60        $key  = __FUNCTION__;
    6161        $val1 = 'val1';
    6262        $val2 = 'val2';
    6363
    6464        // add $key to the cache
    65         $this->assertTrue($this->cache->add($key, $val1));
    66         $this->assertEquals($val1, $this->cache->get($key));
     65        $this->assertTrue( $this->cache->add( $key, $val1 ) );
     66        $this->assertEquals( $val1, $this->cache->get( $key ) );
    6767        // $key is in the cache, so reject new calls to add()
    68         $this->assertFalse($this->cache->add($key, $val2));
    69         $this->assertEquals($val1, $this->cache->get($key));
     68        $this->assertFalse( $this->cache->add( $key, $val2 ) );
     69        $this->assertEquals( $val1, $this->cache->get( $key ) );
    7070    }
    7171
    7272    function test_replace() {
    73         $key = __FUNCTION__;
    74         $val = 'val1';
     73        $key  = __FUNCTION__;
     74        $val  = 'val1';
    7575        $val2 = 'val2';
    7676
    7777        // memcached rejects replace() if the key does not exist
    78         $this->assertFalse($this->cache->replace($key, $val));
    79         $this->assertFalse($this->cache->get($key));
    80         $this->assertTrue($this->cache->add($key, $val));
    81         $this->assertEquals($val, $this->cache->get($key));
    82         $this->assertTrue($this->cache->replace($key, $val2));
    83         $this->assertEquals($val2, $this->cache->get($key));
     78        $this->assertFalse( $this->cache->replace( $key, $val ) );
     79        $this->assertFalse( $this->cache->get( $key ) );
     80        $this->assertTrue( $this->cache->add( $key, $val ) );
     81        $this->assertEquals( $val, $this->cache->get( $key ) );
     82        $this->assertTrue( $this->cache->replace( $key, $val2 ) );
     83        $this->assertEquals( $val2, $this->cache->get( $key ) );
    8484    }
    8585
    8686    function test_set() {
    87         $key = __FUNCTION__;
     87        $key  = __FUNCTION__;
    8888        $val1 = 'val1';
    8989        $val2 = 'val2';
    9090
    9191        // memcached accepts set() if the key does not exist
    92         $this->assertTrue($this->cache->set($key, $val1));
    93         $this->assertEquals($val1, $this->cache->get($key));
     92        $this->assertTrue( $this->cache->set( $key, $val1 ) );
     93        $this->assertEquals( $val1, $this->cache->get( $key ) );
    9494        // Second set() with same key should be allowed
    95         $this->assertTrue($this->cache->set($key, $val2));
    96         $this->assertEquals($val2, $this->cache->get($key));
     95        $this->assertTrue( $this->cache->set( $key, $val2 ) );
     96        $this->assertEquals( $val2, $this->cache->get( $key ) );
    9797    }
    9898
     
    100100        global $_wp_using_ext_object_cache;
    101101
    102         if ( $_wp_using_ext_object_cache )
     102        if ( $_wp_using_ext_object_cache ) {
    103103            return;
     104        }
    104105
    105106        $key = __FUNCTION__;
    106107        $val = 'val';
    107108
    108         $this->cache->add($key, $val);
     109        $this->cache->add( $key, $val );
    109110        // item is visible to both cache objects
    110         $this->assertEquals($val, $this->cache->get($key));
     111        $this->assertEquals( $val, $this->cache->get( $key ) );
    111112        $this->cache->flush();
    112113        // If there is no value get returns false.
    113         $this->assertFalse($this->cache->get($key));
     114        $this->assertFalse( $this->cache->get( $key ) );
    114115    }
    115116
    116117    // Make sure objects are cloned going to and from the cache
    117118    function test_object_refs() {
    118         $key = __FUNCTION__ . '_1';
    119         $object_a = new stdClass;
     119        $key           = __FUNCTION__ . '_1';
     120        $object_a      = new stdClass;
    120121        $object_a->foo = 'alpha';
    121122        $this->cache->set( $key, $object_a );
    122123        $object_a->foo = 'bravo';
    123         $object_b = $this->cache->get( $key );
     124        $object_b      = $this->cache->get( $key );
    124125        $this->assertEquals( 'alpha', $object_b->foo );
    125126        $object_b->foo = 'charlie';
    126127        $this->assertEquals( 'bravo', $object_a->foo );
    127128
    128         $key = __FUNCTION__ . '_2';
    129         $object_a = new stdClass;
     129        $key           = __FUNCTION__ . '_2';
     130        $object_a      = new stdClass;
    130131        $object_a->foo = 'alpha';
    131132        $this->cache->add( $key, $object_a );
    132133        $object_a->foo = 'bravo';
    133         $object_b = $this->cache->get( $key );
     134        $object_b      = $this->cache->get( $key );
    134135        $this->assertEquals( 'alpha', $object_b->foo );
    135136        $object_b->foo = 'charlie';
     
    212213        $this->assertFalse( $this->cache->get( $key ) );
    213214
    214         $this->assertFalse( $this->cache->delete( $key, 'default') );
     215        $this->assertFalse( $this->cache->delete( $key, 'default' ) );
    215216    }
    216217
     
    231232        // $this->assertTrue( wp_cache_delete( $key, 'default', true ) );
    232233
    233         $this->assertFalse( wp_cache_delete( $key, 'default') );
     234        $this->assertFalse( wp_cache_delete( $key, 'default' ) );
    234235    }
    235236
    236237    function test_switch_to_blog() {
    237         if ( ! method_exists( $this->cache, 'switch_to_blog' ) )
     238        if ( ! method_exists( $this->cache, 'switch_to_blog' ) ) {
    238239            return;
    239 
    240         $key = __FUNCTION__;
    241         $val = 'val1';
     240        }
     241
     242        $key  = __FUNCTION__;
     243        $val  = 'val1';
    242244        $val2 = 'val2';
    243245
     
    287289        if ( wp_using_ext_object_cache() ) {
    288290            // External caches will contain property values that contain non-matching resource IDs
    289             $this->assertInstanceOf( 'WP_Object_Cache', $wp_object_cache  );
     291            $this->assertInstanceOf( 'WP_Object_Cache', $wp_object_cache );
    290292        } else {
    291293            $this->assertEquals( $wp_object_cache, $new_blank_cache_object );
Note: See TracChangeset for help on using the changeset viewer.