A unit test that worked fine in MediaWiki 1.26 throws an error in MediaWiki 1.27.
PHP Notice: Uncommitted DB writes (transaction from DatabaseBase::query (LinkCache::addLinkObj)). in /home/wiki/wiki/wiki/includes/db/Database.php on line 3303 PHP Stack trace: PHP 1. {main}() /home/wiki/wiki/wiki/tests/phpunit/phpunit.php:0 PHP 2. PHPUnit_TextUI_Command::main() /home/wiki/wiki/wiki/tests/phpunit/phpunit.php:262 PHP 3. PHPUnit_TextUI_Command->run() /home/wiki/wiki/wiki/vendor/phpunit/phpunit/src/TextUI/Command.php:100 PHP 4. DatabaseBase->__destruct() /home/wiki/wiki/wiki/includes/db/Database.php:0 PHP 5. trigger_error() /home/wiki/wiki/wiki/includes/db/Database.php:3303
Here is a minimal example, which performs two calls to MovePage::move. The second call causes the error.
<?php /** * @group BadTest * @group Database * @group Destructive */ class BadTest extends MediaWikiTestCase { protected function setUp() { parent::setUp(); $this->tablesUsed[] = 'page'; } public function testMoveBug() { $pageName = 'Foobar'; $talkPageName = 'Talk:' . $pageName; $user = RequestContext::getMain()->getUser(); foreach ( array($pageName, $talkPageName) as $name ) { $page = WikiPage::factory( Title::newFromText($name) ); $page->doEditContent( new WikitextContent( 'some content' ), 'my summary', EDIT_NEW, false, $user ); } // Move a page $source = Title::newFromText($pageName); $dest = Title::newFromText('whatever'); $mp = new MovePage($source, $dest); $mp->move($user, 'some reason', true); // Move a second page $sourceTalk = Title::newFromText($talkPageName); $destTalk = Title::newFromText('Talk:anything'); $mp = new MovePage($sourceTalk, $destTalk); // If you comment out the next line, the error disappears $mp->move($user, 'some reason', true); $this->assertTrue(true); } }
To reproduce, use --group BadTest.
If you comment out the second call to $mp->move, the error disappears.
The error happens only during unit testing, not when the code is run normally on a MediaWiki site.