Skip to content

Commit da87120

Browse files
committed
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. git-svn-id: https://develop.svn.wordpress.org/branches/6.8@60223 602fd350-edb4-49c9-b593-d223f7449a82
1 parent 7a6b20c commit da87120

File tree

1 file changed

+63
-0
lines changed

1 file changed

+63
-0
lines changed

tests/phpunit/tests/basic.php

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,4 +65,67 @@ public function test_package_json_node_engine( $package_json ) {
6565
$this->assertArrayHasKey( 'engines', $package_json );
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
}

0 commit comments

Comments
 (0)