Merge "Exclude redirects from Special:Fewestrevisions"
[lhc/web/wiklou.git] / tests / phpunit / unit / includes / deferred / MWCallableUpdateTest.php
1 <?php
2
3 /**
4 * @covers MWCallableUpdate
5 */
6 class MWCallableUpdateTest extends MediaWikiUnitTestCase {
7
8 public function testDoUpdate() {
9 $ran = 0;
10 $update = new MWCallableUpdate( function () use ( &$ran ) {
11 $ran++;
12 } );
13 $this->assertSame( 0, $ran );
14 $update->doUpdate();
15 $this->assertSame( 1, $ran );
16 }
17
18 public function testCancel() {
19 // Prepare update and DB
20 $db = new DatabaseTestHelper( __METHOD__ );
21 $db->begin( __METHOD__ );
22 $ran = 0;
23 $update = new MWCallableUpdate( function () use ( &$ran ) {
24 $ran++;
25 }, __METHOD__, $db );
26
27 // Emulate rollback
28 $db->rollback( __METHOD__ );
29
30 $update->doUpdate();
31
32 // Ensure it was cancelled
33 $this->assertSame( 0, $ran );
34 }
35
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__ );
42 $ran = 0;
43 $update = new MWCallableUpdate( function () use ( &$ran ) {
44 $ran++;
45 }, __METHOD__, [ $db1, $db2 ] );
46
47 // Emulate rollback
48 $db1->rollback( __METHOD__ );
49
50 $update->doUpdate();
51
52 // Prevents: "Notice: DB transaction writes or callbacks still pending"
53 $db2->rollback( __METHOD__ );
54
55 // Ensure it was cancelled
56 $this->assertSame( 0, $ran );
57 }
58
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__ );
65 $ran = 0;
66 $update = new MWCallableUpdate( function () use ( &$ran ) {
67 $ran++;
68 }, __METHOD__, [ $db1, $db2 ] );
69
70 // Emulate rollbacks
71 $db1->rollback( __METHOD__ );
72 $db2->rollback( __METHOD__ );
73
74 $update->doUpdate();
75
76 // Ensure it was cancelled
77 $this->assertSame( 0, $ran );
78 }
79
80 }