Make WordPress Core

Ticket #48074: 48074-tests-Remove-work-arounds-for-PHP-5.6.patch

File 48074-tests-Remove-work-arounds-for-PHP-5.6.patch, 8.5 KB (added by jrf, 5 years ago)

Same as the previous patch, but now for the unit tests.

  • tests/phpunit/includes/utils.php

    From 1a400a063032c90ac07b8f6916a18cc5f3f9a547 Mon Sep 17 00:00:00 2001
    From: jrfnl <jrfnl@users.noreply.github.com>
    Date: Sat, 27 Jul 2019 01:32:47 +0200
    Subject: [PATCH] [tests] Remove work-arounds for PHP < 5.6
    
    ---
     tests/phpunit/includes/utils.php                     | 8 ++------
     tests/phpunit/tests/admin/wpPrivacyRequestsTable.php | 4 ----
     tests/phpunit/tests/compat.php                       | 5 -----
     tests/phpunit/tests/customize/nav-menus.php          | 4 +---
     tests/phpunit/tests/db/charset.php                   | 4 ----
     tests/phpunit/tests/functions.php                    | 4 ----
     tests/phpunit/tests/post/query.php                   | 5 -----
     tests/phpunit/tests/rest-api/rest-request.php        | 8 --------
     tests/phpunit/tests/theme/customHeader.php           | 9 ---------
     tests/phpunit/tests/widgets/media-widget.php         | 5 -----
     10 files changed, 3 insertions(+), 53 deletions(-)
    
    diff --git a/tests/phpunit/includes/utils.php b/tests/phpunit/includes/utils.php
    index a213bce0d0..9a03250f6a 100644
    a b class WpdbExposedMethodsForTesting extends wpdb { 
    465465function benchmark_pcre_backtracking( $pattern, $subject, $strategy ) {
    466466        $saved_config = ini_get( 'pcre.backtrack_limit' );
    467467
    468         // Attempt to prevent PHP crashes.  Adjust these lower when needed.
    469         if ( version_compare( phpversion(), '5.4.8', '>' ) ) {
    470                 $limit = 1000000;
    471         } else {
    472                 $limit = 20000;  // 20,000 is a reasonable upper limit, but see also https://core.trac.wordpress.org/ticket/29557#comment:10
    473         }
     468        // Attempt to prevent PHP crashes. Adjust these lower when needed.
     469        $limit = 1000000;
    474470
    475471        // Start with small numbers, so if a crash is encountered at higher numbers we can still debug the problem.
    476472        for ( $i = 4; $i <= $limit; $i *= 2 ) {
  • tests/phpunit/tests/admin/wpPrivacyRequestsTable.php

    diff --git a/tests/phpunit/tests/admin/wpPrivacyRequestsTable.php b/tests/phpunit/tests/admin/wpPrivacyRequestsTable.php
    index 9c9be20f92..debe163862 100644
    a b class Tests_Admin_WpPrivacyRequestsTable extends WP_UnitTestCase { 
    2424         * @return PHPUnit_Framework_MockObject_MockObject|WP_Privacy_Requests_Table $instance Mocked class instance.
    2525         */
    2626        public function get_mocked_class_instance() {
    27                 if ( version_compare( PHP_VERSION, '5.3', '<' ) ) {
    28                         $this->markTestSkipped( 'ReflectionMethod::setAccessible is only available in PHP 5.3+' );
    29                 }
    30 
    3127                $args = array(
    3228                        'plural'   => 'privacy_requests',
    3329                        'singular' => 'privacy_request',
  • tests/phpunit/tests/compat.php

    diff --git a/tests/phpunit/tests/compat.php b/tests/phpunit/tests/compat.php
    index d70d0271b1..a0797317cc 100644
    a b EOT; 
    246246                        $this->markTestSkipped( 'The intl extension is not loaded. ResourceBundle not tested for is_countable().' );
    247247                }
    248248
    249                 if ( version_compare( PHP_VERSION, '5.4', '<' ) ) {
    250                         $this->markTestSkipped( 'ResourceBundle is only countable in PHP 5.4+' );
    251                         return;
    252                 }
    253 
    254249                $this->assertTrue( is_countable( new ResourceBundle( 'en', null ) ) );
    255250        }
    256251
  • tests/phpunit/tests/customize/nav-menus.php

    diff --git a/tests/phpunit/tests/customize/nav-menus.php b/tests/phpunit/tests/customize/nav-menus.php
    index e7387773ac..1de6047097 100644
    a b class Test_WP_Customize_Nav_Menus extends WP_UnitTestCase { 
    10831083                );
    10841084
    10851085                // Add global namespace prefix to check #41488.
    1086                 if ( version_compare( PHP_VERSION, '5.3', '>=' ) ) {
    1087                         $original_args['fallback_cb'] = '\\' . $original_args['fallback_cb'];
    1088                 }
     1086                $original_args['fallback_cb'] = '\\' . $original_args['fallback_cb'];
    10891087
    10901088                $args = $menus->filter_wp_nav_menu_args( $original_args );
    10911089
  • tests/phpunit/tests/db/charset.php

    diff --git a/tests/phpunit/tests/db/charset.php b/tests/phpunit/tests/db/charset.php
    index 3089ec9a74..dc7f7c3b8f 100644
    a b class Tests_DB_Charset extends WP_UnitTestCase { 
    482482         * @ticket 21212
    483483         */
    484484        function test_strip_invalid_text( $data, $expected, $message ) {
    485                 if ( version_compare( PHP_VERSION, '5.3', '<' ) && stristr( php_uname( 's' ), 'win' ) ) {
    486                         $this->markTestSkipped( 'This test fails in PHP 5.2 on Windows. See https://core.trac.wordpress.org/ticket/31262' );
    487                 }
    488 
    489485                $charset = self::$_wpdb->charset;
    490486                if ( isset( $data[0]['connection_charset'] ) ) {
    491487                        $new_charset = $data[0]['connection_charset'];
  • tests/phpunit/tests/functions.php

    diff --git a/tests/phpunit/tests/functions.php b/tests/phpunit/tests/functions.php
    index 2191af7ddb..dd29c779e5 100644
    a b class Tests_Functions extends WP_UnitTestCase { 
    918918         * @ticket 28786
    919919         */
    920920        function test_wp_json_encode_depth() {
    921                 if ( version_compare( PHP_VERSION, '5.5', '<' ) ) {
    922                         $this->markTestSkipped( 'json_encode() supports the $depth parameter in PHP 5.5+' );
    923                 };
    924 
    925921                $data = array( array( array( 1, 2, 3 ) ) );
    926922                $json = wp_json_encode( $data, 0, 1 );
    927923                $this->assertFalse( $json );
  • tests/phpunit/tests/post/query.php

    diff --git a/tests/phpunit/tests/post/query.php b/tests/phpunit/tests/post/query.php
    index 7388dc24b7..4bac94c1bc 100644
    a b class Tests_Post_Query extends WP_UnitTestCase { 
    705705         * @dataProvider set_found_posts_provider
    706706         */
    707707        public function test_set_found_posts_not_posts_as_an_array( $posts, $expected ) {
    708                 if ( version_compare( PHP_VERSION, '5.3', '<' ) ) {
    709                         $this->markTestSkipped( 'ReflectionMethod::setAccessible is only available in PHP 5.3+' );
    710                         return;
    711                 }
    712 
    713708                $q = new WP_Query(
    714709                        array(
    715710                                'post_type'      => 'wptests_pt',
  • tests/phpunit/tests/rest-api/rest-request.php

    diff --git a/tests/phpunit/tests/rest-api/rest-request.php b/tests/phpunit/tests/rest-api/rest-request.php
    index cf3d79142c..2dd539a509 100644
    a b class Tests_REST_Request extends WP_UnitTestCase { 
    491491        }
    492492
    493493        public function test_has_valid_params_json_error() {
    494                 if ( version_compare( PHP_VERSION, '5.3', '<' ) ) {
    495                         return $this->markTestSkipped( 'JSON validation is only available for PHP 5.3+' );
    496                 }
    497 
    498494                $this->request->set_header( 'Content-Type', 'application/json' );
    499495                $this->request->set_body( '{"invalid": JSON}' );
    500496
    class Tests_REST_Request extends WP_UnitTestCase { 
    507503
    508504
    509505        public function test_has_valid_params_empty_json_no_error() {
    510                 if ( version_compare( PHP_VERSION, '5.3', '<' ) ) {
    511                         return $this->markTestSkipped( 'JSON validation is only available for PHP 5.3+' );
    512                 }
    513 
    514506                $this->request->set_header( 'Content-Type', 'application/json' );
    515507                $this->request->set_body( '' );
    516508
  • tests/phpunit/tests/theme/customHeader.php

    diff --git a/tests/phpunit/tests/theme/customHeader.php b/tests/phpunit/tests/theme/customHeader.php
    index eeb240fc91..65b037042a 100644
    a b class Tests_Theme_Custom_Header extends WP_UnitTestCase { 
    126126                $this->assertFalse( has_custom_header() );
    127127                $this->assertEmpty( $html );
    128128
    129                 // ReflectionMethod::setAccessible is only available in PHP 5.3+
    130                 if ( version_compare( PHP_VERSION, '5.3', '<' ) ) {
    131                         return;
    132                 }
    133129                // The container should always be returned in the Customizer preview.
    134130                $this->_set_customize_previewing( true );
    135131                $html = get_custom_header_markup();
    class Tests_Theme_Custom_Header extends WP_UnitTestCase { 
    226222        }
    227223
    228224        function test_header_script_is_enqueued_by_the_custom_header_markup_without_video_when_previewing_in_customizer() {
    229                 if ( version_compare( PHP_VERSION, '5.3', '<' ) ) {
    230                         $this->markTestSkipped( 'ReflectionMethod::setAccessible is only available in PHP 5.3+' );
    231                         return;
    232                 }
    233 
    234225                $this->_add_theme_support(
    235226                        array(
    236227                                'video'                 => true,
  • tests/phpunit/tests/widgets/media-widget.php

    diff --git a/tests/phpunit/tests/widgets/media-widget.php b/tests/phpunit/tests/widgets/media-widget.php
    index 86a06eccc6..6b9dc926ce 100644
    a b class Test_WP_Widget_Media extends WP_UnitTestCase { 
    479479         * @covers WP_Widget_Media::has_content()
    480480         */
    481481        function test_has_content() {
    482                 if ( version_compare( PHP_VERSION, '5.3', '<' ) ) {
    483                         $this->markTestSkipped( 'ReflectionMethod::setAccessible is only available for PHP 5.3+' );
    484                         return;
    485                 }
    486 
    487482                $attachment_id = self::factory()->attachment->create_object(
    488483                        array(
    489484                                'file'           => DIR_TESTDATA . '/images/canola.jpg',