- Timestamp:
- 01/09/2019 05:43:14 AM (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/phpunit/includes/factory/class-wp-unittest-factory-for-thing.php
r42343 r44497 22 22 } 23 23 24 /** 25 * Creates an object. 26 * 27 * @param array $args The arguments. 28 * 29 * @return mixed The result. Can be anything. 30 */ 24 31 abstract function create_object( $args ); 32 33 /** 34 * Updates an existing object. 35 * 36 * @param int $object The object id. 37 * @param array $fields The values to update. 38 * 39 * @return mixed The result. Can be anything. 40 */ 25 41 abstract function update_object( $object, $fields ); 26 42 43 /** 44 * Creates an object. 45 * 46 * @param array $args Optional. The arguments for the object to create. Default is empty array. 47 * @param null $generation_definitions Optional. The default values for the object. Default is null. 48 * 49 * @return mixed The result. Can be anything. 50 */ 27 51 function create( $args = array(), $generation_definitions = null ) { 28 52 if ( is_null( $generation_definitions ) ) { … … 46 70 } 47 71 72 /** 73 * Creates an object and returns its object. 74 * 75 * @param array $args Optional. The arguments for the object to create. Default is empty array. 76 * @param null $generation_definitions Optional. The default values for the object. Default is null. 77 * 78 * @return mixed The created object. Can be anything. 79 */ 48 80 function create_and_get( $args = array(), $generation_definitions = null ) { 49 81 $object_id = $this->create( $args, $generation_definitions ); … … 51 83 } 52 84 85 /** 86 * Retrieves an object by ID. 87 * 88 * @param int $object_id The object id. 89 * 90 * @return mixed The object. Can be anything. 91 */ 53 92 abstract function get_object_by_id( $object_id ); 54 93 94 /** 95 * Creates multiple objects. 96 * 97 * @param int $count Amount of objects to create. 98 * @param array $args Optional. The arguments for the object to create. Default is empty array. 99 * @param null $generation_definitions Optional. The default values for the object. Default is null. 100 * 101 * @return array 102 */ 55 103 function create_many( $count, $args = array(), $generation_definitions = null ) { 56 104 $results = array(); … … 61 109 } 62 110 111 /** 112 * Combines the given argument with the generation_definitions (defaults) and applies 113 * possibly set callbacks on it. 114 * 115 * @param array $args Optional. The arguments to combine with defaults. Default is empty array. 116 * @param array|null $generation_definitions Optional. The defaults. Default is null. 117 * @param array|null $callbacks Optional. Array with callbacks to apply on the fields. Default is null. 118 * 119 * @return array|WP_Error Combined array on success. WP_Error when default value is incorrent. 120 */ 63 121 function generate_args( $args = array(), $generation_definitions = null, &$callbacks = null ) { 64 122 $callbacks = array(); … … 89 147 } 90 148 149 150 /** 151 * Applies the callbacks on the created object. 152 * 153 * @param WP_UnitTest_Factory_Callback_After_Create[] $callbacks Array with callback functions. 154 * @param mixed $created The object to apply callbacks for. 155 * 156 * @return array The altered fields. 157 */ 91 158 function apply_callbacks( $callbacks, $created ) { 92 159 $updated_fields = array(); 160 93 161 foreach ( $callbacks as $field_name => $generator ) { 94 162 $updated_fields[ $field_name ] = $generator->call( $created ); … … 97 165 } 98 166 167 /** 168 * Instantiates a callback objects for the given function name. 169 * 170 * @param string $function The callback function. 171 * 172 * @return WP_UnitTest_Factory_Callback_After_Create 173 */ 99 174 function callback( $function ) { 100 175 return new WP_UnitTest_Factory_Callback_After_Create( $function ); 101 176 } 102 177 178 /** 179 * Adds slashes to the given value. 180 * 181 * @param array|object|string|mixed $value The value to add slashes to. 182 * 183 * @return array|string The value with the possibly applied slashes. 184 */ 103 185 function addslashes_deep( $value ) { 104 186 if ( is_array( $value ) ) {
Note: See TracChangeset
for help on using the changeset viewer.