WordPress.org

Make WordPress Core

Ticket #47678: 47678-select-unit-tests.patch

File 47678-select-unit-tests.patch, 1.7 KB (added by jrf, 8 months ago)

Simplify & modernize select unit tests

  • tests/phpunit/tests/db.php

    From 46d8e235ddb6f3c96982e1235e7f68a867f62d33 Mon Sep 17 00:00:00 2001
    From: jrfnl <jrfnl@users.noreply.github.com>
    Date: Sat, 20 Jul 2019 20:27:23 +0200
    Subject: [PATCH] Simplify & modernize select unit tests
    
    ---
     tests/phpunit/tests/db.php | 15 ++++++---------
     1 file changed, 6 insertions(+), 9 deletions(-)
    
    diff --git a/tests/phpunit/tests/db.php b/tests/phpunit/tests/db.php
    index 0583ae132a..842246528d 100644
    a b class Tests_DB extends WP_UnitTestCase { 
    422422        public function test_prepare_incorrect_arg_count( $query, $args, $expected ) {
    423423                global $wpdb;
    424424
    425                 // $query is the first argument to be passed to wpdb::prepare()
    426                 array_unshift( $args, $query );
    427 
    428                 // phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged
    429                 $prepared = @call_user_func_array( array( $wpdb, 'prepare' ), $args );
     425                // phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged,WordPress.DB.PreparedSQL
     426                $prepared = @$wpdb->prepare( $query, ...$args );
    430427                $this->assertEquals( $expected, $prepared );
    431428        }
    432429
    class Tests_DB extends WP_UnitTestCase { 
    13661363                        $values = array( $values );
    13671364                }
    13681365
    1369                 array_unshift( $values, $sql );
    1370 
    1371                 $sql = call_user_func_array( array( $wpdb, 'prepare' ), $values );
     1366                // phpcs:ignore WordPress.DB.PreparedSQL
     1367                $sql = $wpdb->prepare( $sql, ...$values );
    13721368                $this->assertEquals( $expected, $sql );
    13731369        }
    13741370
    class Tests_DB extends WP_UnitTestCase { 
    13861382                        $values = array( $values );
    13871383                }
    13881384
    1389                 $sql = call_user_func_array( array( $wpdb, 'prepare' ), array( $sql, $values ) );
     1385                // phpcs:ignore WordPress.DB.PreparedSQL
     1386                $sql = $wpdb->prepare( $sql, $values );
    13901387                $this->assertEquals( $expected, $sql );
    13911388        }
    13921389