Ticket #43583: 43583.2.patch
| File 43583.2.patch, 2.4 KB (added by , 8 years ago) |
|---|
-
src/wp-includes/compat.php
505 505 if ( ! function_exists( 'spl_autoload_register' ) ) { 506 506 require_once ABSPATH . WPINC . '/spl-autoload-compat.php'; 507 507 } 508 509 if ( ! function_exists( 'is_countable' ) ) { 510 /** 511 * Polyfill for is_countable function added in PHP 7.3. 512 * 513 * Verify that the content of a variable is an array or an object 514 * implementing Countable 515 * 516 * @since 4.9.6 517 * 518 * @param mixed $var The value to check. 519 * 520 * @return bool Returns true if var is countable, false otherwise. 521 */ 522 function is_countable( $var ) { 523 return ( is_array( $var ) || $var instanceof Countable ); 524 } 525 } -
tests/phpunit/tests/compat.php
186 186 $this->assertEquals( '["foo"]', $json->encodeUnsafe( array( 'foo' ) ) ); 187 187 $this->assertEquals( array( 'foo' ), $json->decode( '["foo"]' ) ); 188 188 } 189 190 /** 191 * @ticket 43583 192 */ 193 function test_is_countable_availability() { 194 $this->assertTrue( function_exists( 'is_countable' ) ); 195 } 196 197 /** 198 * Test is_countable polyfill. 199 * 200 * @ticket 43583 201 * 202 * @dataProvider countable_variable_test_data 203 */ 204 function test_is_countable_functionality($variable, $is_countable) { 205 $this->assertEquals( is_countable( $variable ), $is_countable ); 206 } 207 208 /** 209 * Data provider for test_is_countable_functionality test. First array value 210 * is the variable, and the second value is the expected return value of the 211 * PHP 7.3's is_countable function. 212 * 213 * @ticket 43583 214 * 215 * @return array test data. 216 */ 217 public function countable_variable_test_data() { 218 return array( 219 array( true, false ), 220 array( new stdClass(), false ), 221 array( new ArrayIteratorFake(), true ), 222 array( new CountableFake(), true ), 223 array( 16, false ), 224 array( null, false ), 225 array( array( 1, 2, 3 ), true ), 226 array( (array) 1, true ), 227 array( (object) array( 'foo', 'bar', 'baz' ), false ), 228 ); 229 } 189 230 } 190 231 191 232 /* used in test_mb_substr_phpcore */ … … 194 235 return 'Class A object'; 195 236 } 196 237 } 238 239 class ArrayIteratorFake extends ArrayIterator { 240 } 241 242 class CountableFake implements Countable { 243 public function count() { 244 return 16; 245 } 246 }