Skip to content

Commit 3fded09

Browse files
t-hamanoswissspidyMamaduka
authored
CI: Run PHP unit tests on PHP 8.4 and 8.5 (#79260)
* CI: Run PHP unit tests on PHP 8.4 and 8.5 WordPress 6.9 officially supports PHP 8.5, so Gutenberg should verify its PHP unit tests pass on it too. Add 8.4 (previously missing) and 8.5 to the test-php matrix, following the existing pattern: PRs test the oldest and newest PHP (7.4 and 8.5) on the latest WP, while trunk grants previous-WP coverage to those same boundary versions. Co-Authored-By: Claude <noreply@anthropic.com> * Tests: Guard ReflectionMethod/Property::setAccessible() for PHP 8.5 PHP 8.5 deprecates ReflectionMethod::setAccessible() and ReflectionProperty::setAccessible(), which have had no effect since PHP 8.1. The PHP unit test suite turns deprecation notices into errors, so these calls broke the newly added PHP 8.5 matrix job with 65 errors. Wrap the remaining unguarded calls in `if ( PHP_VERSION_ID < 80100 )`, matching the pattern already used elsewhere in the codebase. The calls are still required on PHP < 8.1 (which Gutenberg supports down to 7.4), where private members are not reflectable without them. Co-Authored-By: Claude <noreply@anthropic.com> --------- Co-authored-by: t-hamano <wildworks@git.wordpress.org> Co-authored-by: swissspidy <swissspidy@git.wordpress.org> Co-authored-by: Mamaduka <mamaduka@git.wordpress.org>
1 parent 551b136 commit 3fded09

6 files changed

Lines changed: 76 additions & 24 deletions

‎.github/workflows/unit-test.yml‎

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -173,17 +173,21 @@ jobs:
173173
fail-fast: true
174174
matrix:
175175
event: ['${{ github.event_name }}']
176-
php: ['7.4', '8.0', '8.1', '8.2', '8.3']
176+
php: ['7.4', '8.0', '8.1', '8.2', '8.3', '8.4', '8.5']
177177
multisite: [false, true]
178178
wordpress: ['', 'previous major version']
179179
exclude:
180-
# On PRs: Only test PHP 7.4 and 8.3, single-site, latest WP
180+
# On PRs: Only test PHP 7.4 and 8.5, single-site, latest WP
181181
- event: 'pull_request'
182182
php: '8.0'
183183
- event: 'pull_request'
184184
php: '8.1'
185185
- event: 'pull_request'
186186
php: '8.2'
187+
- event: 'pull_request'
188+
php: '8.3'
189+
- event: 'pull_request'
190+
php: '8.4'
187191
- event: 'pull_request'
188192
multisite: true
189193
- event: 'pull_request'
@@ -195,6 +199,10 @@ jobs:
195199
wordpress: 'previous major version'
196200
- php: '8.2'
197201
wordpress: 'previous major version'
202+
- php: '8.3'
203+
wordpress: 'previous major version'
204+
- php: '8.4'
205+
wordpress: 'previous major version'
198206

199207
env:
200208
WP_ENV_PHP_VERSION: ${{ matrix.php }}

‎phpunit/blocks/class-wp-navigation-block-renderer-test.php‎

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,9 @@ public function test_gutenberg_default_block_is_enclosed_in_li_tags() {
2727
// Setup an empty testing instance of `WP_Navigation_Block_Renderer` and save the original.
2828
$reflection = new ReflectionClass( 'WP_Navigation_Block_Renderer_Gutenberg' );
2929
$method = $reflection->getMethod( 'get_markup_for_inner_block' );
30-
$method->setAccessible( true );
30+
if ( PHP_VERSION_ID < 80100 ) {
31+
$method->setAccessible( true );
32+
}
3133
// Invoke the private method.
3234
$result = $method->invoke( $reflection, $navigation_link_block );
3335

@@ -61,7 +63,9 @@ public function test_gutenberg_get_markup_for_inner_block_site_title() {
6163
// Setup an empty testing instance of `WP_Navigation_Block_Renderer` and save the original.
6264
$reflection = new ReflectionClass( 'WP_Navigation_Block_Renderer_Gutenberg' );
6365
$method = $reflection->getMethod( 'get_markup_for_inner_block' );
64-
$method->setAccessible( true );
66+
if ( PHP_VERSION_ID < 80100 ) {
67+
$method->setAccessible( true );
68+
}
6569
// Invoke the private method.
6670
$result = $method->invoke( $reflection, $site_title_block );
6771

@@ -99,7 +103,9 @@ public function test_gutenberg_block_not_automatically_wrapped_with_li_tag() {
99103
// Setup an empty testing instance of `WP_Navigation_Block_Renderer` and save the original.
100104
$reflection = new ReflectionClass( 'WP_Navigation_Block_Renderer_Gutenberg' );
101105
$method = $reflection->getMethod( 'get_markup_for_inner_block' );
102-
$method->setAccessible( true );
106+
if ( PHP_VERSION_ID < 80100 ) {
107+
$method->setAccessible( true );
108+
}
103109
// Invoke the private method.
104110
$result = $method->invoke( $reflection, $heading_block );
105111

@@ -153,7 +159,9 @@ public function test_gutenberg_block_is_automatically_wrapped_with_li_tag_when_f
153159
// Setup an empty testing instance of `WP_Navigation_Block_Renderer` and save the original.
154160
$reflection = new ReflectionClass( 'WP_Navigation_Block_Renderer_Gutenberg' );
155161
$method = $reflection->getMethod( 'get_markup_for_inner_block' );
156-
$method->setAccessible( true );
162+
if ( PHP_VERSION_ID < 80100 ) {
163+
$method->setAccessible( true );
164+
}
157165
// Invoke the private method.
158166
$result = $method->invoke( $reflection, $heading_block );
159167

@@ -175,7 +183,9 @@ public function test_gutenberg_block_is_automatically_wrapped_with_li_tag_when_f
175183
public function test_gutenberg_get_inner_blocks_from_navigation_post_returns_empty_block_list() {
176184
$reflection = new ReflectionClass( 'WP_Navigation_Block_Renderer_Gutenberg' );
177185
$method = $reflection->getMethod( 'get_inner_blocks_from_navigation_post' );
178-
$method->setAccessible( true );
186+
if ( PHP_VERSION_ID < 80100 ) {
187+
$method->setAccessible( true );
188+
}
179189
$attributes = array( 'ref' => 0 );
180190

181191
$actual = $method->invoke( $reflection, $attributes );

‎phpunit/blocks/render-block-rss-test.php‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,9 @@ private function setup_block_context() {
6464
$wp_block_supports = WP_Block_Supports::get_instance();
6565
$reflection = new ReflectionClass( $wp_block_supports );
6666
$property = $reflection->getProperty( 'block_to_render' );
67-
$property->setAccessible( true );
67+
if ( PHP_VERSION_ID < 80100 ) {
68+
$property->setAccessible( true );
69+
}
6870
$property->setValue( $wp_block_supports, $block );
6971
}
7072

‎phpunit/class-wp-duotone-test.php‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,9 @@ public function data_get_slug_from_attribute() {
112112
public function test_get_slug_from_attribute( $data_attr, $expected ) {
113113

114114
$reflection = new ReflectionMethod( 'WP_Duotone_Gutenberg', 'get_slug_from_attribute' );
115-
$reflection->setAccessible( true );
115+
if ( PHP_VERSION_ID < 80100 ) {
116+
$reflection->setAccessible( true );
117+
}
116118

117119
$this->assertSame( $expected, $reflection->invoke( null, $data_attr ) );
118120
}
@@ -134,7 +136,9 @@ public function data_is_preset() {
134136
*/
135137
public function test_is_preset( $data_attr, $expected ) {
136138
$reflection = new ReflectionMethod( 'WP_Duotone_Gutenberg', 'is_preset' );
137-
$reflection->setAccessible( true );
139+
if ( PHP_VERSION_ID < 80100 ) {
140+
$reflection->setAccessible( true );
141+
}
138142

139143
$this->assertSame( $expected, $reflection->invoke( null, $data_attr ) );
140144
}

‎phpunit/class-wp-theme-json-resolver-test.php‎

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -75,11 +75,15 @@ public static function set_up_before_class() {
7575
);
7676

7777
static::$property_blocks_cache = new ReflectionProperty( WP_Theme_JSON_Resolver_Gutenberg::class, 'blocks_cache' );
78-
static::$property_blocks_cache->setAccessible( true );
78+
if ( PHP_VERSION_ID < 80100 ) {
79+
static::$property_blocks_cache->setAccessible( true );
80+
}
7981
static::$property_blocks_cache_orig_value = static::$property_blocks_cache->getValue();
8082

8183
static::$property_core = new ReflectionProperty( WP_Theme_JSON_Resolver_Gutenberg::class, 'core' );
82-
static::$property_core->setAccessible( true );
84+
if ( PHP_VERSION_ID < 80100 ) {
85+
static::$property_core->setAccessible( true );
86+
}
8387
static::$property_core_orig_value = static::$property_core->getValue();
8488
}
8589

@@ -285,7 +289,9 @@ private function get_registered_block_names( $hard_reset = false ) {
285289
*/
286290
public function test_has_same_registered_blocks_when_all_blocks_not_cached( $origin, array $cache = array() ) {
287291
$has_same_registered_blocks = new ReflectionMethod( WP_Theme_JSON_Resolver_Gutenberg::class, 'has_same_registered_blocks' );
288-
$has_same_registered_blocks->setAccessible( true );
292+
if ( PHP_VERSION_ID < 80100 ) {
293+
$has_same_registered_blocks->setAccessible( true );
294+
}
289295
$expected_cache = $this->get_registered_block_names();
290296

291297
// Set up the blocks cache for the origin.
@@ -358,7 +364,9 @@ public function data_has_same_registered_blocks_when_all_blocks_not_cached() {
358364
*/
359365
public function test_has_same_registered_blocks_when_all_blocks_are_cached( $origin ) {
360366
$has_same_registered_blocks = new ReflectionMethod( WP_Theme_JSON_Resolver_Gutenberg::class, 'has_same_registered_blocks' );
361-
$has_same_registered_blocks->setAccessible( true );
367+
if ( PHP_VERSION_ID < 80100 ) {
368+
$has_same_registered_blocks->setAccessible( true );
369+
}
362370
$expected_cache = $this->get_registered_block_names();
363371

364372
// Set up the cache with all registered blocks.
@@ -798,7 +806,9 @@ public function test_get_theme_data_does_not_parse_theme_json_if_not_present() {
798806

799807
// Force-unset $i18n_schema property to "unload" translation schema.
800808
$property = new ReflectionProperty( $theme_json_resolver, 'i18n_schema' );
801-
$property->setAccessible( true );
809+
if ( PHP_VERSION_ID < 80100 ) {
810+
$property->setAccessible( true );
811+
}
802812
$property->setValue( null, null );
803813

804814
// A completely empty theme.json data set still has the 'version' key when parsed.

‎phpunit/class-wp-theme-json-test.php‎

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4213,7 +4213,9 @@ public function test_get_property_value_should_return_string_for_invalid_paths_o
42134213
$reflection_class = new ReflectionClass( WP_Theme_JSON_Gutenberg::class );
42144214

42154215
$get_property_value_method = $reflection_class->getMethod( 'get_property_value' );
4216-
$get_property_value_method->setAccessible( true );
4216+
if ( PHP_VERSION_ID < 80100 ) {
4217+
$get_property_value_method->setAccessible( true );
4218+
}
42174219
$result = $get_property_value_method->invoke( null, $styles, $path );
42184220

42194221
$this->assertSame( '', $result );
@@ -6614,7 +6616,9 @@ public function test_process_blocks_custom_css( $input, $expected ) {
66146616
)
66156617
);
66166618
$reflection = new ReflectionMethod( $theme_json, 'process_blocks_custom_css' );
6617-
$reflection->setAccessible( true );
6619+
if ( PHP_VERSION_ID < 80100 ) {
6620+
$reflection->setAccessible( true );
6621+
}
66186622

66196623
$this->assertSame( $expected, $reflection->invoke( $theme_json, $input['css'], $input['selector'] ) );
66206624
}
@@ -6939,7 +6943,9 @@ public function test_get_block_style_variation_selector( $selector, $expected )
69396943
$theme_json = new ReflectionClass( 'WP_Theme_JSON_Gutenberg' );
69406944

69416945
$func = $theme_json->getMethod( 'get_block_style_variation_selector' );
6942-
$func->setAccessible( true );
6946+
if ( PHP_VERSION_ID < 80100 ) {
6947+
$func->setAccessible( true );
6948+
}
69436949

69446950
$actual = $func->invoke( null, 'custom', $selector );
69456951

@@ -7019,7 +7025,9 @@ public function test_scope_style_node_selectors() {
70197025
$theme_json = new ReflectionClass( 'WP_Theme_JSON_Gutenberg' );
70207026

70217027
$func = $theme_json->getMethod( 'scope_style_node_selectors' );
7022-
$func->setAccessible( true );
7028+
if ( PHP_VERSION_ID < 80100 ) {
7029+
$func->setAccessible( true );
7030+
}
70237031

70247032
$node = array(
70257033
'name' => 'core/image',
@@ -7066,7 +7074,9 @@ public function test_opt_out_of_block_style_variations_by_default() {
70667074
$theme_json = new ReflectionClass( 'WP_Theme_JSON_Gutenberg' );
70677075

70687076
$func = $theme_json->getMethod( 'get_block_nodes' );
7069-
$func->setAccessible( true );
7077+
if ( PHP_VERSION_ID < 80100 ) {
7078+
$func->setAccessible( true );
7079+
}
70707080

70717081
$theme_json = array(
70727082
'version' => WP_Theme_JSON_Gutenberg::LATEST_SCHEMA,
@@ -7100,7 +7110,9 @@ public function test_opt_in_to_block_style_variations() {
71007110
$theme_json = new ReflectionClass( 'WP_Theme_JSON_Gutenberg' );
71017111

71027112
$func = $theme_json->getMethod( 'get_block_nodes' );
7103-
$func->setAccessible( true );
7113+
if ( PHP_VERSION_ID < 80100 ) {
7114+
$func->setAccessible( true );
7115+
}
71047116

71057117
$theme_json = array(
71067118
'version' => WP_Theme_JSON_Gutenberg::LATEST_SCHEMA,
@@ -7143,7 +7155,9 @@ public function test_return_block_node_paths() {
71437155
$theme_json = new ReflectionClass( 'WP_Theme_JSON_Gutenberg' );
71447156

71457157
$func = $theme_json->getMethod( 'get_block_nodes' );
7146-
$func->setAccessible( true );
7158+
if ( PHP_VERSION_ID < 80100 ) {
7159+
$func->setAccessible( true );
7160+
}
71477161

71487162
$theme_json = array(
71497163
'version' => WP_Theme_JSON_Gutenberg::LATEST_SCHEMA,
@@ -7195,7 +7209,9 @@ public function test_return_block_node_paths_with_variations() {
71957209
$theme_json = new ReflectionClass( 'WP_Theme_JSON_Gutenberg' );
71967210

71977211
$func = $theme_json->getMethod( 'get_block_nodes' );
7198-
$func->setAccessible( true );
7212+
if ( PHP_VERSION_ID < 80100 ) {
7213+
$func->setAccessible( true );
7214+
}
71997215

72007216
$theme_json = array(
72017217
'version' => WP_Theme_JSON_Gutenberg::LATEST_SCHEMA,
@@ -7991,7 +8007,9 @@ public function test_sanitize_preserves_null_schema_behavior() {
79918007
*/
79928008
public function test_to_ruleset_skips_non_scalar_values_and_casts_numerics() {
79938009
$reflection = new ReflectionMethod( WP_Theme_JSON_Gutenberg::class, 'to_ruleset' );
7994-
$reflection->setAccessible( true );
8010+
if ( PHP_VERSION_ID < 80100 ) {
8011+
$reflection->setAccessible( true );
8012+
}
79958013
$declarations = array(
79968014
array(
79978015
'name' => 'color',

0 commit comments

Comments
 (0)