Make WordPress Core

Changeset 60223


Ignore:
Timestamp:
05/06/2025 02:37:30 AM (15 months ago)
Author:
peterwilsoncc
Message:

Build/Test Tools: Test version in additional config files.

Introduces tests to ensure the version numbers in package-lock.json (two instances) and composer.json match the WordPress version specified in version.php.

In pull requests, the package-lock.json file is updated automatically to match the version in package.json. The new test is intended to ensure the version numbers are correct in production branches.

Reviewed by jorbin.
Merges [60219], [60221] to the 6.8 branch.

Fixes #63390.

Location:
branches/6.8
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/6.8

  • branches/6.8/tests/phpunit/tests/basic.php

    r53686 r60223  
    6666                $this->assertArrayHasKey( 'node', $package_json['engines'] );
    6767        }
     68
     69        /**
     70         * Test the version numbers in package-lock.json are correct.
     71         *
     72         * In pull requests, the package-lock.json file is updated automatically
     73         * to match the version in package.json. This test is intended to ensure
     74         * the version numbers are correct in production branches.
     75         *
     76         * @coversNothing
     77         *
     78         * @dataProvider data_package_lock_json
     79         */
     80        public function test_package_lock_json( $path ) {
     81                $package_lock_json = file_get_contents( dirname( ABSPATH ) . '/package-lock.json' );
     82                $package_lock_json = json_decode( $package_lock_json, true );
     83                list( $version )   = explode( '-', $GLOBALS['wp_version'] );
     84
     85                // package-lock.json uses x.y.z, so fill cleaned $wp_version for .0 releases.
     86                if ( 1 === substr_count( $version, '.' ) ) {
     87                        $version .= '.0';
     88                }
     89
     90                $json_paths           = explode( '.', $path );
     91                $package_lock_version = $package_lock_json;
     92                foreach ( $json_paths as $json_path ) {
     93                        if ( ! isset( $package_lock_version[ $json_path ] ) ) {
     94                                $this->fail( "package-lock.json does not contain the path '$path'." );
     95                        }
     96                        $package_lock_version = $package_lock_version[ $json_path ];
     97                }
     98
     99                $this->assertSame( $version, $package_lock_version, "package-lock.json's $path needs to be updated to $version." );
     100        }
     101
     102        /**
     103         * Data provider for test_package_lock_json.
     104         *
     105         * @return array[] Data provider.
     106         */
     107        public function data_package_lock_json() {
     108                return array(
     109                        'top level' => array( 'version' ),
     110                        'package'   => array( 'packages..version' ),
     111                );
     112        }
     113
     114        /**
     115         * Test the version number in composer.json is correct.
     116         *
     117         * @coversNothing
     118         */
     119        public function test_composer_json() {
     120                $composer_json   = file_get_contents( dirname( ABSPATH ) . '/composer.json' );
     121                $composer_json   = json_decode( $composer_json, true );
     122                list( $version ) = explode( '-', $GLOBALS['wp_version'] );
     123
     124                // composer.json uses x.y.z, so fill cleaned $wp_version for .0 releases.
     125                if ( 1 === substr_count( $version, '.' ) ) {
     126                        $version .= '.0';
     127                }
     128
     129                $this->assertSame( $version, $composer_json['version'], "composer.json's version needs to be updated to $version." );
     130        }
    68131}
Note: See TracChangeset for help on using the changeset viewer.