Changeset 60219
- Timestamp:
- 05/05/2025 01:41:14 AM (10 months ago)
- File:
-
- 1 edited
-
trunk/tests/phpunit/tests/basic.php (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/phpunit/tests/basic.php
r53686 r60219 66 66 $this->assertArrayHasKey( 'node', $package_json['engines'] ); 67 67 } 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.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 // package.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 } 68 131 }
Note: See TracChangeset
for help on using the changeset viewer.