MediaWiki  1.30.0
MaintenanceTest.php
Go to the documentation of this file.
1 <?php
2 
3 // It would be great if we were able to use PHPUnit's getMockForAbstractClass
4 // instead of the MaintenanceFixup hack below. However, we cannot do
5 // without changing the visibility and without working around hacks in
6 // Maintenance.php
7 // For the same reason, we cannot just use FakeMaintenance.
9 
29 
30  // --- Making up for the register_shutdown_function hack in Maintenance.php
31 
42  private $testCase;
43 
49  private $shutdownSimulated = false;
50 
54  public function simulateShutdown() {
55  if ( $this->shutdownSimulated ) {
56  $this->testCase->fail( __METHOD__ . " called more than once" );
57  }
58 
59  // The cleanup action.
60  $this->outputChanneled( false );
61 
62  // Bookkeeping that we simulated the clean up.
63  $this->shutdownSimulated = true;
64  }
65 
66  // Note that the "public" here does not change visibility
67  public function outputChanneled( $msg, $channel = null ) {
68  if ( $this->shutdownSimulated ) {
69  if ( $msg !== false ) {
70  $this->testCase->fail( "Already past simulated shutdown, but msg is "
71  . "not false. Did the hack in Maintenance.php change? Please "
72  . "adapt the test case or Maintenance.php" );
73  }
74 
75  // The current call is the one registered via register_shutdown_function.
76  // We can safely ignore it, as we simulated this one via simulateShutdown
77  // before (if we did not, the destructor of this instance will warn about
78  // it)
79  return;
80  }
81 
82  call_user_func_array( [ "parent", __FUNCTION__ ], func_get_args() );
83  }
84 
88  public function __destruct() {
89  if ( !$this->shutdownSimulated ) {
90  // Someone generated a MaintenanceFixup instance without calling
91  // simulateShutdown. We'd have to raise a PHPUnit exception to correctly
92  // flag this illegal usage. However, we are already in a destruktor, which
93  // would trigger undefined behavior. Hence, we can only report to the
94  // error output :( Hopefully people read the PHPUnit output.
95  $name = $this->testCase->getName();
96  fwrite( STDERR, "ERROR! Instance of " . __CLASS__ . " for test $name "
97  . "destructed without calling simulateShutdown method. Call "
98  . "simulateShutdown on the instance before it gets destructed." );
99  }
100 
101  // The following guard is required, as PHP does not offer default destructors :(
102  if ( is_callable( "parent::__destruct" ) ) {
103  parent::__destruct();
104  }
105  }
106 
108  parent::__construct();
109  $this->testCase = $testCase;
110  }
111 
112  // --- Making protected functions visible for test
113 
114  public function output( $out, $channel = null ) {
115  // Just to make PHP not nag about signature mismatches, we copied
116  // Maintenance::output signature. However, we do not use (or rely on)
117  // those variables. Instead we pass to Maintenance::output whatever we
118  // receive at runtime.
119  return call_user_func_array( [ "parent", __FUNCTION__ ], func_get_args() );
120  }
121 
122  public function addOption( $name, $description, $required = false,
123  $withArg = false, $shortName = false, $multiOccurance = false
124  ) {
125  return call_user_func_array( [ "parent", __FUNCTION__ ], func_get_args() );
126  }
127 
128  public function getOption( $name, $default = null ) {
129  return call_user_func_array( [ "parent", __FUNCTION__ ], func_get_args() );
130  }
131 
132  // --- Requirements for getting instance of abstract class
133 
134  public function execute() {
135  $this->testCase->fail( __METHOD__ . " called unexpectedly" );
136  }
137 }
138 
143 
149  private $m;
150 
151  protected function setUp() {
152  parent::setUp();
153  $this->m = new MaintenanceFixup( $this );
154  }
155 
156  protected function tearDown() {
157  if ( $this->m ) {
158  $this->m->simulateShutdown();
159  $this->m = null;
160  }
161  parent::tearDown();
162  }
163 
176  private function assertOutputPrePostShutdown( $preShutdownOutput, $expectNLAppending ) {
177  $this->assertEquals( $preShutdownOutput, $this->getActualOutput(),
178  "Output before shutdown simulation" );
179 
180  $this->m->simulateShutdown();
181  $this->m = null;
182 
183  $postShutdownOutput = $preShutdownOutput . ( $expectNLAppending ? "\n" : "" );
184  $this->expectOutputString( $postShutdownOutput );
185  }
186 
187  // Although the following tests do not seem to be too consistent (compare for
188  // example the newlines within the test.*StringString tests, or the
189  // test.*Intermittent.* tests), the objective of these tests is not to describe
190  // consistent behavior, but rather currently existing behavior.
191 
192  function testOutputEmpty() {
193  $this->m->output( "" );
194  $this->assertOutputPrePostShutdown( "", false );
195  }
196 
197  function testOutputString() {
198  $this->m->output( "foo" );
199  $this->assertOutputPrePostShutdown( "foo", false );
200  }
201 
203  $this->m->output( "foo" );
204  $this->m->output( "bar" );
205  $this->assertOutputPrePostShutdown( "foobar", false );
206  }
207 
208  function testOutputStringNL() {
209  $this->m->output( "foo\n" );
210  $this->assertOutputPrePostShutdown( "foo\n", false );
211  }
212 
213  function testOutputStringNLNL() {
214  $this->m->output( "foo\n\n" );
215  $this->assertOutputPrePostShutdown( "foo\n\n", false );
216  }
217 
219  $this->m->output( "foo\nbar" );
220  $this->assertOutputPrePostShutdown( "foo\nbar", false );
221  }
222 
224  $this->m->output( "foo\nbar\n" );
225  $this->assertOutputPrePostShutdown( "foo\nbar\n", false );
226  }
227 
229  $this->m->output( "foo\n" );
230  $this->m->output( "bar\n" );
231  $this->assertOutputPrePostShutdown( "foo\nbar\n", false );
232  }
233 
235  $this->m->output( "" );
236  $this->m->output( "foo" );
237  $this->m->output( "" );
238  $this->m->output( "\n" );
239  $this->m->output( "ba" );
240  $this->m->output( "" );
241  $this->m->output( "r\n" );
242  $this->assertOutputPrePostShutdown( "foo\nbar\n", false );
243  }
244 
246  $this->m->output( "" );
247  $this->m->output( "foo" );
248  $this->m->output( "" );
249  $this->m->output( "\nb" );
250  $this->m->output( "a" );
251  $this->m->output( "" );
252  $this->m->output( "r\n" );
253  $this->assertOutputPrePostShutdown( "foo\nbar\n", false );
254  }
255 
257  $this->m->output( "", null );
258  $this->assertOutputPrePostShutdown( "", false );
259  }
260 
262  $this->m->output( "foo", null );
263  $this->assertOutputPrePostShutdown( "foo", false );
264  }
265 
267  $this->m->output( "foo", null );
268  $this->m->output( "bar", null );
269  $this->assertOutputPrePostShutdown( "foobar", false );
270  }
271 
273  $this->m->output( "foo\n", null );
274  $this->assertOutputPrePostShutdown( "foo\n", false );
275  }
276 
278  $this->m->output( "foo\n\n", null );
279  $this->assertOutputPrePostShutdown( "foo\n\n", false );
280  }
281 
283  $this->m->output( "foo\nbar", null );
284  $this->assertOutputPrePostShutdown( "foo\nbar", false );
285  }
286 
288  $this->m->output( "foo\nbar\n", null );
289  $this->assertOutputPrePostShutdown( "foo\nbar\n", false );
290  }
291 
293  $this->m->output( "foo\n", null );
294  $this->m->output( "bar\n", null );
295  $this->assertOutputPrePostShutdown( "foo\nbar\n", false );
296  }
297 
299  $this->m->output( "", null );
300  $this->m->output( "foo", null );
301  $this->m->output( "", null );
302  $this->m->output( "\n", null );
303  $this->m->output( "ba", null );
304  $this->m->output( "", null );
305  $this->m->output( "r\n", null );
306  $this->assertOutputPrePostShutdown( "foo\nbar\n", false );
307  }
308 
310  $this->m->output( "", null );
311  $this->m->output( "foo", null );
312  $this->m->output( "", null );
313  $this->m->output( "\nb", null );
314  $this->m->output( "a", null );
315  $this->m->output( "", null );
316  $this->m->output( "r\n", null );
317  $this->assertOutputPrePostShutdown( "foo\nbar\n", false );
318  }
319 
321  $this->m->output( "foo", "bazChannel" );
322  $this->assertOutputPrePostShutdown( "foo", true );
323  }
324 
326  $this->m->output( "foo\n", "bazChannel" );
327  $this->assertOutputPrePostShutdown( "foo", true );
328  }
329 
331  // If this test fails, note that output takes strings with double line
332  // endings (although output's implementation in this situation calls
333  // outputChanneled with a string ending in a nl ... which is not allowed
334  // according to the documentation of outputChanneled)
335  $this->m->output( "foo\n\n", "bazChannel" );
336  $this->assertOutputPrePostShutdown( "foo\n", true );
337  }
338 
340  $this->m->output( "foo\nbar", "bazChannel" );
341  $this->assertOutputPrePostShutdown( "foo\nbar", true );
342  }
343 
345  $this->m->output( "foo\nbar\n", "bazChannel" );
346  $this->assertOutputPrePostShutdown( "foo\nbar", true );
347  }
348 
350  $this->m->output( "foo\n", "bazChannel" );
351  $this->m->output( "bar\n", "bazChannel" );
352  $this->assertOutputPrePostShutdown( "foobar", true );
353  }
354 
356  $this->m->output( "", "bazChannel" );
357  $this->m->output( "foo", "bazChannel" );
358  $this->m->output( "", "bazChannel" );
359  $this->m->output( "\n", "bazChannel" );
360  $this->m->output( "ba", "bazChannel" );
361  $this->m->output( "", "bazChannel" );
362  $this->m->output( "r\n", "bazChannel" );
363  $this->assertOutputPrePostShutdown( "foobar", true );
364  }
365 
367  $this->m->output( "", "bazChannel" );
368  $this->m->output( "foo", "bazChannel" );
369  $this->m->output( "", "bazChannel" );
370  $this->m->output( "\nb", "bazChannel" );
371  $this->m->output( "a", "bazChannel" );
372  $this->m->output( "", "bazChannel" );
373  $this->m->output( "r\n", "bazChannel" );
374  $this->assertOutputPrePostShutdown( "foo\nbar", true );
375  }
376 
378  $this->m->output( "foo", "bazChannel" );
379  $this->m->output( "bar", "bazChannel" );
380  $this->m->output( "qux", "quuxChannel" );
381  $this->m->output( "corge", "bazChannel" );
382  $this->assertOutputPrePostShutdown( "foobar\nqux\ncorge", true );
383  }
384 
386  $this->m->output( "foo", "bazChannel" );
387  $this->m->output( "bar\n", "bazChannel" );
388  $this->m->output( "qux\n", "quuxChannel" );
389  $this->m->output( "corge", "bazChannel" );
390  $this->assertOutputPrePostShutdown( "foobar\nqux\ncorge", true );
391  }
392 
394  $this->m->output( "foo" );
395  $this->m->output( "bar", "bazChannel" );
396  $this->m->output( "qux" );
397  $this->m->output( "quux", "bazChannel" );
398  $this->assertOutputPrePostShutdown( "foobar\nquxquux", true );
399  }
400 
402  $this->m->output( "foo", "bazChannel" );
403  $this->m->output( "bar" );
404  $this->m->output( "qux", "bazChannel" );
405  $this->m->output( "quux" );
406  $this->assertOutputPrePostShutdown( "foo\nbarqux\nquux", false );
407  }
408 
410  $this->m->output( "foo", 1 );
411  $this->m->output( "bar", 1.0 );
412  $this->assertOutputPrePostShutdown( "foo\nbar", true );
413  }
414 
416  $this->m->output( "foo" );
417  $this->m->output( "" );
418  $this->m->output( "bar" );
419  $this->assertOutputPrePostShutdown( "foobar", false );
420  }
421 
423  $this->m->output( "foo" );
424  $this->m->output( false );
425  $this->m->output( "bar" );
426  $this->assertOutputPrePostShutdown( "foobar", false );
427  }
428 
430  $this->m->output( "qux", "quuxChannel" );
431  $this->m->output( "foo" );
432  $this->m->output( false );
433  $this->m->output( "bar" );
434  $this->assertOutputPrePostShutdown( "qux\nfoobar", false );
435  }
436 
438  $this->m->output( "foo", null );
439  $this->m->output( "", null );
440  $this->m->output( "bar", null );
441  $this->assertOutputPrePostShutdown( "foobar", false );
442  }
443 
445  $this->m->output( "foo", null );
446  $this->m->output( false, null );
447  $this->m->output( "bar", null );
448  $this->assertOutputPrePostShutdown( "foobar", false );
449  }
450 
452  $this->m->output( "foo", "bazChannel" );
453  $this->m->output( "", "bazChannel" );
454  $this->m->output( "bar", "bazChannel" );
455  $this->assertOutputPrePostShutdown( "foobar", true );
456  }
457 
459  $this->m->output( "foo", "bazChannel" );
460  $this->m->output( false, "bazChannel" );
461  $this->m->output( "bar", "bazChannel" );
462  $this->assertOutputPrePostShutdown( "foobar", true );
463  }
464 
465  // Note that (per documentation) outputChanneled does take strings that end
466  // in \n, hence we do not test such strings.
467 
469  $this->m->outputChanneled( "" );
470  $this->assertOutputPrePostShutdown( "\n", false );
471  }
472 
474  $this->m->outputChanneled( "foo" );
475  $this->assertOutputPrePostShutdown( "foo\n", false );
476  }
477 
479  $this->m->outputChanneled( "foo" );
480  $this->m->outputChanneled( "bar" );
481  $this->assertOutputPrePostShutdown( "foo\nbar\n", false );
482  }
483 
485  $this->m->outputChanneled( "foo\nbar" );
486  $this->assertOutputPrePostShutdown( "foo\nbar\n", false );
487  }
488 
490  $this->m->outputChanneled( "" );
491  $this->m->outputChanneled( "foo" );
492  $this->m->outputChanneled( "" );
493  $this->m->outputChanneled( "\nb" );
494  $this->m->outputChanneled( "a" );
495  $this->m->outputChanneled( "" );
496  $this->m->outputChanneled( "r" );
497  $this->assertOutputPrePostShutdown( "\nfoo\n\n\nb\na\n\nr\n", false );
498  }
499 
501  $this->m->outputChanneled( "", null );
502  $this->assertOutputPrePostShutdown( "\n", false );
503  }
504 
506  $this->m->outputChanneled( "foo", null );
507  $this->assertOutputPrePostShutdown( "foo\n", false );
508  }
509 
511  $this->m->outputChanneled( "foo", null );
512  $this->m->outputChanneled( "bar", null );
513  $this->assertOutputPrePostShutdown( "foo\nbar\n", false );
514  }
515 
517  $this->m->outputChanneled( "foo\nbar", null );
518  $this->assertOutputPrePostShutdown( "foo\nbar\n", false );
519  }
520 
522  $this->m->outputChanneled( "", null );
523  $this->m->outputChanneled( "foo", null );
524  $this->m->outputChanneled( "", null );
525  $this->m->outputChanneled( "\nb", null );
526  $this->m->outputChanneled( "a", null );
527  $this->m->outputChanneled( "", null );
528  $this->m->outputChanneled( "r", null );
529  $this->assertOutputPrePostShutdown( "\nfoo\n\n\nb\na\n\nr\n", false );
530  }
531 
533  $this->m->outputChanneled( "foo", "bazChannel" );
534  $this->assertOutputPrePostShutdown( "foo", true );
535  }
536 
538  $this->m->outputChanneled( "foo\nbar", "bazChannel" );
539  $this->assertOutputPrePostShutdown( "foo\nbar", true );
540  }
541 
543  $this->m->outputChanneled( "foo", "bazChannel" );
544  $this->m->outputChanneled( "bar", "bazChannel" );
545  $this->assertOutputPrePostShutdown( "foobar", true );
546  }
547 
549  $this->m->outputChanneled( "", "bazChannel" );
550  $this->m->outputChanneled( "foo", "bazChannel" );
551  $this->m->outputChanneled( "", "bazChannel" );
552  $this->m->outputChanneled( "\nb", "bazChannel" );
553  $this->m->outputChanneled( "a", "bazChannel" );
554  $this->m->outputChanneled( "", "bazChannel" );
555  $this->m->outputChanneled( "r", "bazChannel" );
556  $this->assertOutputPrePostShutdown( "foo\nbar", true );
557  }
558 
560  $this->m->outputChanneled( "foo", "bazChannel" );
561  $this->m->outputChanneled( "bar", "bazChannel" );
562  $this->m->outputChanneled( "qux", "quuxChannel" );
563  $this->m->outputChanneled( "corge", "bazChannel" );
564  $this->assertOutputPrePostShutdown( "foobar\nqux\ncorge", true );
565  }
566 
568  $this->m->outputChanneled( "foo", "bazChannel" );
569  $this->m->outputChanneled( "bar", null );
570  $this->m->outputChanneled( "qux", null );
571  $this->m->outputChanneled( "corge", "bazChannel" );
572  $this->assertOutputPrePostShutdown( "foo\nbar\nqux\ncorge", true );
573  }
574 
576  $this->m->outputChanneled( "foo", "bazChannel" );
577  $this->m->outputChanneled( "bar", null );
578  $this->m->outputChanneled( "qux", null );
579  $this->m->outputChanneled( "corge", "quuxChannel" );
580  $this->assertOutputPrePostShutdown( "foo\nbar\nqux\ncorge", true );
581  }
582 
584  $this->m->outputChanneled( "foo" );
585  $this->m->outputChanneled( "bar", "bazChannel" );
586  $this->m->outputChanneled( "qux" );
587  $this->m->outputChanneled( "quux", "bazChannel" );
588  $this->assertOutputPrePostShutdown( "foo\nbar\nqux\nquux", true );
589  }
590 
592  $this->m->outputChanneled( "foo", "bazChannel" );
593  $this->m->outputChanneled( "bar" );
594  $this->m->outputChanneled( "qux", "bazChannel" );
595  $this->m->outputChanneled( "quux" );
596  $this->assertOutputPrePostShutdown( "foo\nbar\nqux\nquux\n", false );
597  }
598 
600  $this->m->outputChanneled( "foo", 1 );
601  $this->m->outputChanneled( "bar", 1.0 );
602  $this->assertOutputPrePostShutdown( "foo\nbar", true );
603  }
604 
606  $this->m->outputChanneled( "foo" );
607  $this->m->outputChanneled( "" );
608  $this->m->outputChanneled( "bar" );
609  $this->assertOutputPrePostShutdown( "foo\n\nbar\n", false );
610  }
611 
613  $this->m->outputChanneled( "foo" );
614  $this->m->outputChanneled( false );
615  $this->m->outputChanneled( "bar" );
616  $this->assertOutputPrePostShutdown( "foo\nbar\n", false );
617  }
618 
620  $this->m->outputChanneled( "foo", null );
621  $this->m->outputChanneled( "", null );
622  $this->m->outputChanneled( "bar", null );
623  $this->assertOutputPrePostShutdown( "foo\n\nbar\n", false );
624  }
625 
627  $this->m->outputChanneled( "foo", null );
628  $this->m->outputChanneled( false, null );
629  $this->m->outputChanneled( "bar", null );
630  $this->assertOutputPrePostShutdown( "foo\nbar\n", false );
631  }
632 
634  $this->m->outputChanneled( "foo", "bazChannel" );
635  $this->m->outputChanneled( "", "bazChannel" );
636  $this->m->outputChanneled( "bar", "bazChannel" );
637  $this->assertOutputPrePostShutdown( "foobar", true );
638  }
639 
641  $this->m->outputChanneled( "foo", "bazChannel" );
642  $this->m->outputChanneled( false, "bazChannel" );
643  $this->m->outputChanneled( "bar", "bazChannel" );
644  $this->assertOutputPrePostShutdown( "foo\nbar", true );
645  }
646 
648  $this->m->cleanupChanneled();
649  $this->assertOutputPrePostShutdown( "", false );
650  }
651 
653  $this->m->output( "foo" );
654  $this->m->cleanupChanneled();
655  $this->assertOutputPrePostShutdown( "foo", false );
656  }
657 
659  $this->m->output( "foo", null );
660  $this->m->cleanupChanneled();
661  $this->assertOutputPrePostShutdown( "foo", false );
662  }
663 
665  $this->m->output( "foo", "bazChannel" );
666  $this->m->cleanupChanneled();
667  $this->assertOutputPrePostShutdown( "foo\n", false );
668  }
669 
671  $this->m->output( "foo\n" );
672  $this->m->cleanupChanneled();
673  $this->assertOutputPrePostShutdown( "foo\n", false );
674  }
675 
677  $this->m->output( "foo\n", null );
678  $this->m->cleanupChanneled();
679  $this->assertOutputPrePostShutdown( "foo\n", false );
680  }
681 
683  $this->m->output( "foo\n", "bazChannel" );
684  $this->m->cleanupChanneled();
685  $this->assertOutputPrePostShutdown( "foo\n", false );
686  }
687 
689  $this->m->outputChanneled( "foo" );
690  $this->m->cleanupChanneled();
691  $this->assertOutputPrePostShutdown( "foo\n", false );
692  }
693 
695  $this->m->outputChanneled( "foo", null );
696  $this->m->cleanupChanneled();
697  $this->assertOutputPrePostShutdown( "foo\n", false );
698  }
699 
701  $this->m->outputChanneled( "foo", "bazChannel" );
702  $this->m->cleanupChanneled();
703  $this->assertOutputPrePostShutdown( "foo\n", false );
704  }
705 
707  $m2 = new MaintenanceFixup( $this );
708 
709  $this->m->output( "foo" );
710  $m2->output( "bar" );
711 
712  $this->assertEquals( "foobar", $this->getActualOutput(),
713  "Output before shutdown simulation (m2)" );
714  $m2->simulateShutdown();
715  $this->assertOutputPrePostShutdown( "foobar", false );
716  }
717 
719  $m2 = new MaintenanceFixup( $this );
720 
721  $this->m->output( "foo", null );
722  $m2->output( "bar", null );
723 
724  $this->assertEquals( "foobar", $this->getActualOutput(),
725  "Output before shutdown simulation (m2)" );
726  $m2->simulateShutdown();
727  $this->assertOutputPrePostShutdown( "foobar", false );
728  }
729 
731  $m2 = new MaintenanceFixup( $this );
732 
733  $this->m->output( "foo", "bazChannel" );
734  $m2->output( "bar", "bazChannel" );
735 
736  $this->assertEquals( "foobar", $this->getActualOutput(),
737  "Output before shutdown simulation (m2)" );
738  $m2->simulateShutdown();
739  $this->assertOutputPrePostShutdown( "foobar\n", true );
740  }
741 
743  $m2 = new MaintenanceFixup( $this );
744 
745  $this->m->output( "foo\n", null );
746  $m2->output( "bar\n", null );
747 
748  $this->assertEquals( "foo\nbar\n", $this->getActualOutput(),
749  "Output before shutdown simulation (m2)" );
750  $m2->simulateShutdown();
751  $this->assertOutputPrePostShutdown( "foo\nbar\n", false );
752  }
753 
755  $m2 = new MaintenanceFixup( $this );
756 
757  $this->m->output( "foo\n", "bazChannel" );
758  $m2->output( "bar\n", "bazChannel" );
759 
760  $this->assertEquals( "foobar", $this->getActualOutput(),
761  "Output before shutdown simulation (m2)" );
762  $m2->simulateShutdown();
763  $this->assertOutputPrePostShutdown( "foobar\n", true );
764  }
765 
767  $m2 = new MaintenanceFixup( $this );
768 
769  $this->m->outputChanneled( "foo" );
770  $m2->outputChanneled( "bar" );
771 
772  $this->assertEquals( "foo\nbar\n", $this->getActualOutput(),
773  "Output before shutdown simulation (m2)" );
774  $m2->simulateShutdown();
775  $this->assertOutputPrePostShutdown( "foo\nbar\n", false );
776  }
777 
779  $m2 = new MaintenanceFixup( $this );
780 
781  $this->m->outputChanneled( "foo", null );
782  $m2->outputChanneled( "bar", null );
783 
784  $this->assertEquals( "foo\nbar\n", $this->getActualOutput(),
785  "Output before shutdown simulation (m2)" );
786  $m2->simulateShutdown();
787  $this->assertOutputPrePostShutdown( "foo\nbar\n", false );
788  }
789 
791  $m2 = new MaintenanceFixup( $this );
792 
793  $this->m->outputChanneled( "foo", "bazChannel" );
794  $m2->outputChanneled( "bar", "bazChannel" );
795 
796  $this->assertEquals( "foobar", $this->getActualOutput(),
797  "Output before shutdown simulation (m2)" );
798  $m2->simulateShutdown();
799  $this->assertOutputPrePostShutdown( "foobar\n", true );
800  }
801 
803  $m2 = new MaintenanceFixup( $this );
804 
805  $this->m->outputChanneled( "foo", "bazChannel" );
806  $m2->outputChanneled( "bar", "bazChannel" );
807 
808  $this->assertEquals( "foobar", $this->getActualOutput(),
809  "Output before first cleanup" );
810  $this->m->cleanupChanneled();
811  $this->assertEquals( "foobar\n", $this->getActualOutput(),
812  "Output after first cleanup" );
813  $m2->cleanupChanneled();
814  $this->assertEquals( "foobar\n\n", $this->getActualOutput(),
815  "Output after second cleanup" );
816 
817  $m2->simulateShutdown();
818  $this->assertOutputPrePostShutdown( "foobar\n\n", false );
819  }
820 
824  public function testGetConfig() {
825  $this->assertInstanceOf( 'Config', $this->m->getConfig() );
826  $this->assertSame(
827  MediaWikiServices::getInstance()->getMainConfig(),
828  $this->m->getConfig()
829  );
830  }
831 
835  public function testSetConfig() {
836  $conf = $this->createMock( 'Config' );
837  $this->m->setConfig( $conf );
838  $this->assertSame( $conf, $this->m->getConfig() );
839  }
840 
841  function testParseArgs() {
842  $m2 = new MaintenanceFixup( $this );
843  // Create an option with an argument allowed to be specified multiple times
844  $m2->addOption( 'multi', 'This option does stuff', false, true, false, true );
845  $m2->loadWithArgv( [ '--multi', 'this1', '--multi', 'this2' ] );
846 
847  $this->assertEquals( [ 'this1', 'this2' ], $m2->getOption( 'multi' ) );
848  $this->assertEquals( [ [ 'multi', 'this1' ], [ 'multi', 'this2' ] ],
849  $m2->orderedOptions );
850 
851  $m2->simulateShutdown();
852 
853  $m2 = new MaintenanceFixup( $this );
854 
855  $m2->addOption( 'multi', 'This option does stuff', false, false, false, true );
856  $m2->loadWithArgv( [ '--multi', '--multi' ] );
857 
858  $this->assertEquals( [ 1, 1 ], $m2->getOption( 'multi' ) );
859  $this->assertEquals( [ [ 'multi', 1 ], [ 'multi', 1 ] ], $m2->orderedOptions );
860 
861  $m2->simulateShutdown();
862 
863  $m2 = new MaintenanceFixup( $this );
864  // Create an option with an argument allowed to be specified multiple times
865  $m2->addOption( 'multi', 'This option doesn\'t actually support multiple occurrences' );
866  $m2->loadWithArgv( [ '--multi=yo' ] );
867 
868  $this->assertEquals( 'yo', $m2->getOption( 'multi' ) );
869  $this->assertEquals( [ [ 'multi', 'yo' ] ], $m2->orderedOptions );
870 
871  $m2->simulateShutdown();
872  }
873 }
MaintenanceFixup
makes parts of the API of Maintenance that is hidden by protected visibily visible for testing,...
Definition: MaintenanceTest.php:28
MaintenanceTest\testOutputWChannelStringNL
testOutputWChannelStringNL()
Definition: MaintenanceTest.php:325
MaintenanceTest\testOutputWNullChannelString
testOutputWNullChannelString()
Definition: MaintenanceTest.php:261
MaintenanceFixup\output
output( $out, $channel=null)
Throw some output to the user.
Definition: MaintenanceTest.php:114
MaintenanceTest\testMultipleMaintenanceObjectsInteractionOutputChanneled
testMultipleMaintenanceObjectsInteractionOutputChanneled()
Definition: MaintenanceTest.php:766
MaintenanceTest\setUp
setUp()
Definition: MaintenanceTest.php:151
MaintenanceTest\testOutputChanneledWAndWOChannelStringStartWO
testOutputChanneledWAndWOChannelStringStartWO()
Definition: MaintenanceTest.php:583
MaintenanceTest\testOutputWNullChannelStringNLString
testOutputWNullChannelStringNLString()
Definition: MaintenanceTest.php:282
MaintenanceTest\testMultipleMaintenanceObjectsInteractionCleanupChanneledWChannel
testMultipleMaintenanceObjectsInteractionCleanupChanneledWChannel()
Definition: MaintenanceTest.php:802
MaintenanceTest\testOutputWNullChannelEmpty
testOutputWNullChannelEmpty()
Definition: MaintenanceTest.php:256
MaintenanceTest\testCleanupChanneledAfterNLOutput
testCleanupChanneledAfterNLOutput()
Definition: MaintenanceTest.php:670
MaintenanceTest\testOutputWChannelStringNLNL
testOutputWChannelStringNLNL()
Definition: MaintenanceTest.php:330
MaintenanceTest\testOutputWMultipleChannelsChannelChange
testOutputWMultipleChannelsChannelChange()
Definition: MaintenanceTest.php:377
MaintenanceTest\testOutputWChannelStringNLStringNLLinewise
testOutputWChannelStringNLStringNLLinewise()
Definition: MaintenanceTest.php:349
MaintenanceTest\testCleanupChanneledAfterOutputChanneledWOChannel
testCleanupChanneledAfterOutputChanneledWOChannel()
Definition: MaintenanceTest.php:688
MaintenanceFixup\simulateShutdown
simulateShutdown()
Simulates what Maintenance wants to happen at script's end.
Definition: MaintenanceTest.php:54
MaintenanceTest\assertOutputPrePostShutdown
assertOutputPrePostShutdown( $preShutdownOutput, $expectNLAppending)
asserts the output before and after simulating shutdown
Definition: MaintenanceTest.php:176
MaintenanceTest\testOutputStringNLNL
testOutputStringNLNL()
Definition: MaintenanceTest.php:213
MaintenanceTest\testOutputWNullChannelStringNLStringNL
testOutputWNullChannelStringNLStringNL()
Definition: MaintenanceTest.php:287
MaintenanceTest\testOutputStringNLStringNLArbitraryAgain
testOutputStringNLStringNLArbitraryAgain()
Definition: MaintenanceTest.php:245
MaintenanceTest\testOutputChanneledStringNLString
testOutputChanneledStringNLString()
Definition: MaintenanceTest.php:484
MaintenanceFixup\outputChanneled
outputChanneled( $msg, $channel=null)
Message outputter with channeled message support.
Definition: MaintenanceTest.php:67
MaintenanceTest\testMultipleMaintenanceObjectsInteractionOutputChanneledWChannel
testMultipleMaintenanceObjectsInteractionOutputChanneledWChannel()
Definition: MaintenanceTest.php:790
MaintenanceTest\testOutputWNullChannelStringNLStringNLArbitraryAgain
testOutputWNullChannelStringNLStringNLArbitraryAgain()
Definition: MaintenanceTest.php:309
MaintenanceFixup\$shutdownSimulated
bool $shutdownSimulated
shutdownSimulated === true if simulateShutdown has done it's work
Definition: MaintenanceTest.php:49
MaintenanceTest\testOutputString
testOutputString()
Definition: MaintenanceTest.php:197
MaintenanceTest\testOutputWNullChannelStringString
testOutputWNullChannelStringString()
Definition: MaintenanceTest.php:266
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
MaintenanceTest\testOutputStringNLStringNLLinewise
testOutputStringNLStringNLLinewise()
Definition: MaintenanceTest.php:228
MaintenanceTest\testCleanupChanneledAfterOutputWNullChannel
testCleanupChanneledAfterOutputWNullChannel()
Definition: MaintenanceTest.php:658
MaintenanceFixup\__construct
__construct(MediaWikiTestCase $testCase)
Definition: MaintenanceTest.php:107
MaintenanceTest\testOutputWChannelIntermittentEmpty
testOutputWChannelIntermittentEmpty()
Definition: MaintenanceTest.php:451
MaintenanceFixup\addOption
addOption( $name, $description, $required=false, $withArg=false, $shortName=false, $multiOccurance=false)
Add a parameter to the script.
Definition: MaintenanceTest.php:122
$name
Allows to change the fields on the form that will be generated $name
Definition: hooks.txt:302
Maintenance
Abstract maintenance class for quickly writing and churning out maintenance scripts with minimal effo...
Definition: maintenance.txt:39
MaintenanceTest\testOutputChanneledWNullChannelStringString
testOutputChanneledWNullChannelStringString()
Definition: MaintenanceTest.php:510
MaintenanceTest\testOutputChanneledStringNLStringNLArbitraryAgain
testOutputChanneledStringNLStringNLArbitraryAgain()
Definition: MaintenanceTest.php:489
MaintenanceTest\testMultipleMaintenanceObjectsInteractionOutputWNullChannel
testMultipleMaintenanceObjectsInteractionOutputWNullChannel()
Definition: MaintenanceTest.php:718
MaintenanceTest\testOutputWChannelIntermittentFalse
testOutputWChannelIntermittentFalse()
Definition: MaintenanceTest.php:458
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
MaintenanceTest\testOutputWChannelTypeSwitch
testOutputWChannelTypeSwitch()
Definition: MaintenanceTest.php:409
MaintenanceTest\testCleanupChanneledAfterNLOutputWChannel
testCleanupChanneledAfterNLOutputWChannel()
Definition: MaintenanceTest.php:682
MaintenanceTest\testMultipleMaintenanceObjectsInteractionOutputWChannel
testMultipleMaintenanceObjectsInteractionOutputWChannel()
Definition: MaintenanceTest.php:730
MaintenanceTest\testOutputStringNL
testOutputStringNL()
Definition: MaintenanceTest.php:208
MaintenanceTest\testOutputChanneledWChannelString
testOutputChanneledWChannelString()
Definition: MaintenanceTest.php:532
MaintenanceFixup\getOption
getOption( $name, $default=null)
Get an option, or return the default.
Definition: MaintenanceTest.php:128
MaintenanceTest\testOutputIntermittentFalse
testOutputIntermittentFalse()
Definition: MaintenanceTest.php:422
MaintenanceTest\testOutputStringNLStringNLArbitrary
testOutputStringNLStringNLArbitrary()
Definition: MaintenanceTest.php:234
MaintenanceTest\testOutputChanneledWChannelStringString
testOutputChanneledWChannelStringString()
Definition: MaintenanceTest.php:542
MaintenanceTest\testOutputWAndWOChannelStringStartWO
testOutputWAndWOChannelStringStartWO()
Definition: MaintenanceTest.php:393
MaintenanceTest\testOutputChanneledWAndWOChannelStringStartW
testOutputChanneledWAndWOChannelStringStartW()
Definition: MaintenanceTest.php:591
MaintenanceTest\testOutputWChannelStringNLStringNLArbitraryAgain
testOutputWChannelStringNLStringNLArbitraryAgain()
Definition: MaintenanceTest.php:366
MaintenanceTest\testMultipleMaintenanceObjectsInteractionOutputWNullChannelNL
testMultipleMaintenanceObjectsInteractionOutputWNullChannelNL()
Definition: MaintenanceTest.php:742
MaintenanceTest\tearDown
tearDown()
Definition: MaintenanceTest.php:156
MaintenanceTest\testCleanupChanneledAfterNLOutputWNullChannel
testCleanupChanneledAfterNLOutputWNullChannel()
Definition: MaintenanceTest.php:676
MaintenanceTest\testSetConfig
testSetConfig()
Maintenance::setConfig.
Definition: MaintenanceTest.php:835
MediaWikiTestCase
Definition: MediaWikiTestCase.php:15
MaintenanceTest\testOutputChanneledWMultipleChannelsChannelChange
testOutputChanneledWMultipleChannelsChannelChange()
Definition: MaintenanceTest.php:559
MaintenanceTest\testOutputWNullChannelStringNL
testOutputWNullChannelStringNL()
Definition: MaintenanceTest.php:272
MaintenanceTest\testOutputChanneledWNullChannelEmpty
testOutputChanneledWNullChannelEmpty()
Definition: MaintenanceTest.php:500
MaintenanceTest\testOutputStringString
testOutputStringString()
Definition: MaintenanceTest.php:202
MaintenanceTest\testOutputChanneledWNullChannelIntermittentEmpty
testOutputChanneledWNullChannelIntermittentEmpty()
Definition: MaintenanceTest.php:619
MaintenanceTest\testOutputChanneledWMultipleChannelsChannelChangeEnclosedNull
testOutputChanneledWMultipleChannelsChannelChangeEnclosedNull()
Definition: MaintenanceTest.php:567
MaintenanceTest\testOutputChanneledWOChannelIntermittentEmpty
testOutputChanneledWOChannelIntermittentEmpty()
Definition: MaintenanceTest.php:605
MaintenanceTest\testOutputChanneledWChannelStringNLString
testOutputChanneledWChannelStringNLString()
Definition: MaintenanceTest.php:537
MaintenanceTest\testParseArgs
testParseArgs()
Definition: MaintenanceTest.php:841
MaintenanceTest\testOutputChanneledWOChannelIntermittentFalse
testOutputChanneledWOChannelIntermittentFalse()
Definition: MaintenanceTest.php:612
MaintenanceTest\testOutputChanneledWNullChannelStringNLString
testOutputChanneledWNullChannelStringNLString()
Definition: MaintenanceTest.php:516
MaintenanceTest
Maintenance.
Definition: MaintenanceTest.php:142
MaintenanceTest\testOutputChanneledWNullChannelIntermittentFalse
testOutputChanneledWNullChannelIntermittentFalse()
Definition: MaintenanceTest.php:626
MaintenanceTest\testMultipleMaintenanceObjectsInteractionOutputWChannelNL
testMultipleMaintenanceObjectsInteractionOutputWChannelNL()
Definition: MaintenanceTest.php:754
MaintenanceTest\testOutputStringNLString
testOutputStringNLString()
Definition: MaintenanceTest.php:218
MaintenanceTest\testOutputWMultipleChannelsChannelChangeNL
testOutputWMultipleChannelsChannelChangeNL()
Definition: MaintenanceTest.php:385
MaintenanceTest\testOutputChanneledWChannelIntermittentEmpty
testOutputChanneledWChannelIntermittentEmpty()
Definition: MaintenanceTest.php:633
MaintenanceTest\testOutputWChannelStringNLStringNL
testOutputWChannelStringNLStringNL()
Definition: MaintenanceTest.php:344
MaintenanceTest\testOutputWNullChannelIntermittentFalse
testOutputWNullChannelIntermittentFalse()
Definition: MaintenanceTest.php:444
MaintenanceFixup\__destruct
__destruct()
Safety net around register_shutdown_function of Maintenance.php.
Definition: MaintenanceTest.php:88
MaintenanceTest\testOutputWNullChannelStringNLStringNLLinewise
testOutputWNullChannelStringNLStringNLLinewise()
Definition: MaintenanceTest.php:292
MaintenanceTest\testOutputWNullChannelStringNLNL
testOutputWNullChannelStringNLNL()
Definition: MaintenanceTest.php:277
MaintenanceTest\testOutputChanneledString
testOutputChanneledString()
Definition: MaintenanceTest.php:473
MaintenanceTest\testOutputWAndWOChannelStringStartW
testOutputWAndWOChannelStringStartW()
Definition: MaintenanceTest.php:401
MaintenanceTest\testOutputStringNLStringNL
testOutputStringNLStringNL()
Definition: MaintenanceTest.php:223
MaintenanceTest\testOutputWNullChannelStringNLStringNLArbitrary
testOutputWNullChannelStringNLStringNLArbitrary()
Definition: MaintenanceTest.php:298
MaintenanceTest\testMultipleMaintenanceObjectsInteractionOutput
testMultipleMaintenanceObjectsInteractionOutput()
Definition: MaintenanceTest.php:706
MaintenanceTest\testOutputChanneledEmpty
testOutputChanneledEmpty()
Definition: MaintenanceTest.php:468
MaintenanceTest\testMultipleMaintenanceObjectsInteractionOutputChanneledWNullChannel
testMultipleMaintenanceObjectsInteractionOutputChanneledWNullChannel()
Definition: MaintenanceTest.php:778
MaintenanceTest\testOutputIntermittentFalseAfterOtherChannel
testOutputIntermittentFalseAfterOtherChannel()
Definition: MaintenanceTest.php:429
MaintenanceTest\testOutputWNullChannelIntermittentEmpty
testOutputWNullChannelIntermittentEmpty()
Definition: MaintenanceTest.php:437
MaintenanceTest\testCleanupChanneledAfterOutputChanneledWChannel
testCleanupChanneledAfterOutputChanneledWChannel()
Definition: MaintenanceTest.php:700
MaintenanceTest\testOutputChanneledWNullChannelString
testOutputChanneledWNullChannelString()
Definition: MaintenanceTest.php:505
MaintenanceTest\testCleanupChanneledAfterOutputChanneledWNullChannel
testCleanupChanneledAfterOutputChanneledWNullChannel()
Definition: MaintenanceTest.php:694
MaintenanceTest\testCleanupChanneledAfterOutput
testCleanupChanneledAfterOutput()
Definition: MaintenanceTest.php:652
MaintenanceTest\testOutputWChannelString
testOutputWChannelString()
Definition: MaintenanceTest.php:320
MaintenanceTest\testOutputEmpty
testOutputEmpty()
Definition: MaintenanceTest.php:192
MaintenanceTest\$m
MaintenanceFixup $m
The main Maintenance instance that is used for testing.
Definition: MaintenanceTest.php:149
MaintenanceTest\testOutputIntermittentEmpty
testOutputIntermittentEmpty()
Definition: MaintenanceTest.php:415
MediaWikiServices
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 MediaWikiServices
Definition: injection.txt:23
MaintenanceTest\testCleanupChanneledAfterOutputWChannel
testCleanupChanneledAfterOutputWChannel()
Definition: MaintenanceTest.php:664
MaintenanceTest\testOutputChanneledStringString
testOutputChanneledStringString()
Definition: MaintenanceTest.php:478
MaintenanceTest\testOutputWChannelStringNLString
testOutputWChannelStringNLString()
Definition: MaintenanceTest.php:339
MaintenanceTest\testOutputWChannelStringNLStringNLArbitrary
testOutputWChannelStringNLStringNLArbitrary()
Definition: MaintenanceTest.php:355
MaintenanceFixup\execute
execute()
Do the actual work.
Definition: MaintenanceTest.php:134
MaintenanceTest\testOutputChanneledWChannelIntermittentFalse
testOutputChanneledWChannelIntermittentFalse()
Definition: MaintenanceTest.php:640
MaintenanceFixup\$testCase
MediaWikiTestCase $testCase
The test case that generated this instance.
Definition: MaintenanceTest.php:42
MaintenanceTest\testCleanupChanneledClean
testCleanupChanneledClean()
Definition: MaintenanceTest.php:647
MaintenanceTest\testOutputChanneledWChannelTypeSwitch
testOutputChanneledWChannelTypeSwitch()
Definition: MaintenanceTest.php:599
MaintenanceTest\testOutputChanneledWNullChannelStringNLStringNLArbitraryAgain
testOutputChanneledWNullChannelStringNLStringNLArbitraryAgain()
Definition: MaintenanceTest.php:521
MaintenanceTest\testOutputChanneledWChannelStringNLStringNLArbitraryAgain
testOutputChanneledWChannelStringNLStringNLArbitraryAgain()
Definition: MaintenanceTest.php:548
MaintenanceTest\testGetConfig
testGetConfig()
Maintenance::getConfig.
Definition: MaintenanceTest.php:824
$out
this hook is for auditing only or null if authentication failed before getting that far or null if we can t even determine that probably a stub it is not rendered in wiki pages or galleries in category pages allow injecting custom HTML after the section Any uses of the hook need to handle escaping see BaseTemplate::getToolbox and BaseTemplate::makeListItem for details on the format of individual items inside of this array or by returning and letting standard HTTP rendering take place modifiable or by returning false and taking over the output $out
Definition: hooks.txt:781
MaintenanceTest\testOutputChanneledWMultipleChannelsChannelAfterNullChange
testOutputChanneledWMultipleChannelsChannelAfterNullChange()
Definition: MaintenanceTest.php:575