diff --git a/composer.json b/composer.json index 4391767..d258ced 100644 --- a/composer.json +++ b/composer.json @@ -59,16 +59,16 @@ "test": [ "@php -r \"file_exists( 'tests/wordpress/wp-content/db.php' ) || copy( 'tests/wordpress/wp-content/plugins/sqlite-database-integration/db.copy', 'tests/wordpress/wp-content/db.php' );\"", - "npm run validate", - "./tests/bin/build-wp-types.sh", - "npm run test-wp-types", - "rm -f tests/wordpress/wp-content/database/.ht.sqlite", "wp core multisite-install --url=example.org --title=Example --admin_user=admin --admin_email=admin@example.org --skip-email", "wp language core install de_DE it_IT ar he_IL", "wp json-dump --theme=twentytwentyone", "wp json-dump", + + "npm run validate", + "./tests/bin/build-wp-types.sh", + "npm run test-wp-types", "./tests/bin/test.sh" ] }, diff --git a/packages/wp-types/index.ts b/packages/wp-types/index.ts index 312b306..dc109c8 100644 --- a/packages/wp-types/index.ts +++ b/packages/wp-types/index.ts @@ -4002,6 +4002,7 @@ export const enum WP_Http_Status_Code { UNPROCESSABLE_ENTITY = 422, LOCKED = 423, FAILED_DEPENDENCY = 424, + TOO_EARLY = 425, UPGRADE_REQUIRED = 426, PRECONDITION_REQUIRED = 428, TOO_MANY_REQUESTS = 429, diff --git a/schemas/rest-api/properties/http-status-code.json b/schemas/rest-api/properties/http-status-code.json index 0cb59c1..3cfacdf 100644 --- a/schemas/rest-api/properties/http-status-code.json +++ b/schemas/rest-api/properties/http-status-code.json @@ -49,6 +49,7 @@ "UNPROCESSABLE_ENTITY", "LOCKED", "FAILED_DEPENDENCY", + "TOO_EARLY", "UPGRADE_REQUIRED", "PRECONDITION_REQUIRED", "TOO_MANY_REQUESTS", @@ -111,6 +112,7 @@ 422, 423, 424, + 425, 426, 428, 429, diff --git a/tests/mu-plugins/mu-plugin.php b/tests/mu-plugins/mu-plugin.php index f7b09b3..d02c11a 100644 --- a/tests/mu-plugins/mu-plugin.php +++ b/tests/mu-plugins/mu-plugin.php @@ -177,6 +177,38 @@ function save_external_schema( string $url, string $name, array $path = [] ) : v } } +function set_schema_field( string $filename, string $key, mixed $value ) : void { + $target = dirname( ABSPATH, 2 ) . "/" . $filename; + $file = file_get_contents( $target ); + + if ( ! $file ) { + throw new \Exception( "Failed to open {$filename} schema file." ); + } + + $data = json_decode( $file, true ); + + if ( ! $data ) { + throw new \Exception( "Failed to parse {$filename} schema." ); + } + + $data[ $key ] = $value; + + $json = json_encode( $data, JSON_PRETTY_PRINT ^ JSON_UNESCAPED_SLASHES ); + + $printer = new Printer\Printer(); + + $json = $printer->print( + $json, + "\t", + ); + + $result = file_put_contents( $target, $json . "\n" ); + + if ( ! $result ) { + throw new \Exception( "Failed to save {$filename} schema." ); + } +} + /** * Helper function for performing an internal REST API request and returning its response data. * diff --git a/tests/output/http.php b/tests/output/http.php new file mode 100644 index 0000000..9a6c828 --- /dev/null +++ b/tests/output/http.php @@ -0,0 +1,11 @@ +getConstants(); +$file = 'schemas/rest-api/properties/http-status-code.json'; + +set_schema_field( $file, 'tsEnumNames', array_keys( $constants ) ); +set_schema_field( $file, 'enum', array_values( $constants ) );