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 { |
62 | 62 | if ( is_null( $generation_definitions ) ) |
63 | 63 | $generation_definitions = $this->default_generation_definitions; |
64 | 64 | |
| 65 | $gen = new WP_UnitTest_Generator_Sequence(); |
| 66 | $incr = $gen->get_incr(); |
| 67 | |
65 | 68 | foreach( array_keys( $generation_definitions ) as $field_name ) { |
66 | 69 | if ( !isset( $args[$field_name] ) ) { |
67 | 70 | $generator = $generation_definitions[$field_name]; |
68 | | if ( is_scalar( $generator ) ) |
| 71 | if ( is_scalar( $generator ) ) { |
69 | 72 | $args[$field_name] = $generator; |
70 | | elseif ( is_object( $generator ) && method_exists( $generator, 'call' ) ) { |
| 73 | } elseif ( is_object( $generator ) && method_exists( $generator, 'call' ) ) { |
71 | 74 | $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 { |
75 | 78 | return new WP_Error( 'invalid_argument', 'Factory default value should be either a scalar or an generator object.' ); |
| 79 | } |
76 | 80 | } |
77 | 81 | } |
| 82 | |
78 | 83 | return $args; |
79 | 84 | } |
80 | 85 | |
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 { |
20 | 20 | $this->next++; |
21 | 21 | return $generated; |
22 | 22 | } |
| 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 | } |
23 | 45 | } |