Page MenuHomePhabricator

MediaWiki test database is not reset between successive test runs
Closed, DuplicatePublicBUG REPORT

Description

Minimal test case:

DatabaseResetTest.php
<?php

/**
 * @group Database
 */
class DatabaseResetTest extends MediaWikiIntegrationTestCase {
	public function testOne() {
		$result = $this->editPage( 'Test', 'x' );
		$this->assertTrue( $result->isOK() );
		$this->assertTrue( $result->getValue()['new'], 'Not new!' );
	}

	public function testTwo() {
		$result = $this->editPage( 'Test', 'x' );
		$this->assertTrue( $result->isOK() );
		$this->assertTrue( $result->getValue()['new'], 'Not new!' );
	}
}

Running the test in Vagrant yields

$ PHPUNIT_WIKI=wiki /vagrant/mediawiki/tests/phpunit/phpunit.php DatabaseResetTest.php 
Using PHP 7.2.31-1+0~20200514.41+debian9~1.gbpe2a56b+wmf1
PHPUnit 8.5.19 by Sebastian Bergmann and contributors.
...
1) DatabaseResetTest::testTwo
Not new!
Failed asserting that false is true.

Event Timeline

Tgr updated the task description. (Show Details)

You can set $tablesUsed in the test.

Not sue if editPage should set $tablesUsed (to 'page' would be enough), because when editPage is used in addDBDataOnce it would be cleared after the first test and the tables are empty for the second test. It seems the tests needs a tablesUsedOnce to be clear on class teardown? But how can editPage know what to use?

Not related: T265033

As noted above, setting $tablesUsed would fix this issue. But even better would be to track the used tables automatically and reset them after each test (or after the whole test class, if used from within addDBDataOnce). This is what T342301 is for, and it has a patch already in review.

(And to clarify, I'm considering this a duplicate because $tablesUsed is something the developer needs to know about and use properly, which is really hard. With T342301, you get the expected behaviour of resetting all tables by default)