mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-08-12 04:40:26 +00:00
Unit Tests: one $factory to rule them all, and it shall be static.
Using more than one instance of `WP_UnitTest_Factory` causes all kinds of craziness, due to out-of-sync internal generator sequences. Since we want to use `setUpBeforeClass`, we were creating ad hoc instances. To avoid that, we were injecting one `static` instance via Dependency Injection in `wpSetUpBeforeClass`. All tests should really use the `static` instance, so we will remove the instance prop `$factory`. Replace `$this->factory` with `self::$factory` over 2000 times. Rewrite all of the tests that were hard-coding dynamic values. #YOLOFriday git-svn-id: https://develop.svn.wordpress.org/trunk@35225 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
@@ -31,8 +31,8 @@ class Tests_Query_Search extends WP_UnitTestCase {
|
||||
|
||||
function test_search_order_title_relevance() {
|
||||
foreach ( range( 1, 7 ) as $i )
|
||||
$this->factory->post->create( array( 'post_content' => $i . rand_str() . ' about', 'post_type' => $this->post_type ) );
|
||||
$post_id = $this->factory->post->create( array( 'post_title' => 'About', 'post_type' => $this->post_type ) );
|
||||
self::$factory->post->create( array( 'post_content' => $i . rand_str() . ' about', 'post_type' => $this->post_type ) );
|
||||
$post_id = self::$factory->post->create( array( 'post_title' => 'About', 'post_type' => $this->post_type ) );
|
||||
|
||||
$posts = $this->get_search_results( 'About' );
|
||||
$this->assertEquals( $post_id, reset( $posts )->ID );
|
||||
@@ -63,11 +63,11 @@ class Tests_Query_Search extends WP_UnitTestCase {
|
||||
* @ticket 33988
|
||||
*/
|
||||
public function test_s_should_exclude_term_prefixed_with_dash() {
|
||||
$p1 = $this->factory->post->create( array(
|
||||
$p1 = self::$factory->post->create( array(
|
||||
'post_status' => 'publish',
|
||||
'post_content' => 'This post has foo but also bar',
|
||||
) );
|
||||
$p2 = $this->factory->post->create( array(
|
||||
$p2 = self::$factory->post->create( array(
|
||||
'post_status' => 'publish',
|
||||
'post_content' => 'This post has only foo',
|
||||
) );
|
||||
@@ -84,11 +84,11 @@ class Tests_Query_Search extends WP_UnitTestCase {
|
||||
* @ticket 33988
|
||||
*/
|
||||
public function test_s_should_exclude_first_term_if_prefixed_with_dash() {
|
||||
$p1 = $this->factory->post->create( array(
|
||||
$p1 = self::$factory->post->create( array(
|
||||
'post_status' => 'publish',
|
||||
'post_content' => 'This post has foo but also bar',
|
||||
) );
|
||||
$p2 = $this->factory->post->create( array(
|
||||
$p2 = self::$factory->post->create( array(
|
||||
'post_status' => 'publish',
|
||||
'post_content' => 'This post has only bar',
|
||||
) );
|
||||
@@ -105,15 +105,15 @@ class Tests_Query_Search extends WP_UnitTestCase {
|
||||
* @ticket 33988
|
||||
*/
|
||||
public function test_s_should_not_exclude_for_dashes_in_the_middle_of_words() {
|
||||
$p1 = $this->factory->post->create( array(
|
||||
$p1 = self::$factory->post->create( array(
|
||||
'post_status' => 'publish',
|
||||
'post_content' => 'This post has foo but also bar',
|
||||
) );
|
||||
$p2 = $this->factory->post->create( array(
|
||||
$p2 = self::$factory->post->create( array(
|
||||
'post_status' => 'publish',
|
||||
'post_content' => 'This post has only bar',
|
||||
) );
|
||||
$p3 = $this->factory->post->create( array(
|
||||
$p3 = self::$factory->post->create( array(
|
||||
'post_status' => 'publish',
|
||||
'post_content' => 'This post has only foo-bar',
|
||||
) );
|
||||
|
||||
Reference in New Issue
Block a user