Make WordPress Core


Ignore:
Timestamp:
04/21/2022 01:00:24 AM (4 years ago)
Author:
peterwilsoncc
Message:

Tests, Build Tools: Improve version compatibility tests.

Improve tests for is_wp_version_compatible() and is_php_version_compatible().

Follow up to [53227].

Props costdev, SergeyBiryukov.
Fixes #54257.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/functions/isPhpVersionCompatible.php

    r53227 r53237  
    22
    33/**
    4  * Tests the is_php_version_compatible function.
     4 * Tests the is_php_version_compatible() function.
    55 *
    66 * @group functions.php
    77 * @covers ::is_php_version_compatible
    88 */
    9 class Tests_Functions_isPhpVersionCompatible extends WP_UnitTestCase {
     9class Tests_Functions_IsPhpVersionCompatible extends WP_UnitTestCase {
    1010        /**
    1111         * Tests is_php_version_compatible().
    … …  
    1313         * @dataProvider data_is_php_version_compatible
    1414         *
    15          * @param mixed $test_value
    16          * @param bool $expected
     15         * @ticket 54257
    1716         *
    18          * @ticket 54257
     17         * @param mixed $required The minimum required PHP version.
     18         * @param bool  $expected The expected result.
    1919         */
    20         public function test_is_php_version_compatible( $test_value, $expected ) {
    21                 $this->assertSame( is_php_version_compatible( $test_value ), $expected );
     20        public function test_is_php_version_compatible( $required, $expected ) {
     21                $this->assertSame( $expected, is_php_version_compatible( $required ) );
    2222        }
    2323
    2424        /**
    25          * Provides test scenarios for test_php_version_compatible.
     25         * Data provider.
    2626         *
    2727         * @return array
    2828         */
    29         function data_is_php_version_compatible() {
     29        public function data_is_php_version_compatible() {
    3030                $php_version = phpversion();
    3131
    32                 $more = explode( '.', $php_version );
    33                 $less = $more;
     32                $version_parts  = explode( '.', $php_version );
     33                $lower_version  = $version_parts;
     34                $higher_version = $version_parts;
    3435
    35                 -- $less[ count( $less ) - 1 ];
    36                 ++ $more[ count( $less ) - 1 ];
     36                // Adjust the major version numbers.
     37                --$lower_version[0];
     38                ++$higher_version[0];
     39
     40                $lower_version  = implode( '.', $lower_version );
     41                $higher_version = implode( '.', $higher_version );
    3742
    3843                return array(
    39                         'greater' => array(
    40                                 'test_value' => implode( '.', $more ),
    41                                 'expected'   => false,
     44                        // Happy paths.
     45                        'a lower required version'  => array(
     46                                'required' => $lower_version,
     47                                'expected' => true,
    4248                        ),
    43                         'same'    => array(
    44                                 'test_value' => $php_version,
    45                                 'expected'   => true,
     49                        'the same version'          => array(
     50                                'required' => $php_version,
     51                                'expected' => true,
    4652                        ),
    47                         'less'    => array(
    48                                 'test_value' => implode( '.', $less ),
    49                                 'expected'   => true,
     53                        'a higher required version' => array(
     54                                'required' => $higher_version,
     55                                'expected' => false,
     56                        ),
     57
     58                        // Falsey values.
     59                        'false'                     => array(
     60                                'required' => false,
     61                                'expected' => true,
     62                        ),
     63                        'null'                      => array(
     64                                'required' => null,
     65                                'expected' => true,
     66                        ),
     67                        '0 int'                     => array(
     68                                'required' => 0,
     69                                'expected' => true,
     70                        ),
     71                        '0.0 float'                 => array(
     72                                'required' => 0.0,
     73                                'expected' => true,
     74                        ),
     75                        '0 string'                  => array(
     76                                'required' => '0',
     77                                'expected' => true,
     78                        ),
     79                        'empty string'              => array(
     80                                'required' => '',
     81                                'expected' => true,
     82                        ),
     83                        'empty array'               => array(
     84                                'required' => array(),
     85                                'expected' => true,
    5086                        ),
    5187                );
Note: See TracChangeset for help on using the changeset viewer.