4 * @covers MWCallableUpdate
6 class MWCallableUpdateTest
extends MediaWikiUnitTestCase
{
8 public function testDoUpdate() {
10 $update = new MWCallableUpdate( function () use ( &$ran ) {
13 $this->assertSame( 0, $ran );
15 $this->assertSame( 1, $ran );
18 public function testCancel() {
19 // Prepare update and DB
20 $db = new DatabaseTestHelper( __METHOD__
);
21 $db->begin( __METHOD__
);
23 $update = new MWCallableUpdate( function () use ( &$ran ) {
28 $db->rollback( __METHOD__
);
32 // Ensure it was cancelled
33 $this->assertSame( 0, $ran );
36 public function testCancelSome() {
37 // Prepare update and DB
38 $db1 = new DatabaseTestHelper( __METHOD__
);
39 $db1->begin( __METHOD__
);
40 $db2 = new DatabaseTestHelper( __METHOD__
);
41 $db2->begin( __METHOD__
);
43 $update = new MWCallableUpdate( function () use ( &$ran ) {
45 }, __METHOD__
, [ $db1, $db2 ] );
48 $db1->rollback( __METHOD__
);
52 // Prevents: "Notice: DB transaction writes or callbacks still pending"
53 $db2->rollback( __METHOD__
);
55 // Ensure it was cancelled
56 $this->assertSame( 0, $ran );
59 public function testCancelAll() {
60 // Prepare update and DB
61 $db1 = new DatabaseTestHelper( __METHOD__
);
62 $db1->begin( __METHOD__
);
63 $db2 = new DatabaseTestHelper( __METHOD__
);
64 $db2->begin( __METHOD__
);
66 $update = new MWCallableUpdate( function () use ( &$ran ) {
68 }, __METHOD__
, [ $db1, $db2 ] );
71 $db1->rollback( __METHOD__
);
72 $db2->rollback( __METHOD__
);
76 // Ensure it was cancelled
77 $this->assertSame( 0, $ran );