MediaWiki  1.29.2
DeferredUpdatesTest.php
Go to the documentation of this file.
1 <?php
2 
4 
8  public function testGetPendingUpdates() {
9  # Prevent updates from running
10  $this->setMwGlobals( 'wgCommandLineMode', false );
11 
14  $all = DeferredUpdates::ALL;
15 
16  $update = $this->getMockBuilder( 'DeferrableUpdate' )
17  ->getMock();
18  $update->expects( $this->never() )
19  ->method( 'doUpdate' );
20 
21  DeferredUpdates::addUpdate( $update, $pre );
22  $this->assertCount( 1, DeferredUpdates::getPendingUpdates( $pre ) );
23  $this->assertCount( 0, DeferredUpdates::getPendingUpdates( $post ) );
24  $this->assertCount( 1, DeferredUpdates::getPendingUpdates( $all ) );
25  $this->assertCount( 1, DeferredUpdates::getPendingUpdates() );
27  $this->assertCount( 0, DeferredUpdates::getPendingUpdates() );
28 
29  DeferredUpdates::addUpdate( $update, $post );
30  $this->assertCount( 0, DeferredUpdates::getPendingUpdates( $pre ) );
31  $this->assertCount( 1, DeferredUpdates::getPendingUpdates( $post ) );
32  $this->assertCount( 1, DeferredUpdates::getPendingUpdates( $all ) );
33  $this->assertCount( 1, DeferredUpdates::getPendingUpdates() );
35  $this->assertCount( 0, DeferredUpdates::getPendingUpdates() );
36  }
37 
38  public function testDoUpdatesWeb() {
39  $this->setMwGlobals( 'wgCommandLineMode', false );
40 
41  $updates = [
42  '1' => "deferred update 1;\n",
43  '2' => "deferred update 2;\n",
44  '2-1' => "deferred update 1 within deferred update 2;\n",
45  '2-2' => "deferred update 2 within deferred update 2;\n",
46  '3' => "deferred update 3;\n",
47  '3-1' => "deferred update 1 within deferred update 3;\n",
48  '3-2' => "deferred update 2 within deferred update 3;\n",
49  '3-1-1' => "deferred update 1 within deferred update 1 within deferred update 3;\n",
50  '3-2-1' => "deferred update 1 within deferred update 2 with deferred update 3;\n",
51  ];
53  function () use ( $updates ) {
54  echo $updates['1'];
55  }
56  );
58  function () use ( $updates ) {
59  echo $updates['2'];
61  function () use ( $updates ) {
62  echo $updates['2-1'];
63  }
64  );
66  function () use ( $updates ) {
67  echo $updates['2-2'];
68  }
69  );
70  }
71  );
73  function () use ( $updates ) {
74  echo $updates['3'];
76  function () use ( $updates ) {
77  echo $updates['3-1'];
79  function () use ( $updates ) {
80  echo $updates['3-1-1'];
81  }
82  );
83  }
84  );
86  function () use ( $updates ) {
87  echo $updates['3-2'];
89  function () use ( $updates ) {
90  echo $updates['3-2-1'];
91  }
92  );
93  }
94  );
95  }
96  );
97 
98  $this->assertEquals( 3, DeferredUpdates::pendingUpdatesCount() );
99 
100  $this->expectOutputString( implode( '', $updates ) );
101 
103 
104  $x = null;
105  $y = null;
107  function () use ( &$x ) {
108  $x = 'Sherity';
109  },
111  );
113  function () use ( &$y ) {
114  $y = 'Marychu';
115  },
117  );
118 
119  $this->assertNull( $x, "Update not run yet" );
120  $this->assertNull( $y, "Update not run yet" );
121 
123  $this->assertEquals( "Sherity", $x, "PRESEND update ran" );
124  $this->assertNull( $y, "POSTSEND update not run yet" );
125 
127  $this->assertEquals( "Marychu", $y, "POSTSEND update ran" );
128  }
129 
130  public function testDoUpdatesCLI() {
131  $this->setMwGlobals( 'wgCommandLineMode', true );
132  $updates = [
133  '1' => "deferred update 1;\n",
134  '2' => "deferred update 2;\n",
135  '2-1' => "deferred update 1 within deferred update 2;\n",
136  '2-2' => "deferred update 2 within deferred update 2;\n",
137  '3' => "deferred update 3;\n",
138  '3-1' => "deferred update 1 within deferred update 3;\n",
139  '3-2' => "deferred update 2 within deferred update 3;\n",
140  '3-1-1' => "deferred update 1 within deferred update 1 within deferred update 3;\n",
141  '3-2-1' => "deferred update 1 within deferred update 2 with deferred update 3;\n",
142  ];
143 
144  wfGetLBFactory()->commitMasterChanges( __METHOD__ ); // clear anything
145 
147  function () use ( $updates ) {
148  echo $updates['1'];
149  }
150  );
152  function () use ( $updates ) {
153  echo $updates['2'];
155  function () use ( $updates ) {
156  echo $updates['2-1'];
157  }
158  );
160  function () use ( $updates ) {
161  echo $updates['2-2'];
162  }
163  );
164  }
165  );
167  function () use ( $updates ) {
168  echo $updates['3'];
170  function () use ( $updates ) {
171  echo $updates['3-1'];
173  function () use ( $updates ) {
174  echo $updates['3-1-1'];
175  }
176  );
177  }
178  );
180  function () use ( $updates ) {
181  echo $updates['3-2'];
183  function () use ( $updates ) {
184  echo $updates['3-2-1'];
185  }
186  );
187  }
188  );
189  }
190  );
191 
192  $this->expectOutputString( implode( '', $updates ) );
193 
195  }
196 
197  public function testPresendAddOnPostsendRun() {
198  $this->setMwGlobals( 'wgCommandLineMode', true );
199 
200  $x = false;
201  $y = false;
202  wfGetLBFactory()->commitMasterChanges( __METHOD__ ); // clear anything
203 
205  function () use ( &$x, &$y ) {
206  $x = true;
208  function () use ( &$y ) {
209  $y = true;
210  },
212  );
213  },
215  );
216 
218 
219  $this->assertTrue( $x, "Outer POSTSEND update ran" );
220  $this->assertTrue( $y, "Nested PRESEND update ran" );
221  }
222 }
DeferredUpdates\ALL
const ALL
Definition: DeferredUpdates.php:59
use
as see the revision history and available at free of to any person obtaining a copy of this software and associated documentation to deal in the Software without including without limitation the rights to use
Definition: MIT-LICENSE.txt:10
DeferredUpdates\addUpdate
static addUpdate(DeferrableUpdate $update, $stage=self::POSTSEND)
Add an update to the deferred list to be run later by execute()
Definition: DeferredUpdates.php:76
DeferredUpdates\clearPendingUpdates
static clearPendingUpdates()
Clear all pending updates without performing them.
Definition: DeferredUpdates.php:351
php
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
DeferredUpdates\addCallableUpdate
static addCallableUpdate( $callable, $stage=self::POSTSEND, IDatabase $dbw=null)
Add a callable update.
Definition: DeferredUpdates.php:111
DeferredUpdatesTest\testPresendAddOnPostsendRun
testPresendAddOnPostsendRun()
Definition: DeferredUpdatesTest.php:197
DeferredUpdatesTest
Definition: DeferredUpdatesTest.php:3
MediaWikiTestCase\setMwGlobals
setMwGlobals( $pairs, $value=null)
Definition: MediaWikiTestCase.php:658
MediaWikiTestCase
Definition: MediaWikiTestCase.php:13
DeferredUpdates\POSTSEND
const POSTSEND
Definition: DeferredUpdates.php:61
DeferredUpdatesTest\testDoUpdatesWeb
testDoUpdatesWeb()
Definition: DeferredUpdatesTest.php:38
DeferredUpdatesTest\testGetPendingUpdates
testGetPendingUpdates()
DeferredUpdates::getPendingUpdates.
Definition: DeferredUpdatesTest.php:8
wfGetLBFactory
wfGetLBFactory()
Get the load balancer factory object.
Definition: GlobalFunctions.php:3089
DeferredUpdates\doUpdates
static doUpdates( $mode='run', $stage=self::ALL)
Do any deferred updates and clear the list.
Definition: DeferredUpdates.php:123
DeferredUpdates\pendingUpdatesCount
static pendingUpdatesCount()
Definition: DeferredUpdates.php:328
DeferredUpdates\PRESEND
const PRESEND
Definition: DeferredUpdates.php:60
DeferredUpdates\getPendingUpdates
static getPendingUpdates( $stage=self::ALL)
Definition: DeferredUpdates.php:336
DeferredUpdatesTest\testDoUpdatesCLI
testDoUpdatesCLI()
Definition: DeferredUpdatesTest.php:130
$pre
return true to allow those checks to and false if checking is done remove or add to the links of a group of changes in EnhancedChangesList Hook subscribers can return false to omit this line from recentchanges use this to change the tables headers temp or archived zone change it to an object instance and return false override the list derivative used the name of the old file when set the default code will be skipped $pre
Definition: hooks.txt:1459