MediaWiki REL1_32
MWCallableUpdateTest.php
Go to the documentation of this file.
1<?php
2
6class MWCallableUpdateTest extends PHPUnit\Framework\TestCase {
7
8 use MediaWikiCoversValidator;
9
10 public function testDoUpdate() {
11 $ran = 0;
12 $update = new MWCallableUpdate( function () use ( &$ran ) {
13 $ran++;
14 } );
15 $this->assertSame( 0, $ran );
16 $update->doUpdate();
17 $this->assertSame( 1, $ran );
18 }
19
20 public function testCancel() {
21 // Prepare update and DB
22 $db = new DatabaseTestHelper( __METHOD__ );
23 $db->begin( __METHOD__ );
24 $ran = 0;
25 $update = new MWCallableUpdate( function () use ( &$ran ) {
26 $ran++;
27 }, __METHOD__, $db );
28
29 // Emulate rollback
30 $db->rollback( __METHOD__ );
31
32 $update->doUpdate();
33
34 // Ensure it was cancelled
35 $this->assertSame( 0, $ran );
36 }
37
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__ );
44 $ran = 0;
45 $update = new MWCallableUpdate( function () use ( &$ran ) {
46 $ran++;
47 }, __METHOD__, [ $db1, $db2 ] );
48
49 // Emulate rollback
50 $db1->rollback( __METHOD__ );
51
52 $update->doUpdate();
53
54 // Prevents: "Notice: DB transaction writes or callbacks still pending"
55 $db2->rollback( __METHOD__ );
56
57 // Ensure it was cancelled
58 $this->assertSame( 0, $ran );
59 }
60
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__ );
67 $ran = 0;
68 $update = new MWCallableUpdate( function () use ( &$ran ) {
69 $ran++;
70 }, __METHOD__, [ $db1, $db2 ] );
71
72 // Emulate rollbacks
73 $db1->rollback( __METHOD__ );
74 $db2->rollback( __METHOD__ );
75
76 $update->doUpdate();
77
78 // Ensure it was cancelled
79 $this->assertSame( 0, $ran );
80 }
81
82}
Apache License January AND DISTRIBUTION Definitions License shall mean the terms and conditions for use
Helper for testing the methods from the Database class.
Deferrable Update for closure/callback.
doUpdate()
Perform the actual work.
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
Definition injection.txt:37