55 if ( $this->shutdownSimulated ) {
56 $this->testCase->fail( __METHOD__ .
" called more than once" );
63 $this->shutdownSimulated =
true;
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" );
82 call_user_func_array( [
"parent", __FUNCTION__ ], func_get_args() );
89 if ( !$this->shutdownSimulated ) {
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." );
102 if ( is_callable(
"parent::__destruct" ) ) {
103 parent::__destruct();
108 parent::__construct();
119 return call_user_func_array( [
"parent", __FUNCTION__ ], func_get_args() );
123 $withArg =
false, $shortName =
false, $multiOccurance =
false
125 return call_user_func_array( [
"parent", __FUNCTION__ ], func_get_args() );
129 return call_user_func_array( [
"parent", __FUNCTION__ ], func_get_args() );
135 $this->testCase->fail( __METHOD__ .
" called unexpectedly" );
158 $this->m->simulateShutdown();
177 $this->assertEquals( $preShutdownOutput, $this->getActualOutput(),
178 "Output before shutdown simulation" );
180 $this->m->simulateShutdown();
183 $postShutdownOutput = $preShutdownOutput . ( $expectNLAppending ?
"\n" :
"" );
184 $this->expectOutputString( $postShutdownOutput );
193 $this->m->output(
"" );
198 $this->m->output(
"foo" );
203 $this->m->output(
"foo" );
204 $this->m->output(
"bar" );
209 $this->m->output(
"foo\n" );
214 $this->m->output(
"foo\n\n" );
219 $this->m->output(
"foo\nbar" );
224 $this->m->output(
"foo\nbar\n" );
229 $this->m->output(
"foo\n" );
230 $this->m->output(
"bar\n" );
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" );
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" );
257 $this->m->output(
"",
null );
262 $this->m->output(
"foo",
null );
267 $this->m->output(
"foo",
null );
268 $this->m->output(
"bar",
null );
273 $this->m->output(
"foo\n",
null );
278 $this->m->output(
"foo\n\n",
null );
283 $this->m->output(
"foo\nbar",
null );
288 $this->m->output(
"foo\nbar\n",
null );
293 $this->m->output(
"foo\n",
null );
294 $this->m->output(
"bar\n",
null );
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 );
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 );
321 $this->m->output(
"foo",
"bazChannel" );
326 $this->m->output(
"foo\n",
"bazChannel" );
335 $this->m->output(
"foo\n\n",
"bazChannel" );
340 $this->m->output(
"foo\nbar",
"bazChannel" );
345 $this->m->output(
"foo\nbar\n",
"bazChannel" );
350 $this->m->output(
"foo\n",
"bazChannel" );
351 $this->m->output(
"bar\n",
"bazChannel" );
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" );
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" );
378 $this->m->output(
"foo",
"bazChannel" );
379 $this->m->output(
"bar",
"bazChannel" );
380 $this->m->output(
"qux",
"quuxChannel" );
381 $this->m->output(
"corge",
"bazChannel" );
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" );
394 $this->m->output(
"foo" );
395 $this->m->output(
"bar",
"bazChannel" );
396 $this->m->output(
"qux" );
397 $this->m->output(
"quux",
"bazChannel" );
402 $this->m->output(
"foo",
"bazChannel" );
403 $this->m->output(
"bar" );
404 $this->m->output(
"qux",
"bazChannel" );
405 $this->m->output(
"quux" );
410 $this->m->output(
"foo", 1 );
411 $this->m->output(
"bar", 1.0 );
416 $this->m->output(
"foo" );
417 $this->m->output(
"" );
418 $this->m->output(
"bar" );
423 $this->m->output(
"foo" );
424 $this->m->output(
false );
425 $this->m->output(
"bar" );
430 $this->m->output(
"qux",
"quuxChannel" );
431 $this->m->output(
"foo" );
432 $this->m->output(
false );
433 $this->m->output(
"bar" );
438 $this->m->output(
"foo",
null );
439 $this->m->output(
"",
null );
440 $this->m->output(
"bar",
null );
445 $this->m->output(
"foo",
null );
446 $this->m->output(
false,
null );
447 $this->m->output(
"bar",
null );
452 $this->m->output(
"foo",
"bazChannel" );
453 $this->m->output(
"",
"bazChannel" );
454 $this->m->output(
"bar",
"bazChannel" );
459 $this->m->output(
"foo",
"bazChannel" );
460 $this->m->output(
false,
"bazChannel" );
461 $this->m->output(
"bar",
"bazChannel" );
469 $this->m->outputChanneled(
"" );
474 $this->m->outputChanneled(
"foo" );
479 $this->m->outputChanneled(
"foo" );
480 $this->m->outputChanneled(
"bar" );
485 $this->m->outputChanneled(
"foo\nbar" );
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" );
501 $this->m->outputChanneled(
"",
null );
506 $this->m->outputChanneled(
"foo",
null );
511 $this->m->outputChanneled(
"foo",
null );
512 $this->m->outputChanneled(
"bar",
null );
517 $this->m->outputChanneled(
"foo\nbar",
null );
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 );
533 $this->m->outputChanneled(
"foo",
"bazChannel" );
538 $this->m->outputChanneled(
"foo\nbar",
"bazChannel" );
543 $this->m->outputChanneled(
"foo",
"bazChannel" );
544 $this->m->outputChanneled(
"bar",
"bazChannel" );
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" );
560 $this->m->outputChanneled(
"foo",
"bazChannel" );
561 $this->m->outputChanneled(
"bar",
"bazChannel" );
562 $this->m->outputChanneled(
"qux",
"quuxChannel" );
563 $this->m->outputChanneled(
"corge",
"bazChannel" );
568 $this->m->outputChanneled(
"foo",
"bazChannel" );
569 $this->m->outputChanneled(
"bar",
null );
570 $this->m->outputChanneled(
"qux",
null );
571 $this->m->outputChanneled(
"corge",
"bazChannel" );
576 $this->m->outputChanneled(
"foo",
"bazChannel" );
577 $this->m->outputChanneled(
"bar",
null );
578 $this->m->outputChanneled(
"qux",
null );
579 $this->m->outputChanneled(
"corge",
"quuxChannel" );
584 $this->m->outputChanneled(
"foo" );
585 $this->m->outputChanneled(
"bar",
"bazChannel" );
586 $this->m->outputChanneled(
"qux" );
587 $this->m->outputChanneled(
"quux",
"bazChannel" );
592 $this->m->outputChanneled(
"foo",
"bazChannel" );
593 $this->m->outputChanneled(
"bar" );
594 $this->m->outputChanneled(
"qux",
"bazChannel" );
595 $this->m->outputChanneled(
"quux" );
600 $this->m->outputChanneled(
"foo", 1 );
601 $this->m->outputChanneled(
"bar", 1.0 );
606 $this->m->outputChanneled(
"foo" );
607 $this->m->outputChanneled(
"" );
608 $this->m->outputChanneled(
"bar" );
613 $this->m->outputChanneled(
"foo" );
614 $this->m->outputChanneled(
false );
615 $this->m->outputChanneled(
"bar" );
620 $this->m->outputChanneled(
"foo",
null );
621 $this->m->outputChanneled(
"",
null );
622 $this->m->outputChanneled(
"bar",
null );
627 $this->m->outputChanneled(
"foo",
null );
628 $this->m->outputChanneled(
false,
null );
629 $this->m->outputChanneled(
"bar",
null );
634 $this->m->outputChanneled(
"foo",
"bazChannel" );
635 $this->m->outputChanneled(
"",
"bazChannel" );
636 $this->m->outputChanneled(
"bar",
"bazChannel" );
641 $this->m->outputChanneled(
"foo",
"bazChannel" );
642 $this->m->outputChanneled(
false,
"bazChannel" );
643 $this->m->outputChanneled(
"bar",
"bazChannel" );
648 $this->m->cleanupChanneled();
653 $this->m->output(
"foo" );
654 $this->m->cleanupChanneled();
659 $this->m->output(
"foo",
null );
660 $this->m->cleanupChanneled();
665 $this->m->output(
"foo",
"bazChannel" );
666 $this->m->cleanupChanneled();
671 $this->m->output(
"foo\n" );
672 $this->m->cleanupChanneled();
677 $this->m->output(
"foo\n",
null );
678 $this->m->cleanupChanneled();
683 $this->m->output(
"foo\n",
"bazChannel" );
684 $this->m->cleanupChanneled();
689 $this->m->outputChanneled(
"foo" );
690 $this->m->cleanupChanneled();
695 $this->m->outputChanneled(
"foo",
null );
696 $this->m->cleanupChanneled();
701 $this->m->outputChanneled(
"foo",
"bazChannel" );
702 $this->m->cleanupChanneled();
709 $this->m->output(
"foo" );
710 $m2->output(
"bar" );
712 $this->assertEquals(
"foobar", $this->getActualOutput(),
713 "Output before shutdown simulation (m2)" );
714 $m2->simulateShutdown();
721 $this->m->output(
"foo",
null );
722 $m2->output(
"bar",
null );
724 $this->assertEquals(
"foobar", $this->getActualOutput(),
725 "Output before shutdown simulation (m2)" );
726 $m2->simulateShutdown();
733 $this->m->output(
"foo",
"bazChannel" );
734 $m2->output(
"bar",
"bazChannel" );
736 $this->assertEquals(
"foobar", $this->getActualOutput(),
737 "Output before shutdown simulation (m2)" );
738 $m2->simulateShutdown();
745 $this->m->output(
"foo\n",
null );
746 $m2->output(
"bar\n",
null );
748 $this->assertEquals(
"foo\nbar\n", $this->getActualOutput(),
749 "Output before shutdown simulation (m2)" );
750 $m2->simulateShutdown();
757 $this->m->output(
"foo\n",
"bazChannel" );
758 $m2->output(
"bar\n",
"bazChannel" );
760 $this->assertEquals(
"foobar", $this->getActualOutput(),
761 "Output before shutdown simulation (m2)" );
762 $m2->simulateShutdown();
769 $this->m->outputChanneled(
"foo" );
770 $m2->outputChanneled(
"bar" );
772 $this->assertEquals(
"foo\nbar\n", $this->getActualOutput(),
773 "Output before shutdown simulation (m2)" );
774 $m2->simulateShutdown();
781 $this->m->outputChanneled(
"foo",
null );
782 $m2->outputChanneled(
"bar",
null );
784 $this->assertEquals(
"foo\nbar\n", $this->getActualOutput(),
785 "Output before shutdown simulation (m2)" );
786 $m2->simulateShutdown();
793 $this->m->outputChanneled(
"foo",
"bazChannel" );
794 $m2->outputChanneled(
"bar",
"bazChannel" );
796 $this->assertEquals(
"foobar", $this->getActualOutput(),
797 "Output before shutdown simulation (m2)" );
798 $m2->simulateShutdown();
805 $this->m->outputChanneled(
"foo",
"bazChannel" );
806 $m2->outputChanneled(
"bar",
"bazChannel" );
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" );
817 $m2->simulateShutdown();
825 $this->assertInstanceOf(
'Config', $this->m->getConfig() );
827 MediaWikiServices::getInstance()->getMainConfig(),
828 $this->m->getConfig()
836 $conf = $this->createMock(
'Config' );
837 $this->m->setConfig( $conf );
838 $this->assertSame( $conf, $this->m->getConfig() );
844 $m2->addOption(
'multi',
'This option does stuff',
false,
true,
false,
true );
845 $m2->loadWithArgv( [
'--multi',
'this1',
'--multi',
'this2' ] );
847 $this->assertEquals( [
'this1',
'this2' ], $m2->getOption(
'multi' ) );
848 $this->assertEquals( [ [
'multi',
'this1' ], [
'multi',
'this2' ] ],
849 $m2->orderedOptions );
851 $m2->simulateShutdown();
855 $m2->addOption(
'multi',
'This option does stuff',
false,
false,
false,
true );
856 $m2->loadWithArgv( [
'--multi',
'--multi' ] );
858 $this->assertEquals( [ 1, 1 ], $m2->getOption(
'multi' ) );
859 $this->assertEquals( [ [
'multi', 1 ], [
'multi', 1 ] ], $m2->orderedOptions );
861 $m2->simulateShutdown();
865 $m2->addOption(
'multi',
'This option doesn\'t actually support multiple occurrences' );
866 $m2->loadWithArgv( [
'--multi=yo' ] );
868 $this->assertEquals(
'yo', $m2->getOption(
'multi' ) );
869 $this->assertEquals( [ [
'multi',
'yo' ] ], $m2->orderedOptions );
871 $m2->simulateShutdown();