From 9f899745ca25e95e8be3ce1dcacc1d841b1a4780 Mon Sep 17 00:00:00 2001
From: jrfnl <jrfnl@users.noreply.github.com>
Date: Fri, 12 Jul 2019 06:12:02 +0200
Subject: [PATCH] Simplify & modernize some unit test functions
---
tests/phpunit/includes/abstract-testcase.php | 7 +++----
tests/phpunit/includes/utils.php | 9 +++------
tests/phpunit/tests/customize/manager.php | 5 +++--
tests/phpunit/tests/hooks/doAction.php | 5 +++--
4 files changed, 12 insertions(+), 14 deletions(-)
diff --git a/tests/phpunit/includes/abstract-testcase.php b/tests/phpunit/includes/abstract-testcase.php
index 0dbcc7f45a..f1e2fdd88f 100644
|
a
|
b
|
abstract class WP_UnitTestCase_Base extends PHPUnit_Framework_TestCase { |
| 909 | 909 | * @since 2.5.0 |
| 910 | 910 | * @since 3.8.0 Moved from `Tests_Query_Conditionals` to `WP_UnitTestCase`. |
| 911 | 911 | * |
| 912 | | * @param string ...$prop Any number of WP_Query properties that are expected to be true for the current request. |
| | 912 | * @param string ...$true Any number of WP_Query properties that are expected to be true for the current request. |
| 913 | 913 | */ |
| 914 | | public function assertQueryTrue() { |
| | 914 | public function assertQueryTrue( ...$true ) { |
| 915 | 915 | global $wp_query; |
| 916 | | $all = array( |
| | 916 | $all = array( |
| 917 | 917 | 'is_404', |
| 918 | 918 | 'is_admin', |
| 919 | 919 | 'is_archive', |
| … |
… |
abstract class WP_UnitTestCase_Base extends PHPUnit_Framework_TestCase { |
| 944 | 944 | 'is_trackback', |
| 945 | 945 | 'is_year', |
| 946 | 946 | ); |
| 947 | | $true = func_get_args(); |
| 948 | 947 | |
| 949 | 948 | foreach ( $true as $true_thing ) { |
| 950 | 949 | $this->assertContains( $true_thing, $all, "Unknown conditional: {$true_thing}." ); |
diff --git a/tests/phpunit/includes/utils.php b/tests/phpunit/includes/utils.php
index f2131ac23f..a6c963806c 100644
|
a
|
b
|
class MockAction { |
| 128 | 128 | return $arg . '_append'; |
| 129 | 129 | } |
| 130 | 130 | |
| 131 | | function filterall( $tag, $arg = null ) { |
| | 131 | function filterall( $tag, ...$args ) { |
| 132 | 132 | // this one doesn't return the result, so it's safe to use with the new 'all' filter |
| 133 | 133 | if ( $this->debug ) { |
| 134 | 134 | dmp( __FUNCTION__, $this->current_filter() ); |
| 135 | 135 | } |
| 136 | 136 | |
| 137 | | $args = func_get_args(); |
| 138 | 137 | $this->events[] = array( |
| 139 | 138 | 'filter' => __FUNCTION__, |
| 140 | 139 | 'tag' => $tag, |
| 141 | | 'args' => array_slice( $args, 1 ), |
| | 140 | 'args' => $args, |
| 142 | 141 | ); |
| 143 | 142 | } |
| 144 | 143 | |
| … |
… |
function xml_array_dumbdown( &$data ) { |
| 300 | 299 | return $out; |
| 301 | 300 | } |
| 302 | 301 | |
| 303 | | function dmp() { |
| 304 | | $args = func_get_args(); |
| 305 | | |
| | 302 | function dmp( ...$args ) { |
| 306 | 303 | foreach ( $args as $thing ) { |
| 307 | 304 | echo ( is_scalar( $thing ) ? strval( $thing ) : var_export( $thing, true ) ), "\n"; |
| 308 | 305 | } |
diff --git a/tests/phpunit/tests/customize/manager.php b/tests/phpunit/tests/customize/manager.php
index f081245c6b..1cd3fddf6f 100644
|
a
|
b
|
class Tests_WP_Customize_Manager extends WP_UnitTestCase { |
| 2541 | 2541 | * Capture the actions fired when calling WP_Customize_Manager::set_post_value(). |
| 2542 | 2542 | * |
| 2543 | 2543 | * @see Tests_WP_Customize_Manager::test_set_post_value() |
| | 2544 | * |
| | 2545 | * @param mixed ...$args Optional arguments passed to the action. |
| 2544 | 2546 | */ |
| 2545 | | function capture_customize_post_value_set_actions() { |
| | 2547 | function capture_customize_post_value_set_actions( ...$args ) { |
| 2546 | 2548 | $action = current_action(); |
| 2547 | | $args = func_get_args(); |
| 2548 | 2549 | $this->captured_customize_post_value_set_actions[] = compact( 'action', 'args' ); |
| 2549 | 2550 | } |
| 2550 | 2551 | |
diff --git a/tests/phpunit/tests/hooks/doAction.php b/tests/phpunit/tests/hooks/doAction.php
index 48ced32e1d..34f90eae3a 100644
|
a
|
b
|
class Tests_WP_Hook_Do_Action extends WP_UnitTestCase { |
| 164 | 164 | |
| 165 | 165 | /** |
| 166 | 166 | * Use this rather than MockAction so we can test callbacks with no args |
| | 167 | * |
| | 168 | * @param mixed ...$args Optional arguments passed to the action. |
| 167 | 169 | */ |
| 168 | | public function _action_callback() { |
| 169 | | $args = func_get_args(); |
| | 170 | public function _action_callback( ...$args ) { |
| 170 | 171 | $this->events[] = array( |
| 171 | 172 | 'action' => __FUNCTION__, |
| 172 | 173 | 'args' => $args, |