Make WordPress Core

Ticket #35199: 35199.diff

File 35199.diff, 2.2 KB (added by boonebgorges, 9 years ago)
  • tests/phpunit/includes/factory/class-wp-unittest-factory-for-thing.php

    diff --git tests/phpunit/includes/factory/class-wp-unittest-factory-for-thing.php tests/phpunit/includes/factory/class-wp-unittest-factory-for-thing.php
    index 8e98457..371ab7e 100644
    abstract class WP_UnitTest_Factory_For_Thing { 
    6262                if ( is_null( $generation_definitions ) )
    6363                        $generation_definitions = $this->default_generation_definitions;
    6464
     65                $gen = new WP_UnitTest_Generator_Sequence();
     66                $incr = $gen->get_incr();
     67
    6568                foreach( array_keys( $generation_definitions ) as $field_name ) {
    6669                        if ( !isset( $args[$field_name] ) ) {
    6770                                $generator = $generation_definitions[$field_name];
    68                                 if ( is_scalar( $generator ) )
     71                                if ( is_scalar( $generator ) ) {
    6972                                        $args[$field_name] = $generator;
    70                                 elseif ( is_object( $generator ) && method_exists( $generator, 'call' ) ) {
     73                                } elseif ( is_object( $generator ) && method_exists( $generator, 'call' ) ) {
    7174                                        $callbacks[$field_name] = $generator;
    72                                 } elseif ( is_object( $generator ) )
    73                                         $args[$field_name] = $generator->next();
    74                                 else
     75                                } elseif ( is_object( $generator ) ) {
     76                                        $args[ $field_name ] = sprintf( $generator->get_template_string(), $incr );
     77                                } else {
    7578                                        return new WP_Error( 'invalid_argument', 'Factory default value should be either a scalar or an generator object.' );
     79                                }
    7680                        }
    7781                }
     82
    7883                return $args;
    7984        }
    8085
  • tests/phpunit/includes/factory/class-wp-unittest-generator-sequence.php

    diff --git tests/phpunit/includes/factory/class-wp-unittest-generator-sequence.php tests/phpunit/includes/factory/class-wp-unittest-generator-sequence.php
    index 940edc4..d1831a9 100644
    class WP_UnitTest_Generator_Sequence { 
    2020                $this->next++;
    2121                return $generated;
    2222        }
     23
     24        /**
     25         * Get the incrementor.
     26         *
     27         * @since 4.6.0
     28         *
     29         * @return int
     30         */
     31        public function get_incr() {
     32                return self::$incr;
     33        }
     34
     35        /**
     36         * Get the template string.
     37         *
     38         * @since 4.6.0
     39         *
     40         * @return string
     41         */
     42        public function get_template_string() {
     43                return $this->template_string;
     44        }
    2345}