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
7 // For the same reason, we cannot just use FakeMaintenance.
8 use MediaWiki\MediaWikiServices
;
11 * makes parts of the API of Maintenance that is hidden by protected visibily
12 * visible for testing, and makes up for a stream closing hack in Maintenance.php.
14 * This class is solely used for being able to test Maintenance right now
15 * without having to apply major refactorings to fix some design issues in
16 * Maintenance.php. Before adding more functions here, please consider whether
17 * this approach is correct, or a refactoring Maintenance to separate concers
18 * is more appropriate.
20 * Upon refactoring, keep in mind that besides the maintenance scrits themselves
21 * and tests right here, also at least Extension:Maintenance make use of
24 * Due to a hack in Maintenance.php using register_shutdown_function, be sure to
25 * finally call simulateShutdown on MaintenanceFixup instance before a test
29 class MaintenanceFixup
extends Maintenance
{
31 // --- Making up for the register_shutdown_function hack in Maintenance.php
34 * The test case that generated this instance.
36 * This member is motivated by allowing the destructor to check whether or not
37 * the test failed, in order to avoid unnecessary nags about omitted shutdown
39 * But as it is already available, we also usi it to flagging tests as failed
41 * @var MediaWikiTestCase
46 * shutdownSimulated === true if simulateShutdown has done it's work
50 private $shutdownSimulated = false;
53 * Simulates what Maintenance wants to happen at script's end.
55 public function simulateShutdown() {
57 if ( $this->shutdownSimulated
) {
58 $this->testCase
->fail( __METHOD__
. " called more than once" );
61 // The cleanup action.
62 $this->outputChanneled( false );
64 // Bookkeeping that we simulated the clean up.
65 $this->shutdownSimulated
= true;
68 // Note that the "public" here does not change visibility
69 public function outputChanneled( $msg, $channel = null ) {
70 if ( $this->shutdownSimulated
) {
71 if ( $msg !== false ) {
72 $this->testCase
->fail( "Already past simulated shutdown, but msg is "
73 . "not false. Did the hack in Maintenance.php change? Please "
74 . "adapt the test case or Maintenance.php" );
77 // The current call is the one registered via register_shutdown_function.
78 // We can safely ignore it, as we simulated this one via simulateShutdown
79 // before (if we did not, the destructor of this instance will warn about
84 call_user_func_array( [ "parent", __FUNCTION__
], func_get_args() );
88 * Safety net around register_shutdown_function of Maintenance.php
90 public function __destruct() {
91 if ( !$this->shutdownSimulated
) {
92 // Someone generated a MaintenanceFixup instance without calling
93 // simulateShutdown. We'd have to raise a PHPUnit exception to correctly
94 // flag this illegal usage. However, we are already in a destruktor, which
95 // would trigger undefined behavior. Hence, we can only report to the
96 // error output :( Hopefully people read the PHPUnit output.
97 $name = $this->testCase
->getName();
98 fwrite( STDERR
, "ERROR! Instance of " . __CLASS__
. " for test $name "
99 . "destructed without calling simulateShutdown method. Call "
100 . "simulateShutdown on the instance before it gets destructed." );
103 // The following guard is required, as PHP does not offer default destructors :(
104 if ( is_callable( "parent::__destruct" ) ) {
105 parent
::__destruct();
109 public function __construct( MediaWikiTestCase
$testCase ) {
110 parent
::__construct();
111 $this->testCase
= $testCase;
114 // --- Making protected functions visible for test
116 public function output( $out, $channel = null ) {
117 // Just to make PHP not nag about signature mismatches, we copied
118 // Maintenance::output signature. However, we do not use (or rely on)
119 // those variables. Instead we pass to Maintenance::output whatever we
120 // receive at runtime.
121 return call_user_func_array( [ "parent", __FUNCTION__
], func_get_args() );
124 public function addOption( $name, $description, $required = false,
125 $withArg = false, $shortName = false, $multiOccurance = false
127 return call_user_func_array( [ "parent", __FUNCTION__
], func_get_args() );
130 public function getOption( $name, $default = null ) {
131 return call_user_func_array( [ "parent", __FUNCTION__
], func_get_args() );
134 // --- Requirements for getting instance of abstract class
136 public function execute() {
137 $this->testCase
->fail( __METHOD__
. " called unexpectedly" );
142 * @covers Maintenance
144 class MaintenanceTest
extends MediaWikiTestCase
{
147 * The main Maintenance instance that is used for testing.
149 * @var MaintenanceFixup
153 protected function setUp() {
155 $this->m
= new MaintenanceFixup( $this );
158 protected function tearDown() {
160 $this->m
->simulateShutdown();
167 * asserts the output before and after simulating shutdown
169 * This function simulates shutdown of self::m.
171 * @param string $preShutdownOutput Expected output before simulating shutdown
172 * @param bool $expectNLAppending Whether or not shutdown simulation is expected
173 * to add a newline to the output. If false, $preShutdownOutput is the
174 * expected output after shutdown simulation. Otherwise,
175 * $preShutdownOutput with an appended newline is the expected output
176 * after shutdown simulation.
178 private function assertOutputPrePostShutdown( $preShutdownOutput, $expectNLAppending ) {
180 $this->assertEquals( $preShutdownOutput, $this->getActualOutput(),
181 "Output before shutdown simulation" );
183 $this->m
->simulateShutdown();
186 $postShutdownOutput = $preShutdownOutput . ( $expectNLAppending ?
"\n" : "" );
187 $this->expectOutputString( $postShutdownOutput );
190 // Although the following tests do not seem to be too consistent (compare for
191 // example the newlines within the test.*StringString tests, or the
192 // test.*Intermittent.* tests), the objective of these tests is not to describe
193 // consistent behavior, but rather currently existing behavior.
195 function testOutputEmpty() {
196 $this->m
->output( "" );
197 $this->assertOutputPrePostShutdown( "", false );
200 function testOutputString() {
201 $this->m
->output( "foo" );
202 $this->assertOutputPrePostShutdown( "foo", false );
205 function testOutputStringString() {
206 $this->m
->output( "foo" );
207 $this->m
->output( "bar" );
208 $this->assertOutputPrePostShutdown( "foobar", false );
211 function testOutputStringNL() {
212 $this->m
->output( "foo\n" );
213 $this->assertOutputPrePostShutdown( "foo\n", false );
216 function testOutputStringNLNL() {
217 $this->m
->output( "foo\n\n" );
218 $this->assertOutputPrePostShutdown( "foo\n\n", false );
221 function testOutputStringNLString() {
222 $this->m
->output( "foo\nbar" );
223 $this->assertOutputPrePostShutdown( "foo\nbar", false );
226 function testOutputStringNLStringNL() {
227 $this->m
->output( "foo\nbar\n" );
228 $this->assertOutputPrePostShutdown( "foo\nbar\n", false );
231 function testOutputStringNLStringNLLinewise() {
232 $this->m
->output( "foo\n" );
233 $this->m
->output( "bar\n" );
234 $this->assertOutputPrePostShutdown( "foo\nbar\n", false );
237 function testOutputStringNLStringNLArbitrary() {
238 $this->m
->output( "" );
239 $this->m
->output( "foo" );
240 $this->m
->output( "" );
241 $this->m
->output( "\n" );
242 $this->m
->output( "ba" );
243 $this->m
->output( "" );
244 $this->m
->output( "r\n" );
245 $this->assertOutputPrePostShutdown( "foo\nbar\n", false );
248 function testOutputStringNLStringNLArbitraryAgain() {
249 $this->m
->output( "" );
250 $this->m
->output( "foo" );
251 $this->m
->output( "" );
252 $this->m
->output( "\nb" );
253 $this->m
->output( "a" );
254 $this->m
->output( "" );
255 $this->m
->output( "r\n" );
256 $this->assertOutputPrePostShutdown( "foo\nbar\n", false );
259 function testOutputWNullChannelEmpty() {
260 $this->m
->output( "", null );
261 $this->assertOutputPrePostShutdown( "", false );
264 function testOutputWNullChannelString() {
265 $this->m
->output( "foo", null );
266 $this->assertOutputPrePostShutdown( "foo", false );
269 function testOutputWNullChannelStringString() {
270 $this->m
->output( "foo", null );
271 $this->m
->output( "bar", null );
272 $this->assertOutputPrePostShutdown( "foobar", false );
275 function testOutputWNullChannelStringNL() {
276 $this->m
->output( "foo\n", null );
277 $this->assertOutputPrePostShutdown( "foo\n", false );
280 function testOutputWNullChannelStringNLNL() {
281 $this->m
->output( "foo\n\n", null );
282 $this->assertOutputPrePostShutdown( "foo\n\n", false );
285 function testOutputWNullChannelStringNLString() {
286 $this->m
->output( "foo\nbar", null );
287 $this->assertOutputPrePostShutdown( "foo\nbar", false );
290 function testOutputWNullChannelStringNLStringNL() {
291 $this->m
->output( "foo\nbar\n", null );
292 $this->assertOutputPrePostShutdown( "foo\nbar\n", false );
295 function testOutputWNullChannelStringNLStringNLLinewise() {
296 $this->m
->output( "foo\n", null );
297 $this->m
->output( "bar\n", null );
298 $this->assertOutputPrePostShutdown( "foo\nbar\n", false );
301 function testOutputWNullChannelStringNLStringNLArbitrary() {
302 $this->m
->output( "", null );
303 $this->m
->output( "foo", null );
304 $this->m
->output( "", null );
305 $this->m
->output( "\n", null );
306 $this->m
->output( "ba", null );
307 $this->m
->output( "", null );
308 $this->m
->output( "r\n", null );
309 $this->assertOutputPrePostShutdown( "foo\nbar\n", false );
312 function testOutputWNullChannelStringNLStringNLArbitraryAgain() {
313 $this->m
->output( "", null );
314 $this->m
->output( "foo", null );
315 $this->m
->output( "", null );
316 $this->m
->output( "\nb", null );
317 $this->m
->output( "a", null );
318 $this->m
->output( "", null );
319 $this->m
->output( "r\n", null );
320 $this->assertOutputPrePostShutdown( "foo\nbar\n", false );
323 function testOutputWChannelString() {
324 $this->m
->output( "foo", "bazChannel" );
325 $this->assertOutputPrePostShutdown( "foo", true );
328 function testOutputWChannelStringNL() {
329 $this->m
->output( "foo\n", "bazChannel" );
330 $this->assertOutputPrePostShutdown( "foo", true );
333 function testOutputWChannelStringNLNL() {
334 // If this test fails, note that output takes strings with double line
335 // endings (although output's implementation in this situation calls
336 // outputChanneled with a string ending in a nl ... which is not allowed
337 // according to the documentation of outputChanneled)
338 $this->m
->output( "foo\n\n", "bazChannel" );
339 $this->assertOutputPrePostShutdown( "foo\n", true );
342 function testOutputWChannelStringNLString() {
343 $this->m
->output( "foo\nbar", "bazChannel" );
344 $this->assertOutputPrePostShutdown( "foo\nbar", true );
347 function testOutputWChannelStringNLStringNL() {
348 $this->m
->output( "foo\nbar\n", "bazChannel" );
349 $this->assertOutputPrePostShutdown( "foo\nbar", true );
352 function testOutputWChannelStringNLStringNLLinewise() {
353 $this->m
->output( "foo\n", "bazChannel" );
354 $this->m
->output( "bar\n", "bazChannel" );
355 $this->assertOutputPrePostShutdown( "foobar", true );
358 function testOutputWChannelStringNLStringNLArbitrary() {
359 $this->m
->output( "", "bazChannel" );
360 $this->m
->output( "foo", "bazChannel" );
361 $this->m
->output( "", "bazChannel" );
362 $this->m
->output( "\n", "bazChannel" );
363 $this->m
->output( "ba", "bazChannel" );
364 $this->m
->output( "", "bazChannel" );
365 $this->m
->output( "r\n", "bazChannel" );
366 $this->assertOutputPrePostShutdown( "foobar", true );
369 function testOutputWChannelStringNLStringNLArbitraryAgain() {
370 $this->m
->output( "", "bazChannel" );
371 $this->m
->output( "foo", "bazChannel" );
372 $this->m
->output( "", "bazChannel" );
373 $this->m
->output( "\nb", "bazChannel" );
374 $this->m
->output( "a", "bazChannel" );
375 $this->m
->output( "", "bazChannel" );
376 $this->m
->output( "r\n", "bazChannel" );
377 $this->assertOutputPrePostShutdown( "foo\nbar", true );
380 function testOutputWMultipleChannelsChannelChange() {
381 $this->m
->output( "foo", "bazChannel" );
382 $this->m
->output( "bar", "bazChannel" );
383 $this->m
->output( "qux", "quuxChannel" );
384 $this->m
->output( "corge", "bazChannel" );
385 $this->assertOutputPrePostShutdown( "foobar\nqux\ncorge", true );
388 function testOutputWMultipleChannelsChannelChangeNL() {
389 $this->m
->output( "foo", "bazChannel" );
390 $this->m
->output( "bar\n", "bazChannel" );
391 $this->m
->output( "qux\n", "quuxChannel" );
392 $this->m
->output( "corge", "bazChannel" );
393 $this->assertOutputPrePostShutdown( "foobar\nqux\ncorge", true );
396 function testOutputWAndWOChannelStringStartWO() {
397 $this->m
->output( "foo" );
398 $this->m
->output( "bar", "bazChannel" );
399 $this->m
->output( "qux" );
400 $this->m
->output( "quux", "bazChannel" );
401 $this->assertOutputPrePostShutdown( "foobar\nquxquux", true );
404 function testOutputWAndWOChannelStringStartW() {
405 $this->m
->output( "foo", "bazChannel" );
406 $this->m
->output( "bar" );
407 $this->m
->output( "qux", "bazChannel" );
408 $this->m
->output( "quux" );
409 $this->assertOutputPrePostShutdown( "foo\nbarqux\nquux", false );
412 function testOutputWChannelTypeSwitch() {
413 $this->m
->output( "foo", 1 );
414 $this->m
->output( "bar", 1.0 );
415 $this->assertOutputPrePostShutdown( "foo\nbar", true );
418 function testOutputIntermittentEmpty() {
419 $this->m
->output( "foo" );
420 $this->m
->output( "" );
421 $this->m
->output( "bar" );
422 $this->assertOutputPrePostShutdown( "foobar", false );
425 function testOutputIntermittentFalse() {
426 $this->m
->output( "foo" );
427 $this->m
->output( false );
428 $this->m
->output( "bar" );
429 $this->assertOutputPrePostShutdown( "foobar", false );
432 function testOutputIntermittentFalseAfterOtherChannel() {
433 $this->m
->output( "qux", "quuxChannel" );
434 $this->m
->output( "foo" );
435 $this->m
->output( false );
436 $this->m
->output( "bar" );
437 $this->assertOutputPrePostShutdown( "qux\nfoobar", false );
440 function testOutputWNullChannelIntermittentEmpty() {
441 $this->m
->output( "foo", null );
442 $this->m
->output( "", null );
443 $this->m
->output( "bar", null );
444 $this->assertOutputPrePostShutdown( "foobar", false );
447 function testOutputWNullChannelIntermittentFalse() {
448 $this->m
->output( "foo", null );
449 $this->m
->output( false, null );
450 $this->m
->output( "bar", null );
451 $this->assertOutputPrePostShutdown( "foobar", false );
454 function testOutputWChannelIntermittentEmpty() {
455 $this->m
->output( "foo", "bazChannel" );
456 $this->m
->output( "", "bazChannel" );
457 $this->m
->output( "bar", "bazChannel" );
458 $this->assertOutputPrePostShutdown( "foobar", true );
461 function testOutputWChannelIntermittentFalse() {
462 $this->m
->output( "foo", "bazChannel" );
463 $this->m
->output( false, "bazChannel" );
464 $this->m
->output( "bar", "bazChannel" );
465 $this->assertOutputPrePostShutdown( "foobar", true );
468 // Note that (per documentation) outputChanneled does take strings that end
469 // in \n, hence we do not test such strings.
471 function testOutputChanneledEmpty() {
472 $this->m
->outputChanneled( "" );
473 $this->assertOutputPrePostShutdown( "\n", false );
476 function testOutputChanneledString() {
477 $this->m
->outputChanneled( "foo" );
478 $this->assertOutputPrePostShutdown( "foo\n", false );
481 function testOutputChanneledStringString() {
482 $this->m
->outputChanneled( "foo" );
483 $this->m
->outputChanneled( "bar" );
484 $this->assertOutputPrePostShutdown( "foo\nbar\n", false );
487 function testOutputChanneledStringNLString() {
488 $this->m
->outputChanneled( "foo\nbar" );
489 $this->assertOutputPrePostShutdown( "foo\nbar\n", false );
492 function testOutputChanneledStringNLStringNLArbitraryAgain() {
493 $this->m
->outputChanneled( "" );
494 $this->m
->outputChanneled( "foo" );
495 $this->m
->outputChanneled( "" );
496 $this->m
->outputChanneled( "\nb" );
497 $this->m
->outputChanneled( "a" );
498 $this->m
->outputChanneled( "" );
499 $this->m
->outputChanneled( "r" );
500 $this->assertOutputPrePostShutdown( "\nfoo\n\n\nb\na\n\nr\n", false );
503 function testOutputChanneledWNullChannelEmpty() {
504 $this->m
->outputChanneled( "", null );
505 $this->assertOutputPrePostShutdown( "\n", false );
508 function testOutputChanneledWNullChannelString() {
509 $this->m
->outputChanneled( "foo", null );
510 $this->assertOutputPrePostShutdown( "foo\n", false );
513 function testOutputChanneledWNullChannelStringString() {
514 $this->m
->outputChanneled( "foo", null );
515 $this->m
->outputChanneled( "bar", null );
516 $this->assertOutputPrePostShutdown( "foo\nbar\n", false );
519 function testOutputChanneledWNullChannelStringNLString() {
520 $this->m
->outputChanneled( "foo\nbar", null );
521 $this->assertOutputPrePostShutdown( "foo\nbar\n", false );
524 function testOutputChanneledWNullChannelStringNLStringNLArbitraryAgain() {
525 $this->m
->outputChanneled( "", null );
526 $this->m
->outputChanneled( "foo", null );
527 $this->m
->outputChanneled( "", null );
528 $this->m
->outputChanneled( "\nb", null );
529 $this->m
->outputChanneled( "a", null );
530 $this->m
->outputChanneled( "", null );
531 $this->m
->outputChanneled( "r", null );
532 $this->assertOutputPrePostShutdown( "\nfoo\n\n\nb\na\n\nr\n", false );
535 function testOutputChanneledWChannelString() {
536 $this->m
->outputChanneled( "foo", "bazChannel" );
537 $this->assertOutputPrePostShutdown( "foo", true );
540 function testOutputChanneledWChannelStringNLString() {
541 $this->m
->outputChanneled( "foo\nbar", "bazChannel" );
542 $this->assertOutputPrePostShutdown( "foo\nbar", true );
545 function testOutputChanneledWChannelStringString() {
546 $this->m
->outputChanneled( "foo", "bazChannel" );
547 $this->m
->outputChanneled( "bar", "bazChannel" );
548 $this->assertOutputPrePostShutdown( "foobar", true );
551 function testOutputChanneledWChannelStringNLStringNLArbitraryAgain() {
552 $this->m
->outputChanneled( "", "bazChannel" );
553 $this->m
->outputChanneled( "foo", "bazChannel" );
554 $this->m
->outputChanneled( "", "bazChannel" );
555 $this->m
->outputChanneled( "\nb", "bazChannel" );
556 $this->m
->outputChanneled( "a", "bazChannel" );
557 $this->m
->outputChanneled( "", "bazChannel" );
558 $this->m
->outputChanneled( "r", "bazChannel" );
559 $this->assertOutputPrePostShutdown( "foo\nbar", true );
562 function testOutputChanneledWMultipleChannelsChannelChange() {
563 $this->m
->outputChanneled( "foo", "bazChannel" );
564 $this->m
->outputChanneled( "bar", "bazChannel" );
565 $this->m
->outputChanneled( "qux", "quuxChannel" );
566 $this->m
->outputChanneled( "corge", "bazChannel" );
567 $this->assertOutputPrePostShutdown( "foobar\nqux\ncorge", true );
570 function testOutputChanneledWMultipleChannelsChannelChangeEnclosedNull() {
571 $this->m
->outputChanneled( "foo", "bazChannel" );
572 $this->m
->outputChanneled( "bar", null );
573 $this->m
->outputChanneled( "qux", null );
574 $this->m
->outputChanneled( "corge", "bazChannel" );
575 $this->assertOutputPrePostShutdown( "foo\nbar\nqux\ncorge", true );
578 function testOutputChanneledWMultipleChannelsChannelAfterNullChange() {
579 $this->m
->outputChanneled( "foo", "bazChannel" );
580 $this->m
->outputChanneled( "bar", null );
581 $this->m
->outputChanneled( "qux", null );
582 $this->m
->outputChanneled( "corge", "quuxChannel" );
583 $this->assertOutputPrePostShutdown( "foo\nbar\nqux\ncorge", true );
586 function testOutputChanneledWAndWOChannelStringStartWO() {
587 $this->m
->outputChanneled( "foo" );
588 $this->m
->outputChanneled( "bar", "bazChannel" );
589 $this->m
->outputChanneled( "qux" );
590 $this->m
->outputChanneled( "quux", "bazChannel" );
591 $this->assertOutputPrePostShutdown( "foo\nbar\nqux\nquux", true );
594 function testOutputChanneledWAndWOChannelStringStartW() {
595 $this->m
->outputChanneled( "foo", "bazChannel" );
596 $this->m
->outputChanneled( "bar" );
597 $this->m
->outputChanneled( "qux", "bazChannel" );
598 $this->m
->outputChanneled( "quux" );
599 $this->assertOutputPrePostShutdown( "foo\nbar\nqux\nquux\n", false );
602 function testOutputChanneledWChannelTypeSwitch() {
603 $this->m
->outputChanneled( "foo", 1 );
604 $this->m
->outputChanneled( "bar", 1.0 );
605 $this->assertOutputPrePostShutdown( "foo\nbar", true );
608 function testOutputChanneledWOChannelIntermittentEmpty() {
609 $this->m
->outputChanneled( "foo" );
610 $this->m
->outputChanneled( "" );
611 $this->m
->outputChanneled( "bar" );
612 $this->assertOutputPrePostShutdown( "foo\n\nbar\n", false );
615 function testOutputChanneledWOChannelIntermittentFalse() {
616 $this->m
->outputChanneled( "foo" );
617 $this->m
->outputChanneled( false );
618 $this->m
->outputChanneled( "bar" );
619 $this->assertOutputPrePostShutdown( "foo\nbar\n", false );
622 function testOutputChanneledWNullChannelIntermittentEmpty() {
623 $this->m
->outputChanneled( "foo", null );
624 $this->m
->outputChanneled( "", null );
625 $this->m
->outputChanneled( "bar", null );
626 $this->assertOutputPrePostShutdown( "foo\n\nbar\n", false );
629 function testOutputChanneledWNullChannelIntermittentFalse() {
630 $this->m
->outputChanneled( "foo", null );
631 $this->m
->outputChanneled( false, null );
632 $this->m
->outputChanneled( "bar", null );
633 $this->assertOutputPrePostShutdown( "foo\nbar\n", false );
636 function testOutputChanneledWChannelIntermittentEmpty() {
637 $this->m
->outputChanneled( "foo", "bazChannel" );
638 $this->m
->outputChanneled( "", "bazChannel" );
639 $this->m
->outputChanneled( "bar", "bazChannel" );
640 $this->assertOutputPrePostShutdown( "foobar", true );
643 function testOutputChanneledWChannelIntermittentFalse() {
644 $this->m
->outputChanneled( "foo", "bazChannel" );
645 $this->m
->outputChanneled( false, "bazChannel" );
646 $this->m
->outputChanneled( "bar", "bazChannel" );
647 $this->assertOutputPrePostShutdown( "foo\nbar", true );
650 function testCleanupChanneledClean() {
651 $this->m
->cleanupChanneled();
652 $this->assertOutputPrePostShutdown( "", false );
655 function testCleanupChanneledAfterOutput() {
656 $this->m
->output( "foo" );
657 $this->m
->cleanupChanneled();
658 $this->assertOutputPrePostShutdown( "foo", false );
661 function testCleanupChanneledAfterOutputWNullChannel() {
662 $this->m
->output( "foo", null );
663 $this->m
->cleanupChanneled();
664 $this->assertOutputPrePostShutdown( "foo", false );
667 function testCleanupChanneledAfterOutputWChannel() {
668 $this->m
->output( "foo", "bazChannel" );
669 $this->m
->cleanupChanneled();
670 $this->assertOutputPrePostShutdown( "foo\n", false );
673 function testCleanupChanneledAfterNLOutput() {
674 $this->m
->output( "foo\n" );
675 $this->m
->cleanupChanneled();
676 $this->assertOutputPrePostShutdown( "foo\n", false );
679 function testCleanupChanneledAfterNLOutputWNullChannel() {
680 $this->m
->output( "foo\n", null );
681 $this->m
->cleanupChanneled();
682 $this->assertOutputPrePostShutdown( "foo\n", false );
685 function testCleanupChanneledAfterNLOutputWChannel() {
686 $this->m
->output( "foo\n", "bazChannel" );
687 $this->m
->cleanupChanneled();
688 $this->assertOutputPrePostShutdown( "foo\n", false );
691 function testCleanupChanneledAfterOutputChanneledWOChannel() {
692 $this->m
->outputChanneled( "foo" );
693 $this->m
->cleanupChanneled();
694 $this->assertOutputPrePostShutdown( "foo\n", false );
697 function testCleanupChanneledAfterOutputChanneledWNullChannel() {
698 $this->m
->outputChanneled( "foo", null );
699 $this->m
->cleanupChanneled();
700 $this->assertOutputPrePostShutdown( "foo\n", false );
703 function testCleanupChanneledAfterOutputChanneledWChannel() {
704 $this->m
->outputChanneled( "foo", "bazChannel" );
705 $this->m
->cleanupChanneled();
706 $this->assertOutputPrePostShutdown( "foo\n", false );
709 function testMultipleMaintenanceObjectsInteractionOutput() {
710 $m2 = new MaintenanceFixup( $this );
712 $this->m
->output( "foo" );
713 $m2->output( "bar" );
715 $this->assertEquals( "foobar", $this->getActualOutput(),
716 "Output before shutdown simulation (m2)" );
717 $m2->simulateShutdown();
718 $this->assertOutputPrePostShutdown( "foobar", false );
721 function testMultipleMaintenanceObjectsInteractionOutputWNullChannel() {
722 $m2 = new MaintenanceFixup( $this );
724 $this->m
->output( "foo", null );
725 $m2->output( "bar", null );
727 $this->assertEquals( "foobar", $this->getActualOutput(),
728 "Output before shutdown simulation (m2)" );
729 $m2->simulateShutdown();
730 $this->assertOutputPrePostShutdown( "foobar", false );
733 function testMultipleMaintenanceObjectsInteractionOutputWChannel() {
734 $m2 = new MaintenanceFixup( $this );
736 $this->m
->output( "foo", "bazChannel" );
737 $m2->output( "bar", "bazChannel" );
739 $this->assertEquals( "foobar", $this->getActualOutput(),
740 "Output before shutdown simulation (m2)" );
741 $m2->simulateShutdown();
742 $this->assertOutputPrePostShutdown( "foobar\n", true );
745 function testMultipleMaintenanceObjectsInteractionOutputWNullChannelNL() {
746 $m2 = new MaintenanceFixup( $this );
748 $this->m
->output( "foo\n", null );
749 $m2->output( "bar\n", null );
751 $this->assertEquals( "foo\nbar\n", $this->getActualOutput(),
752 "Output before shutdown simulation (m2)" );
753 $m2->simulateShutdown();
754 $this->assertOutputPrePostShutdown( "foo\nbar\n", false );
757 function testMultipleMaintenanceObjectsInteractionOutputWChannelNL() {
758 $m2 = new MaintenanceFixup( $this );
760 $this->m
->output( "foo\n", "bazChannel" );
761 $m2->output( "bar\n", "bazChannel" );
763 $this->assertEquals( "foobar", $this->getActualOutput(),
764 "Output before shutdown simulation (m2)" );
765 $m2->simulateShutdown();
766 $this->assertOutputPrePostShutdown( "foobar\n", true );
769 function testMultipleMaintenanceObjectsInteractionOutputChanneled() {
770 $m2 = new MaintenanceFixup( $this );
772 $this->m
->outputChanneled( "foo" );
773 $m2->outputChanneled( "bar" );
775 $this->assertEquals( "foo\nbar\n", $this->getActualOutput(),
776 "Output before shutdown simulation (m2)" );
777 $m2->simulateShutdown();
778 $this->assertOutputPrePostShutdown( "foo\nbar\n", false );
781 function testMultipleMaintenanceObjectsInteractionOutputChanneledWNullChannel() {
782 $m2 = new MaintenanceFixup( $this );
784 $this->m
->outputChanneled( "foo", null );
785 $m2->outputChanneled( "bar", null );
787 $this->assertEquals( "foo\nbar\n", $this->getActualOutput(),
788 "Output before shutdown simulation (m2)" );
789 $m2->simulateShutdown();
790 $this->assertOutputPrePostShutdown( "foo\nbar\n", false );
793 function testMultipleMaintenanceObjectsInteractionOutputChanneledWChannel() {
794 $m2 = new MaintenanceFixup( $this );
796 $this->m
->outputChanneled( "foo", "bazChannel" );
797 $m2->outputChanneled( "bar", "bazChannel" );
799 $this->assertEquals( "foobar", $this->getActualOutput(),
800 "Output before shutdown simulation (m2)" );
801 $m2->simulateShutdown();
802 $this->assertOutputPrePostShutdown( "foobar\n", true );
805 function testMultipleMaintenanceObjectsInteractionCleanupChanneledWChannel() {
806 $m2 = new MaintenanceFixup( $this );
808 $this->m
->outputChanneled( "foo", "bazChannel" );
809 $m2->outputChanneled( "bar", "bazChannel" );
811 $this->assertEquals( "foobar", $this->getActualOutput(),
812 "Output before first cleanup" );
813 $this->m
->cleanupChanneled();
814 $this->assertEquals( "foobar\n", $this->getActualOutput(),
815 "Output after first cleanup" );
816 $m2->cleanupChanneled();
817 $this->assertEquals( "foobar\n\n", $this->getActualOutput(),
818 "Output after second cleanup" );
820 $m2->simulateShutdown();
821 $this->assertOutputPrePostShutdown( "foobar\n\n", false );
825 * @covers Maintenance::getConfig
827 public function testGetConfig() {
828 $this->assertInstanceOf( 'Config', $this->m
->getConfig() );
830 MediaWikiServices
::getInstance()->getMainConfig(),
831 $this->m
->getConfig()
836 * @covers Maintenance::setConfig
838 public function testSetConfig() {
839 $conf = $this->getMock( 'Config' );
840 $this->m
->setConfig( $conf );
841 $this->assertSame( $conf, $this->m
->getConfig() );
844 function testParseArgs() {
845 $m2 = new MaintenanceFixup( $this );
846 // Create an option with an argument allowed to be specified multiple times
847 $m2->addOption( 'multi', 'This option does stuff', false, true, false, true );
848 $m2->loadWithArgv( [ '--multi', 'this1', '--multi', 'this2' ] );
850 $this->assertEquals( [ 'this1', 'this2' ], $m2->getOption( 'multi' ) );
851 $this->assertEquals( [ [ 'multi', 'this1' ], [ 'multi', 'this2' ] ],
852 $m2->orderedOptions
);
854 $m2->simulateShutdown();
856 $m2 = new MaintenanceFixup( $this );
858 $m2->addOption( 'multi', 'This option does stuff', false, false, false, true );
859 $m2->loadWithArgv( [ '--multi', '--multi' ] );
861 $this->assertEquals( [ 1, 1 ], $m2->getOption( 'multi' ) );
862 $this->assertEquals( [ [ 'multi', 1 ], [ 'multi', 1 ] ], $m2->orderedOptions
);
864 $m2->simulateShutdown();
866 $m2 = new MaintenanceFixup( $this );
867 // Create an option with an argument allowed to be specified multiple times
868 $m2->addOption( 'multi', 'This option doesn\'t actually support multiple occurrences' );
869 $m2->loadWithArgv( [ '--multi=yo' ] );
871 $this->assertEquals( 'yo', $m2->getOption( 'multi' ) );
872 $this->assertEquals( [ [ 'multi', 'yo' ] ], $m2->orderedOptions
);
874 $m2->simulateShutdown();