WordPress.org

Make WordPress Core

Ticket #47678: 47678-some-unit-test-functions.patch

File 47678-some-unit-test-functions.patch, 4.1 KB (added by jrf, 7 months ago)

Simplify & modernize some unit test functions

  • tests/phpunit/includes/abstract-testcase.php

    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 { 
    909909         * @since 2.5.0
    910910         * @since 3.8.0 Moved from `Tests_Query_Conditionals` to `WP_UnitTestCase`.
    911911         *
    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.
    913913         */
    914         public function assertQueryTrue() {
     914        public function assertQueryTrue( ...$true ) {
    915915                global $wp_query;
    916                 $all  = array(
     916                $all = array(
    917917                        'is_404',
    918918                        'is_admin',
    919919                        'is_archive',
    abstract class WP_UnitTestCase_Base extends PHPUnit_Framework_TestCase { 
    944944                        'is_trackback',
    945945                        'is_year',
    946946                );
    947                 $true = func_get_args();
    948947
    949948                foreach ( $true as $true_thing ) {
    950949                        $this->assertContains( $true_thing, $all, "Unknown conditional: {$true_thing}." );
  • tests/phpunit/includes/utils.php

    diff --git a/tests/phpunit/includes/utils.php b/tests/phpunit/includes/utils.php
    index f2131ac23f..a6c963806c 100644
    a b class MockAction { 
    128128                return $arg . '_append';
    129129        }
    130130
    131         function filterall( $tag, $arg = null ) {
     131        function filterall( $tag, ...$args ) {
    132132                // this one doesn't return the result, so it's safe to use with the new 'all' filter
    133133                if ( $this->debug ) {
    134134                        dmp( __FUNCTION__, $this->current_filter() );
    135135                }
    136136
    137                 $args           = func_get_args();
    138137                $this->events[] = array(
    139138                        'filter' => __FUNCTION__,
    140139                        'tag'    => $tag,
    141                         'args'   => array_slice( $args, 1 ),
     140                        'args'   => $args,
    142141                );
    143142        }
    144143
    function xml_array_dumbdown( &$data ) { 
    300299        return $out;
    301300}
    302301
    303 function dmp() {
    304         $args = func_get_args();
    305 
     302function dmp( ...$args ) {
    306303        foreach ( $args as $thing ) {
    307304                echo ( is_scalar( $thing ) ? strval( $thing ) : var_export( $thing, true ) ), "\n";
    308305        }
  • tests/phpunit/tests/customize/manager.php

    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 { 
    25412541         * Capture the actions fired when calling WP_Customize_Manager::set_post_value().
    25422542         *
    25432543         * @see Tests_WP_Customize_Manager::test_set_post_value()
     2544         *
     2545         * @param mixed ...$args Optional arguments passed to the action.
    25442546         */
    2545         function capture_customize_post_value_set_actions() {
     2547        function capture_customize_post_value_set_actions( ...$args ) {
    25462548                $action = current_action();
    2547                 $args   = func_get_args();
    25482549                $this->captured_customize_post_value_set_actions[] = compact( 'action', 'args' );
    25492550        }
    25502551
  • tests/phpunit/tests/hooks/doAction.php

    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 { 
    164164
    165165        /**
    166166         * Use this rather than MockAction so we can test callbacks with no args
     167         *
     168         * @param mixed ...$args Optional arguments passed to the action.
    167169         */
    168         public function _action_callback() {
    169                 $args           = func_get_args();
     170        public function _action_callback( ...$args ) {
    170171                $this->events[] = array(
    171172                        'action' => __FUNCTION__,
    172173                        'args'   => $args,