Make WordPress Core


Ignore:
Timestamp:
10/09/2016 01:11:14 AM (8 years ago)
Author:
johnbillion
Message:

Build/Test Tools: Begin eliminating unnecessary randomness in tests.

Although unlikely, clashes in randomly generated strings could cause unexpected failures. In addition, most randomness is entirely unnecessary, is bad practice, and increases test time (however small it may be).

See #37371

File:
1 edited

Legend:

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

    r38571 r38762  
    1010    function test_simple_filter() {
    1111        $a = new MockAction();
    12         $tag = rand_str();
    13         $val = rand_str();
     12        $tag = __FUNCTION__;
     13        $val = __FUNCTION__ . '_val';
    1414
    1515        add_filter($tag, array($a, 'filter'));
     
    2828    function test_remove_filter() {
    2929        $a = new MockAction();
    30         $tag = rand_str();
    31         $val = rand_str();
     30        $tag = __FUNCTION__;
     31        $val = __FUNCTION__ . '_val';
    3232
    3333        add_filter($tag, array($a, 'filter'));
     
    4747
    4848    function test_has_filter() {
    49             $tag = rand_str();
    50             $func = rand_str();
     49            $tag  = __FUNCTION__;
     50            $func = __FUNCTION__ . '_func';
    5151
    5252            $this->assertFalse( has_filter($tag, $func) );
     
    6464        $a1 = new MockAction();
    6565        $a2 = new MockAction();
    66         $tag = rand_str();
    67         $val = rand_str();
     66        $tag = __FUNCTION__;
     67        $val = __FUNCTION__ . '_val';
    6868
    6969        // add both filters to the hook
     
    8080    function test_filter_args_1() {
    8181        $a = new MockAction();
    82         $tag = rand_str();
    83         $val = rand_str();
    84         $arg1 = rand_str();
     82        $tag  = __FUNCTION__;
     83        $val  = __FUNCTION__ . '_val';
     84        $arg1 = __FUNCTION__ . '_arg1';
    8585
    8686        add_filter($tag, array($a, 'filter'), 10, 2);
     
    9696        $a1 = new MockAction();
    9797        $a2 = new MockAction();
    98         $tag = rand_str();
    99         $val = rand_str();
    100         $arg1 = rand_str();
    101         $arg2 = rand_str();
     98        $tag  = __FUNCTION__;
     99        $val  = __FUNCTION__ . '_val';
     100        $arg1 = __FUNCTION__ . '_arg1';
     101        $arg2 = __FUNCTION__ . '_arg2';
    102102
    103103        // a1 accepts two arguments, a2 doesn't
     
    120120    function test_filter_priority() {
    121121        $a = new MockAction();
    122         $tag = rand_str();
    123         $val = rand_str();
     122        $tag = __FUNCTION__;
     123        $val = __FUNCTION__ . '_val';
    124124
    125125        // make two filters with different priorities
     
    151151    function test_all_filter() {
    152152        $a = new MockAction();
    153         $tag1 = rand_str();
    154         $tag2 = rand_str();
    155         $val = rand_str();
     153        $tag1 = __FUNCTION__ . '_1';
     154        $tag2 = __FUNCTION__ . '_2';
     155        $val  = __FUNCTION__ . '_val';
    156156
    157157        // add an 'all' filter
     
    175175    function test_remove_all_filter() {
    176176        $a = new MockAction();
    177         $tag = rand_str();
    178         $val = rand_str();
     177        $tag = __FUNCTION__;
     178        $val = __FUNCTION__ . '_val';
    179179
    180180        add_filter('all', array($a, 'filterall'));
     
    202202    function test_remove_all_filters_should_respect_the_priority_argument() {
    203203        $a = new MockAction();
    204         $tag = rand_str();
    205         $val = rand_str();
     204        $tag = __FUNCTION__;
     205        $val = __FUNCTION__ . '_val';
    206206
    207207        add_filter( $tag, array( $a, 'filter' ), 12 );
     
    222222        $obj = new stdClass();
    223223        $a = new MockAction();
    224         $tag = rand_str();
     224        $tag = __FUNCTION__;
    225225
    226226        add_action($tag, array($a, 'filter'));
     
    242242        $a = new MockAction();
    243243        $b = new MockAction();
    244         $tag = rand_str();
     244        $tag = __FUNCTION__;
    245245
    246246        add_action($tag, array($a, 'filter_append'), 10, 2);
     
    275275    function test_has_filter_after_remove_all_filters() {
    276276        $a = new MockAction();
    277         $tag = rand_str();
    278         $val = rand_str();
     277        $tag = __FUNCTION__;
     278        $val = __FUNCTION__ . '_val';
    279279
    280280        // No priority
Note: See TracChangeset for help on using the changeset viewer.