4 * @covers MWCallableUpdate
6 class MWCallableUpdateTest
extends PHPUnit\Framework\TestCase
{
8 use MediaWikiCoversValidator
;
10 public function testDoUpdate() {
12 $update = new MWCallableUpdate( function () use ( &$ran ) {
15 $this->assertSame( 0, $ran );
17 $this->assertSame( 1, $ran );
20 public function testCancel() {
21 // Prepare update and DB
22 $db = new DatabaseTestHelper( __METHOD__
);
23 $db->begin( __METHOD__
);
25 $update = new MWCallableUpdate( function () use ( &$ran ) {
30 $db->rollback( __METHOD__
);
34 // Ensure it was cancelled
35 $this->assertSame( 0, $ran );
38 public function testCancelSome() {
39 // Prepare update and DB
40 $db1 = new DatabaseTestHelper( __METHOD__
);
41 $db1->begin( __METHOD__
);
42 $db2 = new DatabaseTestHelper( __METHOD__
);
43 $db2->begin( __METHOD__
);
45 $update = new MWCallableUpdate( function () use ( &$ran ) {
47 }, __METHOD__
, [ $db1, $db2 ] );
50 $db1->rollback( __METHOD__
);
54 // Prevents: "Notice: DB transaction writes or callbacks still pending"
55 $db2->rollback( __METHOD__
);
57 // Ensure it was cancelled
58 $this->assertSame( 0, $ran );
61 public function testCancelAll() {
62 // Prepare update and DB
63 $db1 = new DatabaseTestHelper( __METHOD__
);
64 $db1->begin( __METHOD__
);
65 $db2 = new DatabaseTestHelper( __METHOD__
);
66 $db2->begin( __METHOD__
);
68 $update = new MWCallableUpdate( function () use ( &$ran ) {
70 }, __METHOD__
, [ $db1, $db2 ] );
73 $db1->rollback( __METHOD__
);
74 $db2->rollback( __METHOD__
);
78 // Ensure it was cancelled
79 $this->assertSame( 0, $ran );