Created
April 2, 2026 21:18
-
-
Save josephscott/e1265dc63d878a53947ec6c4cc555390 to your computer and use it in GitHub Desktop.
wp_normalize_path split test fix
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * Tests that wp_normalize_path() static cache stores results. | |
| * | |
| * Uses ReflectionFunction::getStaticVariables() to inspect the cache. | |
| * | |
| * Skipped on PHP 8.1 and 8.2 because OPcache's Dead Code Elimination | |
| * incorrectly treats ZEND_BIND_STATIC as side-effect-free for static | |
| * variables with simple initializers, causing getStaticVariables() to | |
| * return compile-time defaults instead of runtime values. Fixed in | |
| * PHP 8.3 via PR #9301 (arbitrary static variable initializers RFC). | |
| * | |
| * @ticket 64538 | |
| */ | |
| public function test_wp_normalize_path_static_cache() { | |
| if ( version_compare( PHP_VERSION, '8.1.0', '>=' ) && version_compare( PHP_VERSION, '8.3.0', '<' ) ) { | |
| $this->markTestSkipped( 'ReflectionFunction::getStaticVariables() returns stale values on PHP 8.1/8.2 with OPcache (fixed in 8.3).' ); | |
| } | |
| $path = '/var/www/cache-test\\subdir\\'; | |
| $expected = '/var/www/cache-test/subdir/'; | |
| $result = wp_normalize_path( $path ); | |
| $this->assertSame( $expected, $result ); | |
| $reflection = new ReflectionFunction( 'wp_normalize_path' ); | |
| $static_vars = $reflection->getStaticVariables(); | |
| $this->assertArrayHasKey( 'cache', $static_vars, 'Static cache array should exist.' ); | |
| $this->assertArrayHasKey( $path, $static_vars['cache'], 'Cache should contain the normalized path.' ); | |
| $this->assertSame( $expected, $static_vars['cache'][ $path ], 'Cached value should match the expected normalized path.' ); | |
| } | |
| /** | |
| * Tests that wp_normalize_path() static cache stores results on PHP 8.1/8.2. | |
| * | |
| * On these versions ReflectionFunction::getStaticVariables() is unreliable | |
| * due to an OPcache DCE bug, so we verify caching behavior indirectly by | |
| * confirming repeated calls return identical results. | |
| * | |
| * @ticket 64538 | |
| */ | |
| public function test_wp_normalize_path_static_cache_php81_82() { | |
| if ( version_compare( PHP_VERSION, '8.1.0', '<' ) || version_compare( PHP_VERSION, '8.3.0', '>=' ) ) { | |
| $this->markTestSkipped( 'This test targets the PHP 8.1/8.2 OPcache bug. Other versions use test_wp_normalize_path_static_cache().' ); | |
| } | |
| $path = '/var/www/cache-test\\subdir\\'; | |
| $expected = '/var/www/cache-test/subdir/'; | |
| $first_call = wp_normalize_path( $path ); | |
| $second_call = wp_normalize_path( $path ); | |
| $this->assertSame( $expected, $first_call, 'First call should return the normalized path.' ); | |
| $this->assertSame( $first_call, $second_call, 'Second call should return the same cached result.' ); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment