Changeset 53521
- Timestamp:
- 06/18/2022 09:28:39 PM (2 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/phpunit/includes/abstract-testcase.php
r53467 r53521 876 876 $this->assertNotEmpty( $sub_array, $message . ' Subitem of the array is empty.' ); 877 877 } 878 } 879 880 /** 881 * Helper function to convert a single-level array containing text strings to a named data provider. 882 * 883 * The value of the data set will also be used as the name of the data set. 884 * 885 * Typical usage of this method: 886 * 887 * public function data_provider_for_test_name() { 888 * $array = array( 889 * 'value1', 890 * 'value2', 891 * ); 892 * 893 * return $this->text_array_to_dataprovider( $array ); 894 * } 895 * 896 * The returned result will look like: 897 * 898 * array( 899 * 'value1' => array( 'value1' ), 900 * 'value2' => array( 'value2' ), 901 * ) 902 * 903 * @since 6.1.0 904 * 905 * @param array $input Input array. 906 * @return array Array which is usable as a test data provider with named data sets. 907 */ 908 public static function text_array_to_dataprovider( $input ) { 909 $data = array(); 910 911 foreach ( $input as $value ) { 912 if ( ! is_string( $value ) ) { 913 throw new Exception( 914 'All values in the input array should be text strings. Fix the input data.' 915 ); 916 } 917 918 if ( isset( $data[ $value ] ) ) { 919 throw new Exception( 920 "Attempting to add a duplicate data set for value $value to the data provider. Fix the input data." 921 ); 922 } 923 924 $data[ $value ] = array( $value ); 925 } 926 927 return $data; 878 928 } 879 929
Note: See TracChangeset
for help on using the changeset viewer.