Making WordPress.org


Ignore:
Timestamp:
06/08/2017 08:18:20 PM (8 years ago)
Author:
iandunn
Message:

Events: Replace object caching with stubs when running tests

Previously the object cache was enabled during tests, but it was bypassed by adding a cachebuster to the input. That was broken by r5552, because the cache keys are no longer built with the entire input. It wasn't immediately apparent, because the tests continued to pass as expected.

This commit changes that approach, so that the tests never load the object cache in the first place, and simply stub its functions instead.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/api.wordpress.org/public_html/events/1.0/tests/test-index.php

    r5549 r5558  
    5959
    6060/**
    61  * Add a cachebusting parameter to bypass the object cache
    62  *
    63  * Cache keys are generated based on the function's input arguments (e.g., get_location()), so adding a unique
    64  * parameter on every function call ensures that the unit tests will never get a cached result.
    65  *
    66  * @param array $arguments
    67  *
    68  * @return array
    69  */
    70 function add_cachebusting_parameter( $arguments ) {
    71     $arguments['cachebuster'] = microtime( true );
    72 
    73     return $arguments;
    74 }
    75 
    76 /**
    7761 * Test `get_location()`
    7862 *
     
    8670
    8771    foreach ( $cases as $case_id => $case ) {
    88         $case['input'] = add_cachebusting_parameter( $case['input'] );
    8972        $actual_result = get_location( $case['input'] );
    9073
     
    860843}
    861844
     845/**
     846 * Stub to simulate cache misses, so that the tests always get fresh results
     847 *
     848 * @return false
     849 */
     850function wp_cache_get() {
     851    return false;
     852}
     853
     854/**
     855 * Stub to simulate cache misses, so that the tests always get fresh results
     856 */
     857function wp_cache_set() {
     858    // Intentionally empty
     859}
     860
    862861run_tests();
Note: See TracChangeset for help on using the changeset viewer.