7c79386135
[35244] changed the way that `WP_UnitTest_Generator_Sequence()` created an incrementor for object fields (like 'post_name' and 'user_email'), by making incrementor static across the entire run of the test suite. While this helped to enforce uniqueness across the tests, it has the side effect of bumping the incrementor between fields on the same object (so that, eg, the same post might have `post_name` "post-12" but `post_title` "Post 13". By switching to a technique that uses the same incrementor for each field belonging to a given fixture, we conform better to the expectations of developers using `WP_UnitTest_Factory`. Fixes #35199. git-svn-id: https://develop.svn.wordpress.org/trunk@37299 602fd350-edb4-49c9-b593-d223f7449a82
46 lines
748 B
PHP
46 lines
748 B
PHP
<?php
|
|
|
|
class WP_UnitTest_Generator_Sequence {
|
|
static $incr = -1;
|
|
public $next;
|
|
public $template_string;
|
|
|
|
function __construct( $template_string = '%s', $start = null ) {
|
|
if ( $start ) {
|
|
$this->next = $start;
|
|
} else {
|
|
self::$incr++;
|
|
$this->next = self::$incr;
|
|
}
|
|
$this->template_string = $template_string;
|
|
}
|
|
|
|
function next() {
|
|
$generated = sprintf( $this->template_string , $this->next );
|
|
$this->next++;
|
|
return $generated;
|
|
}
|
|
|
|
/**
|
|
* Get the incrementor.
|
|
*
|
|
* @since 4.6.0
|
|
*
|
|
* @return int
|
|
*/
|
|
public function get_incr() {
|
|
return self::$incr;
|
|
}
|
|
|
|
/**
|
|
* Get the template string.
|
|
*
|
|
* @since 4.6.0
|
|
*
|
|
* @return string
|
|
*/
|
|
public function get_template_string() {
|
|
return $this->template_string;
|
|
}
|
|
}
|