mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2025-10-16 12:05:38 +00:00
Splits the tests in the `tests/phpunit/tests/compat.php` file up into individual test classes for each function being tested. Improvements to individual test cases: * Adds `@covers` tags. * Adds visibility modifiers to all methods. * Adds function availability test. * Where relevant, fixes the assertion parameter order. * Data provider: * Where relevant, reworks a test to use a data provider. * Where relevant, renames data provider methods to have a more obvious link to the test it applies to. * Makes the data provider more readable by adding keys within the data sets. * Moves the data provider below its associated tests. * Adds/removes data sets in data providers. * Makes the actual test code more readable by using descriptive variables and multi-line function calls. * Adds the `$message` parameter to all assertions when a test method contains more than one assertion. Specifically for the `_mb_substr()` tests: * Splits the `test_mb_substr_phpcore()` method into two test methods based on the PHP Core test files they are emulating. * Makes the actual test code within the `test_mb_substr_phpcore_basic()` method more readable by using descriptive variables and multi-line function calls. * Splits the data used for the second part of the `test_mb_substr_phpcore()` function, now `test_mb_substr_phpcore_input_type_handling()`, off into a separate data provider with named data sets. * Removes duplicate data sets from the `data_mb_substr_phpcore_input_type_handling()`. * Why? The PHP native tests test against upper/lowercase `false`, `true`, `null` and some other text string single quote/double quote variations. As things were, those differentiations had been undone when the coding standards were put in place, so in effect those weren't being tested anymore. And as this is userland code, there's no point in adding these differentiations back as they will be handled the same by PHP anyway (and that is safeguarded via the PHP native tests). * Removes the "undefined variable" and "unset variable" test cases as, while those are relevant to the C code in which PHP is written, they are not relevant for testing userland code and will behave the same as the test passing `null`. Follow-to [25002], [32364], [42228], [42343], [43034], [43036], [43220], [43571], [45607], [47122], [47198], [48937], [48996], [51415], [51563], [51594]. Props jrf, hellofromTonya. See #39265, #53363. git-svn-id: https://develop.svn.wordpress.org/trunk@51852 602fd350-edb4-49c9-b593-d223f7449a82
78 lines
1.8 KiB
PHP
78 lines
1.8 KiB
PHP
<?php
|
|
|
|
/**
|
|
* @group compat
|
|
*
|
|
* @covers ::is_iterable
|
|
*/
|
|
class Tests_Compat_isIterable extends WP_UnitTestCase {
|
|
|
|
/**
|
|
* Test that is_iterable() is always available (either from PHP or WP).
|
|
*
|
|
* @ticket 43619
|
|
*/
|
|
public function test_is_iterable_availability() {
|
|
$this->assertTrue( function_exists( 'is_iterable' ) );
|
|
}
|
|
|
|
/**
|
|
* Test is_iterable() polyfill.
|
|
*
|
|
* @ticket 43619
|
|
*
|
|
* @dataProvider data_is_iterable_functionality
|
|
*
|
|
* @param mixed $variable Variable to check.
|
|
* @param bool $is_iterable The expected return value of PHP 7.1 is_iterable() function.
|
|
*/
|
|
public function test_is_iterable_functionality( $variable, $is_iterable ) {
|
|
$this->assertSame( $is_iterable, is_iterable( $variable ) );
|
|
}
|
|
|
|
/**
|
|
* Data provider for test_is_iterable_functionality().
|
|
*
|
|
* @ticket 43619
|
|
*
|
|
* @return array {
|
|
* @type array {
|
|
* @type mixed $variable Variable to check.
|
|
* @type bool $is_iterable The expected return value of PHP 7.1 is_iterable() function.
|
|
* }
|
|
* }
|
|
*/
|
|
public function data_is_iterable_functionality() {
|
|
return array(
|
|
'empty array' => array(
|
|
'variable' => array(),
|
|
'is_iterable' => true,
|
|
),
|
|
'non-empty array' => array(
|
|
'variable' => array( 1, 2, 3 ),
|
|
'is_iterable' => true,
|
|
),
|
|
'Iterator object' => array(
|
|
'variable' => new ArrayIterator( array( 1, 2, 3 ) ),
|
|
'is_iterable' => true,
|
|
),
|
|
'null' => array(
|
|
'variable' => null,
|
|
'is_iterable' => false,
|
|
),
|
|
'integer 1' => array(
|
|
'variable' => 1,
|
|
'is_iterable' => false,
|
|
),
|
|
'float 3.14' => array(
|
|
'variable' => 3.14,
|
|
'is_iterable' => false,
|
|
),
|
|
'plain stdClass object' => array(
|
|
'variable' => new stdClass(),
|
|
'is_iterable' => false,
|
|
),
|
|
);
|
|
}
|
|
}
|