Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Removed Test_Author_Queried_Object setUp function #540

Merged
merged 1 commit into from
Jul 10, 2018
Merged

Removed Test_Author_Queried_Object setUp function #540

merged 1 commit into from
Jul 10, 2018

Conversation

TheCrowned
Copy link
Contributor

This fixes #526 - test__author_queried_object_fix() fails when run twice.

schermata del 2018-05-30 21-48-44

After tests are run, the database should be properly cleaned by the WP testcase itself, so I dug into the core tests handling to see why that was not happening. Apparently, all queries were being run as TEMPORARY, except the ones from this test. Thus, this statement (which is where the test hanged for me):

$blog2 = $this->factory->blog->create( array( 'user_id' => $author1 ) );

failed, because the blog (and related db tables) were already present.

And indeed, it failed because of the filters in test-author-queried-object.php setUp() function, which prevented the default behavior of declaring the new site tables as TEMPORARY. Commenting those two filters out, tests succeed AND can be run an arbitrary number of times (without throwing any errors).

function setUp() {
	parent::setUp();

	//remove_filter( 'query', array( $this, '_create_temporary_tables' ) );
	//remove_filter( 'query', array( $this, '_drop_temporary_tables' ) );
}

As a side note, WP_UnitTestCase->tearDown(), which executes $wpdb->query( 'ROLLBACK' ); and thus deletes all temporary tables, is called at the end of each plugin test, so it shouldn't create any issues, and those filters are not needed.

I have thus deleted the whole function, since it was not doing anything besides setting up the filters. All tests still pass okay!

Copy link
Contributor

@sboisvert sboisvert left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm, I really like the thorough explanations!

@mdbitz mdbitz merged commit 5962064 into Automattic:master Jul 10, 2018
rebeccahum pushed a commit that referenced this pull request Mar 26, 2019
…-on-multisite-test

Removed Test_Author_Queried_Object setUp function
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Test test__author_queried_object_fix() failing when run twice
3 participants