wiki.techinc.nl/tests/phpunit/unit/includes/deferred/MWCallableUpdateTest.php
Umherirrender a3a9cf99cb tests: Use namespaced class names in @covers annotations
Assist from 8c9cb701e56226cac43fee2fa24b0d0e586f1733

Change-Id: I47897c499028d9e24c00ad0bc6ba7fd8002d9bc1
2024-01-27 01:11:07 +01:00

82 lines
1.9 KiB
PHP

<?php
use MediaWiki\Deferred\MWCallableUpdate;
/**
* @covers \MediaWiki\Deferred\MWCallableUpdate
*/
class MWCallableUpdateTest extends MediaWikiUnitTestCase {
public function testDoUpdate() {
$ran = 0;
$update = new MWCallableUpdate( static function () use ( &$ran ) {
$ran++;
} );
$this->assertSame( 0, $ran );
$update->doUpdate();
$this->assertSame( 1, $ran );
}
public function testCancel() {
// Prepare update and DB
$db = new DatabaseTestHelper( __METHOD__ );
$db->begin( __METHOD__ );
$ran = 0;
$update = new MWCallableUpdate( static function () use ( &$ran ) {
$ran++;
}, __METHOD__, $db );
// Emulate rollback
$db->rollback( __METHOD__ );
$update->doUpdate();
// Ensure it was cancelled
$this->assertSame( 0, $ran );
}
public function testCancelSome() {
// Prepare update and DB
$db1 = new DatabaseTestHelper( __METHOD__ );
$db1->begin( __METHOD__ );
$db2 = new DatabaseTestHelper( __METHOD__ );
$db2->begin( __METHOD__ );
$ran = 0;
$update = new MWCallableUpdate( static function () use ( &$ran ) {
$ran++;
}, __METHOD__, [ $db1, $db2 ] );
// Emulate rollback
$db1->rollback( __METHOD__ );
$update->doUpdate();
// Prevents: "Notice: DB transaction writes or callbacks still pending"
$db2->rollback( __METHOD__ );
// Ensure it was cancelled
$this->assertSame( 0, $ran );
}
public function testCancelAll() {
// Prepare update and DB
$db1 = new DatabaseTestHelper( __METHOD__ );
$db1->begin( __METHOD__ );
$db2 = new DatabaseTestHelper( __METHOD__ );
$db2->begin( __METHOD__ );
$ran = 0;
$update = new MWCallableUpdate( static function () use ( &$ran ) {
$ran++;
}, __METHOD__, [ $db1, $db2 ] );
// Emulate rollbacks
$db1->rollback( __METHOD__ );
$db2->rollback( __METHOD__ );
$update->doUpdate();
// Ensure it was cancelled
$this->assertSame( 0, $ran );
}
}