MediaWiki  1.28.0
DeferredUpdatesTest.php
Go to the documentation of this file.
1 <?php
2 
4  public function testDoUpdatesWeb() {
5  $this->setMwGlobals( 'wgCommandLineMode', false );
6 
7  $updates = [
8  '1' => "deferred update 1;\n",
9  '2' => "deferred update 2;\n",
10  '2-1' => "deferred update 1 within deferred update 2;\n",
11  '2-2' => "deferred update 2 within deferred update 2;\n",
12  '3' => "deferred update 3;\n",
13  '3-1' => "deferred update 1 within deferred update 3;\n",
14  '3-2' => "deferred update 2 within deferred update 3;\n",
15  '3-1-1' => "deferred update 1 within deferred update 1 within deferred update 3;\n",
16  '3-2-1' => "deferred update 1 within deferred update 2 with deferred update 3;\n",
17  ];
19  function () use ( $updates ) {
20  echo $updates['1'];
21  }
22  );
24  function () use ( $updates ) {
25  echo $updates['2'];
27  function () use ( $updates ) {
28  echo $updates['2-1'];
29  }
30  );
32  function () use ( $updates ) {
33  echo $updates['2-2'];
34  }
35  );
36  }
37  );
39  function () use ( $updates ) {
40  echo $updates['3'];
42  function () use ( $updates ) {
43  echo $updates['3-1'];
45  function () use ( $updates ) {
46  echo $updates['3-1-1'];
47  }
48  );
49  }
50  );
52  function () use ( $updates ) {
53  echo $updates['3-2'];
55  function () use ( $updates ) {
56  echo $updates['3-2-1'];
57  }
58  );
59  }
60  );
61  }
62  );
63 
64  $this->assertEquals( 3, DeferredUpdates::pendingUpdatesCount() );
65 
66  $this->expectOutputString( implode( '', $updates ) );
67 
69 
70  $x = null;
71  $y = null;
73  function () use ( &$x ) {
74  $x = 'Sherity';
75  },
77  );
79  function () use ( &$y ) {
80  $y = 'Marychu';
81  },
83  );
84 
85  $this->assertNull( $x, "Update not run yet" );
86  $this->assertNull( $y, "Update not run yet" );
87 
89  $this->assertEquals( "Sherity", $x, "PRESEND update ran" );
90  $this->assertNull( $y, "POSTSEND update not run yet" );
91 
93  $this->assertEquals( "Marychu", $y, "POSTSEND update ran" );
94  }
95 
96  public function testDoUpdatesCLI() {
97  $this->setMwGlobals( 'wgCommandLineMode', true );
98  $updates = [
99  '1' => "deferred update 1;\n",
100  '2' => "deferred update 2;\n",
101  '2-1' => "deferred update 1 within deferred update 2;\n",
102  '2-2' => "deferred update 2 within deferred update 2;\n",
103  '3' => "deferred update 3;\n",
104  '3-1' => "deferred update 1 within deferred update 3;\n",
105  '3-2' => "deferred update 2 within deferred update 3;\n",
106  '3-1-1' => "deferred update 1 within deferred update 1 within deferred update 3;\n",
107  '3-2-1' => "deferred update 1 within deferred update 2 with deferred update 3;\n",
108  ];
109 
110  wfGetLBFactory()->commitMasterChanges( __METHOD__ ); // clear anything
111 
113  function () use ( $updates ) {
114  echo $updates['1'];
115  }
116  );
118  function () use ( $updates ) {
119  echo $updates['2'];
121  function () use ( $updates ) {
122  echo $updates['2-1'];
123  }
124  );
126  function () use ( $updates ) {
127  echo $updates['2-2'];
128  }
129  );
130  }
131  );
133  function () use ( $updates ) {
134  echo $updates['3'];
136  function () use ( $updates ) {
137  echo $updates['3-1'];
139  function () use ( $updates ) {
140  echo $updates['3-1-1'];
141  }
142  );
143  }
144  );
146  function () use ( $updates ) {
147  echo $updates['3-2'];
149  function () use ( $updates ) {
150  echo $updates['3-2-1'];
151  }
152  );
153  }
154  );
155  }
156  );
157 
158  $this->expectOutputString( implode( '', $updates ) );
159 
161  }
162 }
Apache License January AND DISTRIBUTION Definitions License shall mean the terms and conditions for use
static doUpdates($mode= 'run', $stage=self::ALL)
Do any deferred updates and clear the list.
static pendingUpdatesCount()
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:35
wfGetLBFactory()
Get the load balancer factory object.
static addCallableUpdate($callable, $stage=self::POSTSEND, IDatabase $dbw=null)
Add a callable update.
setMwGlobals($pairs, $value=null)