phpunit: Do not call addCoreDBData if the test doesn't need the DB

This is a small step towards T155147. For now we clone the database even
if the test doesn't say it needs it, but we stop adding core data.

If a non-database test depends on this data, it means that it really
should be in the database group, or that it's otherwise doing something
wrong. For example, both MediaWikiTest and
RefreshSecondaryDataUpdateTest were depending on the 'UTPage' page being
created by the test framework, although they did that in such a way that
the needsDB() check in getExistingTestPage() weren't triggered.

Bug: T155147
Depends-On: I1a94c6ca2f335ee5a2d7d57df6dc46b65ca1f767
Change-Id: Ia04ff528628a7ae8b350e3122f5a06dbc1ff753b
This commit is contained in:
Daimona Eaytoy 2023-07-16 14:46:56 +02:00
parent 4485f887ae
commit 3bedffa87b
3 changed files with 13 additions and 5 deletions

View file

@ -502,7 +502,9 @@ abstract class MediaWikiIntegrationTestCase extends PHPUnit\Framework\TestCase {
self::setupAllTestDBs(
$this->db, $this->dbPrefix(), $useTemporaryTables
);
$this->addCoreDBData();
if ( $this->needsDB() ) {
$this->addCoreDBData();
}
}
// TODO: the DB setup should be done in setUpBeforeClass(), so the test DB
@ -1633,7 +1635,7 @@ abstract class MediaWikiIntegrationTestCase extends PHPUnit\Framework\TestCase {
// Make 1 page with 1 revision
$page = MediaWikiServices::getInstance()->getWikiPageFactory()->newFromTitle( Title::makeTitle( NS_MAIN, 'UTPage' ) );
if ( $page->getId() == 0 ) {
if ( !$page->exists() ) {
$page->doUserEditContent(
new WikitextContent( 'UTContent' ),
$user,
@ -2117,8 +2119,10 @@ abstract class MediaWikiIntegrationTestCase extends PHPUnit\Framework\TestCase {
if ( array_intersect( $tablesUsed, $coreDBDataTables ) ) {
// Reset services that may contain information relating to the truncated tables
$this->overrideMwServices();
// Re-add core DB data that was deleted
$this->addCoreDBData();
if ( $this->needsDB() ) {
// Re-add core DB data that was deleted
$this->addCoreDBData();
}
}
}
}

View file

@ -6,6 +6,9 @@ use MediaWiki\Request\WebResponse;
use MediaWiki\Title\Title;
use Wikimedia\TestingAccessWrapper;
/**
* @group Database
*/
class MediaWikiTest extends MediaWikiIntegrationTestCase {
private $oldServer, $oldGet, $oldPost;

View file

@ -8,6 +8,7 @@ use Wikimedia\ScopedCallback;
/**
* @covers RefreshSecondaryDataUpdate
* @group Database
*/
class RefreshSecondaryDataUpdateTest extends MediaWikiIntegrationTestCase {
public function testSuccess() {
@ -206,7 +207,7 @@ class RefreshSecondaryDataUpdateTest extends MediaWikiIntegrationTestCase {
return [ $goodUpdate ];
} );
$wikiPage = $services->getWikiPageFactory()->newFromTitle( Title::makeTitle( NS_MAIN, 'UTPage' ) );
$wikiPage = $this->getExistingTestPage();
$update = new RefreshSecondaryDataUpdate(
$lbFactory,
$user,