Make WordPress Core


Ignore:
Timestamp:
01/09/2019 05:43:14 AM (6 years ago)
Author:
pento
Message:

Docs: Add docblocks for the PHPUnit factory objects.

Props andizer.
Fixes #44521.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/includes/factory/class-wp-unittest-factory-for-thing.php

    r42343 r44497  
    2222    }
    2323
     24    /**
     25     * Creates an object.
     26     *
     27     * @param array $args The arguments.
     28     *
     29     * @return mixed The result. Can be anything.
     30     */
    2431    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     */
    2541    abstract function update_object( $object, $fields );
    2642
     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     */
    2751    function create( $args = array(), $generation_definitions = null ) {
    2852        if ( is_null( $generation_definitions ) ) {
     
    4670    }
    4771
     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     */
    4880    function create_and_get( $args = array(), $generation_definitions = null ) {
    4981        $object_id = $this->create( $args, $generation_definitions );
     
    5183    }
    5284
     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     */
    5392    abstract function get_object_by_id( $object_id );
    5493
     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     */
    55103    function create_many( $count, $args = array(), $generation_definitions = null ) {
    56104        $results = array();
     
    61109    }
    62110
     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     */
    63121    function generate_args( $args = array(), $generation_definitions = null, &$callbacks = null ) {
    64122        $callbacks = array();
     
    89147    }
    90148
     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     */
    91158    function apply_callbacks( $callbacks, $created ) {
    92159        $updated_fields = array();
     160
    93161        foreach ( $callbacks as $field_name => $generator ) {
    94162            $updated_fields[ $field_name ] = $generator->call( $created );
     
    97165    }
    98166
     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     */
    99174    function callback( $function ) {
    100175        return new WP_UnitTest_Factory_Callback_After_Create( $function );
    101176    }
    102177
     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     */
    103185    function addslashes_deep( $value ) {
    104186        if ( is_array( $value ) ) {
Note: See TracChangeset for help on using the changeset viewer.