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


git-svn-id: https://develop.svn.wordpress.org/trunk@38762 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
John Blackbourn
2016-10-09 01:11:14 +00:00
parent b45f2feada
commit c91be6f1fe
21 changed files with 105 additions and 106 deletions
+8 -8
View File
@@ -13,7 +13,7 @@ class Tests_WP_Hook_Add_Filter extends WP_UnitTestCase {
public function test_add_filter_with_function() {
$callback = '__return_null';
$hook = new WP_Hook();
$tag = rand_str();
$tag = __FUNCTION__;
$priority = rand( 1, 100 );
$accepted_args = rand( 1, 100 );
@@ -28,7 +28,7 @@ class Tests_WP_Hook_Add_Filter extends WP_UnitTestCase {
$a = new MockAction();
$callback = array( $a, 'action' );
$hook = new WP_Hook();
$tag = rand_str();
$tag = __FUNCTION__;
$priority = rand( 1, 100 );
$accepted_args = rand( 1, 100 );
@@ -42,7 +42,7 @@ class Tests_WP_Hook_Add_Filter extends WP_UnitTestCase {
public function test_add_filter_with_static_method() {
$callback = array( 'MockAction', 'action' );
$hook = new WP_Hook();
$tag = rand_str();
$tag = __FUNCTION__;
$priority = rand( 1, 100 );
$accepted_args = rand( 1, 100 );
@@ -57,7 +57,7 @@ class Tests_WP_Hook_Add_Filter extends WP_UnitTestCase {
$callback_one = '__return_null';
$callback_two = '__return_false';
$hook = new WP_Hook();
$tag = rand_str();
$tag = __FUNCTION__;
$priority = rand( 1, 100 );
$accepted_args = rand( 1, 100 );
@@ -72,7 +72,7 @@ class Tests_WP_Hook_Add_Filter extends WP_UnitTestCase {
$callback_one = '__return_null';
$callback_two = '__return_false';
$hook = new WP_Hook();
$tag = rand_str();
$tag = __FUNCTION__;
$priority = rand( 1, 100 );
$accepted_args = rand( 1, 100 );
@@ -87,7 +87,7 @@ class Tests_WP_Hook_Add_Filter extends WP_UnitTestCase {
public function test_readd_filter() {
$callback = '__return_null';
$hook = new WP_Hook();
$tag = rand_str();
$tag = __FUNCTION__;
$priority = rand( 1, 100 );
$accepted_args = rand( 1, 100 );
@@ -101,7 +101,7 @@ class Tests_WP_Hook_Add_Filter extends WP_UnitTestCase {
public function test_readd_filter_with_different_priority() {
$callback = '__return_null';
$hook = new WP_Hook();
$tag = rand_str();
$tag = __FUNCTION__;
$priority = rand( 1, 100 );
$accepted_args = rand( 1, 100 );
@@ -118,7 +118,7 @@ class Tests_WP_Hook_Add_Filter extends WP_UnitTestCase {
$b = new MockAction();
$c = new MockAction();
$hook = new WP_Hook();
$tag = rand_str();
$tag = __FUNCTION__;
$hook->add_filter( $tag, array( $a, 'action' ), 10, 1 );
$hook->add_filter( $tag, array( $b, 'action' ), 5, 1 );
+4 -4
View File
@@ -11,10 +11,10 @@ class Tests_WP_Hook_Apply_Filters extends WP_UnitTestCase {
$a = new MockAction();
$callback = array( $a, 'filter' );
$hook = new WP_Hook();
$tag = rand_str();
$tag = __FUNCTION__;
$priority = rand( 1, 100 );
$accepted_args = rand( 1, 100 );
$arg = rand_str();
$arg = __FUNCTION__ . '_arg';
$hook->add_filter( $tag, $callback, $priority, $accepted_args );
@@ -28,10 +28,10 @@ class Tests_WP_Hook_Apply_Filters extends WP_UnitTestCase {
$a = new MockAction();
$callback = array( $a, 'filter' );
$hook = new WP_Hook();
$tag = rand_str();
$tag = __FUNCTION__;
$priority = rand( 1, 100 );
$accepted_args = rand( 1, 100 );
$arg = rand_str();
$arg = __FUNCTION__ . '_arg';
$hook->add_filter( $tag, $callback, $priority, $accepted_args );
+14 -14
View File
@@ -19,10 +19,10 @@ class Tests_WP_Hook_Do_Action extends WP_UnitTestCase {
$a = new MockAction();
$callback = array( $a, 'action' );
$hook = new WP_Hook();
$tag = rand_str();
$tag = __FUNCTION__;
$priority = rand( 1, 100 );
$accepted_args = rand( 1, 100 );
$arg = rand_str();
$arg = __FUNCTION__ . '_arg';
$hook->add_filter( $tag, $callback, $priority, $accepted_args );
$hook->do_action( array( $arg ) );
@@ -34,10 +34,10 @@ class Tests_WP_Hook_Do_Action extends WP_UnitTestCase {
$a = new MockAction();
$callback = array( $a, 'filter' );
$hook = new WP_Hook();
$tag = rand_str();
$tag = __FUNCTION__;
$priority = rand( 1, 100 );
$accepted_args = rand( 1, 100 );
$arg = rand_str();
$arg = __FUNCTION__ . '_arg';
$hook->add_filter( $tag, $callback, $priority, $accepted_args );
$hook->do_action( array( $arg ) );
@@ -52,10 +52,10 @@ class Tests_WP_Hook_Do_Action extends WP_UnitTestCase {
$callback_one = array( $a, 'filter' );
$callback_two = array( $b, 'filter' );
$hook = new WP_Hook();
$tag = rand_str();
$tag = __FUNCTION__;
$priority = rand( 1, 100 );
$accepted_args = rand( 1, 100 );
$arg = rand_str();
$arg = __FUNCTION__ . '_arg';
$hook->add_filter( $tag, $callback_one, $priority, $accepted_args );
$hook->add_filter( $tag, $callback_two, $priority, $accepted_args );
@@ -71,10 +71,10 @@ class Tests_WP_Hook_Do_Action extends WP_UnitTestCase {
$callback_one = array( $a, 'filter' );
$callback_two = array( $b, 'filter' );
$hook = new WP_Hook();
$tag = rand_str();
$tag = __FUNCTION__;
$priority = rand( 1, 100 );
$accepted_args = rand( 1, 100 );
$arg = rand_str();
$arg = __FUNCTION__ . '_arg';
$hook->add_filter( $tag, $callback_one, $priority, $accepted_args );
$hook->add_filter( $tag, $callback_two, $priority, $accepted_args );
@@ -87,10 +87,10 @@ class Tests_WP_Hook_Do_Action extends WP_UnitTestCase {
public function test_do_action_with_no_accepted_args() {
$callback = array( $this, '_action_callback' );
$hook = new WP_Hook();
$tag = rand_str();
$tag = __FUNCTION__;
$priority = rand( 1, 100 );
$accepted_args = 0;
$arg = rand_str();
$arg = __FUNCTION__ . '_arg';
$hook->add_filter( $tag, $callback, $priority, $accepted_args );
$hook->do_action( array( $arg ) );
@@ -101,10 +101,10 @@ class Tests_WP_Hook_Do_Action extends WP_UnitTestCase {
public function test_do_action_with_one_accepted_arg() {
$callback = array( $this, '_action_callback' );
$hook = new WP_Hook();
$tag = rand_str();
$tag = __FUNCTION__;
$priority = rand( 1, 100 );
$accepted_args = 1;
$arg = rand_str();
$arg = __FUNCTION__ . '_arg';
$hook->add_filter( $tag, $callback, $priority, $accepted_args );
$hook->do_action( array( $arg ) );
@@ -115,10 +115,10 @@ class Tests_WP_Hook_Do_Action extends WP_UnitTestCase {
public function test_do_action_with_more_accepted_args() {
$callback = array( $this, '_action_callback' );
$hook = new WP_Hook();
$tag = rand_str();
$tag = __FUNCTION__;
$priority = rand( 1, 100 );
$accepted_args = 1000;
$arg = rand_str();
$arg = __FUNCTION__ . '_arg';
$hook->add_filter( $tag, $callback, $priority, $accepted_args );
$hook->do_action( array( $arg ) );
+1 -1
View File
@@ -14,7 +14,7 @@ class Tests_WP_Hook_Do_All_Hook extends WP_UnitTestCase {
$tag = 'all';
$priority = rand( 1, 100 );
$accepted_args = rand( 1, 100 );
$arg = rand_str();
$arg = 'all_arg';
$hook->add_filter( $tag, $callback, $priority, $accepted_args );
$args = array( $arg );
+6 -6
View File
@@ -10,7 +10,7 @@ class Tests_WP_Hook_Has_Filter extends WP_UnitTestCase {
public function test_has_filter_with_function() {
$callback = '__return_null';
$hook = new WP_Hook();
$tag = rand_str();
$tag = __FUNCTION__;
$priority = rand( 1, 100 );
$accepted_args = rand( 1, 100 );
@@ -23,7 +23,7 @@ class Tests_WP_Hook_Has_Filter extends WP_UnitTestCase {
$a = new MockAction();
$callback = array( $a, 'action' );
$hook = new WP_Hook();
$tag = rand_str();
$tag = __FUNCTION__;
$priority = rand( 1, 100 );
$accepted_args = rand( 1, 100 );
@@ -35,7 +35,7 @@ class Tests_WP_Hook_Has_Filter extends WP_UnitTestCase {
public function test_has_filter_with_static_method() {
$callback = array( 'MockAction', 'action' );
$hook = new WP_Hook();
$tag = rand_str();
$tag = __FUNCTION__;
$priority = rand( 1, 100 );
$accepted_args = rand( 1, 100 );
@@ -47,7 +47,7 @@ class Tests_WP_Hook_Has_Filter extends WP_UnitTestCase {
public function test_has_filter_without_callback() {
$callback = '__return_null';
$hook = new WP_Hook();
$tag = rand_str();
$tag = __FUNCTION__;
$priority = rand( 1, 100 );
$accepted_args = rand( 1, 100 );
@@ -64,7 +64,7 @@ class Tests_WP_Hook_Has_Filter extends WP_UnitTestCase {
public function test_not_has_filter_with_callback() {
$callback = '__return_null';
$hook = new WP_Hook();
$tag = rand_str();
$tag = __FUNCTION__;
$this->assertFalse( $hook->has_filter( $tag, $callback ) );
}
@@ -72,7 +72,7 @@ class Tests_WP_Hook_Has_Filter extends WP_UnitTestCase {
public function test_has_filter_with_wrong_callback() {
$callback = '__return_null';
$hook = new WP_Hook();
$tag = rand_str();
$tag = __FUNCTION__;
$priority = rand( 1, 100 );
$accepted_args = rand( 1, 100 );
+3 -3
View File
@@ -10,7 +10,7 @@ class Tests_WP_Hook_Has_Filters extends WP_UnitTestCase {
public function test_has_filters_with_callback() {
$callback = '__return_null';
$hook = new WP_Hook();
$tag = rand_str();
$tag = __FUNCTION__;
$priority = rand( 1, 100 );
$accepted_args = rand( 1, 100 );
@@ -27,7 +27,7 @@ class Tests_WP_Hook_Has_Filters extends WP_UnitTestCase {
public function test_not_has_filters_with_removed_callback() {
$callback = '__return_null';
$hook = new WP_Hook();
$tag = rand_str();
$tag = __FUNCTION__;
$priority = rand( 1, 100 );
$accepted_args = rand( 1, 100 );
@@ -39,7 +39,7 @@ class Tests_WP_Hook_Has_Filters extends WP_UnitTestCase {
public function test_not_has_filter_with_directly_removed_callback() {
$callback = '__return_null';
$hook = new WP_Hook();
$tag = rand_str();
$tag = __FUNCTION__;
$priority = rand( 1, 100 );
$accepted_args = rand( 1, 100 );
+1 -1
View File
@@ -11,7 +11,7 @@ class Tests_WP_Hook_Iterator extends WP_UnitTestCase {
$callback_one = '__return_null';
$callback_two = '__return_false';
$hook = new WP_Hook();
$tag = rand_str();
$tag = __FUNCTION__;
$priority = rand( 1, 100 );
$accepted_args = rand( 1, 100 );
+2 -2
View File
@@ -8,9 +8,9 @@
class Tests_WP_Hook_Preinit_Hooks extends WP_UnitTestCase {
public function test_array_to_hooks() {
$tag1 = rand_str();
$tag1 = __FUNCTION__ . '_1';
$priority1 = rand( 1, 100 );
$tag2 = rand_str();
$tag2 = __FUNCTION__ . '_2';
$priority2 = rand( 1, 100 );
$filters = array(
$tag1 => array(
@@ -10,7 +10,7 @@ class Tests_WP_Hook_Remove_All_Filters extends WP_UnitTestCase {
public function test_remove_all_filters() {
$callback = '__return_null';
$hook = new WP_Hook();
$tag = rand_str();
$tag = __FUNCTION__;
$priority = rand( 1, 100 );
$accepted_args = rand( 1, 100 );
@@ -25,7 +25,7 @@ class Tests_WP_Hook_Remove_All_Filters extends WP_UnitTestCase {
$callback_one = '__return_null';
$callback_two = '__return_false';
$hook = new WP_Hook();
$tag = rand_str();
$tag = __FUNCTION__;
$priority = rand( 1, 100 );
$accepted_args = rand( 1, 100 );
+5 -5
View File
@@ -10,7 +10,7 @@ class Tests_WP_Hook_Remove_Filter extends WP_UnitTestCase {
public function test_remove_filter_with_function() {
$callback = '__return_null';
$hook = new WP_Hook();
$tag = rand_str();
$tag = __FUNCTION__;
$priority = rand( 1, 100 );
$accepted_args = rand( 1, 100 );
@@ -24,7 +24,7 @@ class Tests_WP_Hook_Remove_Filter extends WP_UnitTestCase {
$a = new MockAction();
$callback = array( $a, 'action' );
$hook = new WP_Hook();
$tag = rand_str();
$tag = __FUNCTION__;
$priority = rand( 1, 100 );
$accepted_args = rand( 1, 100 );
@@ -37,7 +37,7 @@ class Tests_WP_Hook_Remove_Filter extends WP_UnitTestCase {
public function test_remove_filter_with_static_method() {
$callback = array( 'MockAction', 'action' );
$hook = new WP_Hook();
$tag = rand_str();
$tag = __FUNCTION__;
$priority = rand( 1, 100 );
$accepted_args = rand( 1, 100 );
@@ -51,7 +51,7 @@ class Tests_WP_Hook_Remove_Filter extends WP_UnitTestCase {
$callback_one = '__return_null';
$callback_two = '__return_false';
$hook = new WP_Hook();
$tag = rand_str();
$tag = __FUNCTION__;
$priority = rand( 1, 100 );
$accepted_args = rand( 1, 100 );
@@ -67,7 +67,7 @@ class Tests_WP_Hook_Remove_Filter extends WP_UnitTestCase {
$callback_one = '__return_null';
$callback_two = '__return_false';
$hook = new WP_Hook();
$tag = rand_str();
$tag = __FUNCTION__;
$priority = rand( 1, 100 );
$accepted_args = rand( 1, 100 );