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.
10 * makes parts of the API of Maintenance that is hidden by protected visibily
11 * visible for testing, and makes up for a stream closing hack in Maintenance.php.
13 * This class is solely used for being able to test Maintenance right now
14 * without having to apply major refactorings to fix some design issues in
15 * Maintenance.php. Before adding more functions here, please consider whether
16 * this approach is correct, or a refactoring Maintenance to separate concers
17 * is more appropriate.
19 * Upon refactoring, keep in mind that besides the maintenance scrits themselves
20 * and tests right here, also at least Extension:Maintenance make use of
23 * Due to a hack in Maintenance.php using register_shutdown_function, be sure to
24 * finally call simulateShutdown on MaintenanceFixup instance before a test
28 class MaintenanceFixup
extends Maintenance
{
30 // --- Making up for the register_shutdown_function hack in Maintenance.php
33 * The test case that generated this instance.
35 * This member is motivated by allowing the destructor to check whether or not
36 * the test failed, in order to avoid unnecessary nags about omitted shutdown
38 * But as it is already available, we also usi it to flagging tests as failed
40 * @var MediaWikiTestCase
45 * shutdownSimulated === true if simulateShutdown has done it's work
49 private $shutdownSimulated = false;
52 * Simulates what Maintenance wants to happen at script's end.
54 public function simulateShutdown() {
56 if ( $this->shutdownSimulated
) {
57 $this->testCase
->fail( __METHOD__
. " called more than once" );
60 // The cleanup action.
61 $this->outputChanneled( false );
63 // Bookkeeping that we simulated the clean up.
64 $this->shutdownSimulated
= true;
67 // Note that the "public" here does not change visibility
68 public function outputChanneled( $msg, $channel = null ) {
69 if ( $this->shutdownSimulated
) {
70 if ( $msg !== false ) {
71 $this->testCase
->fail( "Already past simulated shutdown, but msg is "
72 . "not false. Did the hack in Maintenance.php change? Please "
73 . "adapt the test case or Maintenance.php" );
76 // The current call is the one registered via register_shutdown_function.
77 // We can safely ignore it, as we simulated this one via simulateShutdown
78 // before (if we did not, the destructor of this instance will warn about
83 call_user_func_array( array( "parent", __FUNCTION__
), func_get_args() );
87 * Safety net around register_shutdown_function of Maintenance.php
89 public function __destruct() {
90 if ( !$this->shutdownSimulated
) {
91 // Someone generated a MaintenanceFixup instance without calling
92 // simulateShutdown. We'd have to raise a PHPUnit exception to correctly
93 // flag this illegal usage. However, we are already in a destruktor, which
94 // would trigger undefined behavior. Hence, we can only report to the
95 // error output :( Hopefully people read the PHPUnit output.
96 $name = $this->testCase
->getName();
97 fwrite( STDERR
, "ERROR! Instance of " . __CLASS__
. " for test $name "
98 . "destructed without calling simulateShutdown method. Call "
99 . "simulateShutdown on the instance before it gets destructed." );
102 // The following guard is required, as PHP does not offer default destructors :(
103 if ( is_callable( "parent::__destruct" ) ) {
104 parent
::__destruct();
108 public function __construct( MediaWikiTestCase
$testCase ) {
109 parent
::__construct();
110 $this->testCase
= $testCase;
113 // --- Making protected functions visible for test
115 public function output( $out, $channel = null ) {
116 // Just to make PHP not nag about signature mismatches, we copied
117 // Maintenance::output signature. However, we do not use (or rely on)
118 // those variables. Instead we pass to Maintenance::output whatever we
119 // receive at runtime.
120 return call_user_func_array( array( "parent", __FUNCTION__
), func_get_args() );
123 // --- Requirements for getting instance of abstract class
125 public function execute() {
126 $this->testCase
->fail( __METHOD__
. " called unexpectedly" );
131 * @covers Maintenance
133 class MaintenanceTest
extends MediaWikiTestCase
{
136 * The main Maintenance instance that is used for testing.
138 * @var MaintenanceFixup
142 protected function setUp() {
144 $this->m
= new MaintenanceFixup( $this );
147 protected function tearDown() {
149 $this->m
->simulateShutdown();
156 * asserts the output before and after simulating shutdown
158 * This function simulates shutdown of self::m.
160 * @param string $preShutdownOutput Expected output before simulating shutdown
161 * @param bool $expectNLAppending Whether or not shutdown simulation is expected
162 * to add a newline to the output. If false, $preShutdownOutput is the
163 * expected output after shutdown simulation. Otherwise,
164 * $preShutdownOutput with an appended newline is the expected output
165 * after shutdown simulation.
167 private function assertOutputPrePostShutdown( $preShutdownOutput, $expectNLAppending ) {
169 $this->assertEquals( $preShutdownOutput, $this->getActualOutput(),
170 "Output before shutdown simulation" );
172 $this->m
->simulateShutdown();
175 $postShutdownOutput = $preShutdownOutput . ( $expectNLAppending ?
"\n" : "" );
176 $this->expectOutputString( $postShutdownOutput );
179 // Although the following tests do not seem to be too consistent (compare for
180 // example the newlines within the test.*StringString tests, or the
181 // test.*Intermittent.* tests), the objective of these tests is not to describe
182 // consistent behavior, but rather currently existing behavior.
184 function testOutputEmpty() {
185 $this->m
->output( "" );
186 $this->assertOutputPrePostShutdown( "", false );
189 function testOutputString() {
190 $this->m
->output( "foo" );
191 $this->assertOutputPrePostShutdown( "foo", false );
194 function testOutputStringString() {
195 $this->m
->output( "foo" );
196 $this->m
->output( "bar" );
197 $this->assertOutputPrePostShutdown( "foobar", false );
200 function testOutputStringNL() {
201 $this->m
->output( "foo\n" );
202 $this->assertOutputPrePostShutdown( "foo\n", false );
205 function testOutputStringNLNL() {
206 $this->m
->output( "foo\n\n" );
207 $this->assertOutputPrePostShutdown( "foo\n\n", false );
210 function testOutputStringNLString() {
211 $this->m
->output( "foo\nbar" );
212 $this->assertOutputPrePostShutdown( "foo\nbar", false );
215 function testOutputStringNLStringNL() {
216 $this->m
->output( "foo\nbar\n" );
217 $this->assertOutputPrePostShutdown( "foo\nbar\n", false );
220 function testOutputStringNLStringNLLinewise() {
221 $this->m
->output( "foo\n" );
222 $this->m
->output( "bar\n" );
223 $this->assertOutputPrePostShutdown( "foo\nbar\n", false );
226 function testOutputStringNLStringNLArbitrary() {
227 $this->m
->output( "" );
228 $this->m
->output( "foo" );
229 $this->m
->output( "" );
230 $this->m
->output( "\n" );
231 $this->m
->output( "ba" );
232 $this->m
->output( "" );
233 $this->m
->output( "r\n" );
234 $this->assertOutputPrePostShutdown( "foo\nbar\n", false );
237 function testOutputStringNLStringNLArbitraryAgain() {
238 $this->m
->output( "" );
239 $this->m
->output( "foo" );
240 $this->m
->output( "" );
241 $this->m
->output( "\nb" );
242 $this->m
->output( "a" );
243 $this->m
->output( "" );
244 $this->m
->output( "r\n" );
245 $this->assertOutputPrePostShutdown( "foo\nbar\n", false );
248 function testOutputWNullChannelEmpty() {
249 $this->m
->output( "", null );
250 $this->assertOutputPrePostShutdown( "", false );
253 function testOutputWNullChannelString() {
254 $this->m
->output( "foo", null );
255 $this->assertOutputPrePostShutdown( "foo", false );
258 function testOutputWNullChannelStringString() {
259 $this->m
->output( "foo", null );
260 $this->m
->output( "bar", null );
261 $this->assertOutputPrePostShutdown( "foobar", false );
264 function testOutputWNullChannelStringNL() {
265 $this->m
->output( "foo\n", null );
266 $this->assertOutputPrePostShutdown( "foo\n", false );
269 function testOutputWNullChannelStringNLNL() {
270 $this->m
->output( "foo\n\n", null );
271 $this->assertOutputPrePostShutdown( "foo\n\n", false );
274 function testOutputWNullChannelStringNLString() {
275 $this->m
->output( "foo\nbar", null );
276 $this->assertOutputPrePostShutdown( "foo\nbar", false );
279 function testOutputWNullChannelStringNLStringNL() {
280 $this->m
->output( "foo\nbar\n", null );
281 $this->assertOutputPrePostShutdown( "foo\nbar\n", false );
284 function testOutputWNullChannelStringNLStringNLLinewise() {
285 $this->m
->output( "foo\n", null );
286 $this->m
->output( "bar\n", null );
287 $this->assertOutputPrePostShutdown( "foo\nbar\n", false );
290 function testOutputWNullChannelStringNLStringNLArbitrary() {
291 $this->m
->output( "", null );
292 $this->m
->output( "foo", null );
293 $this->m
->output( "", null );
294 $this->m
->output( "\n", null );
295 $this->m
->output( "ba", null );
296 $this->m
->output( "", null );
297 $this->m
->output( "r\n", null );
298 $this->assertOutputPrePostShutdown( "foo\nbar\n", false );
301 function testOutputWNullChannelStringNLStringNLArbitraryAgain() {
302 $this->m
->output( "", null );
303 $this->m
->output( "foo", null );
304 $this->m
->output( "", null );
305 $this->m
->output( "\nb", null );
306 $this->m
->output( "a", null );
307 $this->m
->output( "", null );
308 $this->m
->output( "r\n", null );
309 $this->assertOutputPrePostShutdown( "foo\nbar\n", false );
312 function testOutputWChannelString() {
313 $this->m
->output( "foo", "bazChannel" );
314 $this->assertOutputPrePostShutdown( "foo", true );
317 function testOutputWChannelStringNL() {
318 $this->m
->output( "foo\n", "bazChannel" );
319 $this->assertOutputPrePostShutdown( "foo", true );
322 function testOutputWChannelStringNLNL() {
323 // If this test fails, note that output takes strings with double line
324 // endings (although output's implementation in this situation calls
325 // outputChanneled with a string ending in a nl ... which is not allowed
326 // according to the documentation of outputChanneled)
327 $this->m
->output( "foo\n\n", "bazChannel" );
328 $this->assertOutputPrePostShutdown( "foo\n", true );
331 function testOutputWChannelStringNLString() {
332 $this->m
->output( "foo\nbar", "bazChannel" );
333 $this->assertOutputPrePostShutdown( "foo\nbar", true );
336 function testOutputWChannelStringNLStringNL() {
337 $this->m
->output( "foo\nbar\n", "bazChannel" );
338 $this->assertOutputPrePostShutdown( "foo\nbar", true );
341 function testOutputWChannelStringNLStringNLLinewise() {
342 $this->m
->output( "foo\n", "bazChannel" );
343 $this->m
->output( "bar\n", "bazChannel" );
344 $this->assertOutputPrePostShutdown( "foobar", true );
347 function testOutputWChannelStringNLStringNLArbitrary() {
348 $this->m
->output( "", "bazChannel" );
349 $this->m
->output( "foo", "bazChannel" );
350 $this->m
->output( "", "bazChannel" );
351 $this->m
->output( "\n", "bazChannel" );
352 $this->m
->output( "ba", "bazChannel" );
353 $this->m
->output( "", "bazChannel" );
354 $this->m
->output( "r\n", "bazChannel" );
355 $this->assertOutputPrePostShutdown( "foobar", true );
358 function testOutputWChannelStringNLStringNLArbitraryAgain() {
359 $this->m
->output( "", "bazChannel" );
360 $this->m
->output( "foo", "bazChannel" );
361 $this->m
->output( "", "bazChannel" );
362 $this->m
->output( "\nb", "bazChannel" );
363 $this->m
->output( "a", "bazChannel" );
364 $this->m
->output( "", "bazChannel" );
365 $this->m
->output( "r\n", "bazChannel" );
366 $this->assertOutputPrePostShutdown( "foo\nbar", true );
369 function testOutputWMultipleChannelsChannelChange() {
370 $this->m
->output( "foo", "bazChannel" );
371 $this->m
->output( "bar", "bazChannel" );
372 $this->m
->output( "qux", "quuxChannel" );
373 $this->m
->output( "corge", "bazChannel" );
374 $this->assertOutputPrePostShutdown( "foobar\nqux\ncorge", true );
377 function testOutputWMultipleChannelsChannelChangeNL() {
378 $this->m
->output( "foo", "bazChannel" );
379 $this->m
->output( "bar\n", "bazChannel" );
380 $this->m
->output( "qux\n", "quuxChannel" );
381 $this->m
->output( "corge", "bazChannel" );
382 $this->assertOutputPrePostShutdown( "foobar\nqux\ncorge", true );
385 function testOutputWAndWOChannelStringStartWO() {
386 $this->m
->output( "foo" );
387 $this->m
->output( "bar", "bazChannel" );
388 $this->m
->output( "qux" );
389 $this->m
->output( "quux", "bazChannel" );
390 $this->assertOutputPrePostShutdown( "foobar\nquxquux", true );
393 function testOutputWAndWOChannelStringStartW() {
394 $this->m
->output( "foo", "bazChannel" );
395 $this->m
->output( "bar" );
396 $this->m
->output( "qux", "bazChannel" );
397 $this->m
->output( "quux" );
398 $this->assertOutputPrePostShutdown( "foo\nbarqux\nquux", false );
401 function testOutputWChannelTypeSwitch() {
402 $this->m
->output( "foo", 1 );
403 $this->m
->output( "bar", 1.0 );
404 $this->assertOutputPrePostShutdown( "foo\nbar", true );
407 function testOutputIntermittentEmpty() {
408 $this->m
->output( "foo" );
409 $this->m
->output( "" );
410 $this->m
->output( "bar" );
411 $this->assertOutputPrePostShutdown( "foobar", false );
414 function testOutputIntermittentFalse() {
415 $this->m
->output( "foo" );
416 $this->m
->output( false );
417 $this->m
->output( "bar" );
418 $this->assertOutputPrePostShutdown( "foobar", false );
421 function testOutputIntermittentFalseAfterOtherChannel() {
422 $this->m
->output( "qux", "quuxChannel" );
423 $this->m
->output( "foo" );
424 $this->m
->output( false );
425 $this->m
->output( "bar" );
426 $this->assertOutputPrePostShutdown( "qux\nfoobar", false );
429 function testOutputWNullChannelIntermittentEmpty() {
430 $this->m
->output( "foo", null );
431 $this->m
->output( "", null );
432 $this->m
->output( "bar", null );
433 $this->assertOutputPrePostShutdown( "foobar", false );
436 function testOutputWNullChannelIntermittentFalse() {
437 $this->m
->output( "foo", null );
438 $this->m
->output( false, null );
439 $this->m
->output( "bar", null );
440 $this->assertOutputPrePostShutdown( "foobar", false );
443 function testOutputWChannelIntermittentEmpty() {
444 $this->m
->output( "foo", "bazChannel" );
445 $this->m
->output( "", "bazChannel" );
446 $this->m
->output( "bar", "bazChannel" );
447 $this->assertOutputPrePostShutdown( "foobar", true );
450 function testOutputWChannelIntermittentFalse() {
451 $this->m
->output( "foo", "bazChannel" );
452 $this->m
->output( false, "bazChannel" );
453 $this->m
->output( "bar", "bazChannel" );
454 $this->assertOutputPrePostShutdown( "foobar", true );
457 // Note that (per documentation) outputChanneled does take strings that end
458 // in \n, hence we do not test such strings.
460 function testOutputChanneledEmpty() {
461 $this->m
->outputChanneled( "" );
462 $this->assertOutputPrePostShutdown( "\n", false );
465 function testOutputChanneledString() {
466 $this->m
->outputChanneled( "foo" );
467 $this->assertOutputPrePostShutdown( "foo\n", false );
470 function testOutputChanneledStringString() {
471 $this->m
->outputChanneled( "foo" );
472 $this->m
->outputChanneled( "bar" );
473 $this->assertOutputPrePostShutdown( "foo\nbar\n", false );
476 function testOutputChanneledStringNLString() {
477 $this->m
->outputChanneled( "foo\nbar" );
478 $this->assertOutputPrePostShutdown( "foo\nbar\n", false );
481 function testOutputChanneledStringNLStringNLArbitraryAgain() {
482 $this->m
->outputChanneled( "" );
483 $this->m
->outputChanneled( "foo" );
484 $this->m
->outputChanneled( "" );
485 $this->m
->outputChanneled( "\nb" );
486 $this->m
->outputChanneled( "a" );
487 $this->m
->outputChanneled( "" );
488 $this->m
->outputChanneled( "r" );
489 $this->assertOutputPrePostShutdown( "\nfoo\n\n\nb\na\n\nr\n", false );
492 function testOutputChanneledWNullChannelEmpty() {
493 $this->m
->outputChanneled( "", null );
494 $this->assertOutputPrePostShutdown( "\n", false );
497 function testOutputChanneledWNullChannelString() {
498 $this->m
->outputChanneled( "foo", null );
499 $this->assertOutputPrePostShutdown( "foo\n", false );
502 function testOutputChanneledWNullChannelStringString() {
503 $this->m
->outputChanneled( "foo", null );
504 $this->m
->outputChanneled( "bar", null );
505 $this->assertOutputPrePostShutdown( "foo\nbar\n", false );
508 function testOutputChanneledWNullChannelStringNLString() {
509 $this->m
->outputChanneled( "foo\nbar", null );
510 $this->assertOutputPrePostShutdown( "foo\nbar\n", false );
513 function testOutputChanneledWNullChannelStringNLStringNLArbitraryAgain() {
514 $this->m
->outputChanneled( "", null );
515 $this->m
->outputChanneled( "foo", null );
516 $this->m
->outputChanneled( "", null );
517 $this->m
->outputChanneled( "\nb", null );
518 $this->m
->outputChanneled( "a", null );
519 $this->m
->outputChanneled( "", null );
520 $this->m
->outputChanneled( "r", null );
521 $this->assertOutputPrePostShutdown( "\nfoo\n\n\nb\na\n\nr\n", false );
524 function testOutputChanneledWChannelString() {
525 $this->m
->outputChanneled( "foo", "bazChannel" );
526 $this->assertOutputPrePostShutdown( "foo", true );
529 function testOutputChanneledWChannelStringNLString() {
530 $this->m
->outputChanneled( "foo\nbar", "bazChannel" );
531 $this->assertOutputPrePostShutdown( "foo\nbar", true );
534 function testOutputChanneledWChannelStringString() {
535 $this->m
->outputChanneled( "foo", "bazChannel" );
536 $this->m
->outputChanneled( "bar", "bazChannel" );
537 $this->assertOutputPrePostShutdown( "foobar", true );
540 function testOutputChanneledWChannelStringNLStringNLArbitraryAgain() {
541 $this->m
->outputChanneled( "", "bazChannel" );
542 $this->m
->outputChanneled( "foo", "bazChannel" );
543 $this->m
->outputChanneled( "", "bazChannel" );
544 $this->m
->outputChanneled( "\nb", "bazChannel" );
545 $this->m
->outputChanneled( "a", "bazChannel" );
546 $this->m
->outputChanneled( "", "bazChannel" );
547 $this->m
->outputChanneled( "r", "bazChannel" );
548 $this->assertOutputPrePostShutdown( "foo\nbar", true );
551 function testOutputChanneledWMultipleChannelsChannelChange() {
552 $this->m
->outputChanneled( "foo", "bazChannel" );
553 $this->m
->outputChanneled( "bar", "bazChannel" );
554 $this->m
->outputChanneled( "qux", "quuxChannel" );
555 $this->m
->outputChanneled( "corge", "bazChannel" );
556 $this->assertOutputPrePostShutdown( "foobar\nqux\ncorge", true );
559 function testOutputChanneledWMultipleChannelsChannelChangeEnclosedNull() {
560 $this->m
->outputChanneled( "foo", "bazChannel" );
561 $this->m
->outputChanneled( "bar", null );
562 $this->m
->outputChanneled( "qux", null );
563 $this->m
->outputChanneled( "corge", "bazChannel" );
564 $this->assertOutputPrePostShutdown( "foo\nbar\nqux\ncorge", true );
567 function testOutputChanneledWMultipleChannelsChannelAfterNullChange() {
568 $this->m
->outputChanneled( "foo", "bazChannel" );
569 $this->m
->outputChanneled( "bar", null );
570 $this->m
->outputChanneled( "qux", null );
571 $this->m
->outputChanneled( "corge", "quuxChannel" );
572 $this->assertOutputPrePostShutdown( "foo\nbar\nqux\ncorge", true );
575 function testOutputChanneledWAndWOChannelStringStartWO() {
576 $this->m
->outputChanneled( "foo" );
577 $this->m
->outputChanneled( "bar", "bazChannel" );
578 $this->m
->outputChanneled( "qux" );
579 $this->m
->outputChanneled( "quux", "bazChannel" );
580 $this->assertOutputPrePostShutdown( "foo\nbar\nqux\nquux", true );
583 function testOutputChanneledWAndWOChannelStringStartW() {
584 $this->m
->outputChanneled( "foo", "bazChannel" );
585 $this->m
->outputChanneled( "bar" );
586 $this->m
->outputChanneled( "qux", "bazChannel" );
587 $this->m
->outputChanneled( "quux" );
588 $this->assertOutputPrePostShutdown( "foo\nbar\nqux\nquux\n", false );
591 function testOutputChanneledWChannelTypeSwitch() {
592 $this->m
->outputChanneled( "foo", 1 );
593 $this->m
->outputChanneled( "bar", 1.0 );
594 $this->assertOutputPrePostShutdown( "foo\nbar", true );
597 function testOutputChanneledWOChannelIntermittentEmpty() {
598 $this->m
->outputChanneled( "foo" );
599 $this->m
->outputChanneled( "" );
600 $this->m
->outputChanneled( "bar" );
601 $this->assertOutputPrePostShutdown( "foo\n\nbar\n", false );
604 function testOutputChanneledWOChannelIntermittentFalse() {
605 $this->m
->outputChanneled( "foo" );
606 $this->m
->outputChanneled( false );
607 $this->m
->outputChanneled( "bar" );
608 $this->assertOutputPrePostShutdown( "foo\nbar\n", false );
611 function testOutputChanneledWNullChannelIntermittentEmpty() {
612 $this->m
->outputChanneled( "foo", null );
613 $this->m
->outputChanneled( "", null );
614 $this->m
->outputChanneled( "bar", null );
615 $this->assertOutputPrePostShutdown( "foo\n\nbar\n", false );
618 function testOutputChanneledWNullChannelIntermittentFalse() {
619 $this->m
->outputChanneled( "foo", null );
620 $this->m
->outputChanneled( false, null );
621 $this->m
->outputChanneled( "bar", null );
622 $this->assertOutputPrePostShutdown( "foo\nbar\n", false );
625 function testOutputChanneledWChannelIntermittentEmpty() {
626 $this->m
->outputChanneled( "foo", "bazChannel" );
627 $this->m
->outputChanneled( "", "bazChannel" );
628 $this->m
->outputChanneled( "bar", "bazChannel" );
629 $this->assertOutputPrePostShutdown( "foobar", true );
632 function testOutputChanneledWChannelIntermittentFalse() {
633 $this->m
->outputChanneled( "foo", "bazChannel" );
634 $this->m
->outputChanneled( false, "bazChannel" );
635 $this->m
->outputChanneled( "bar", "bazChannel" );
636 $this->assertOutputPrePostShutdown( "foo\nbar", true );
639 function testCleanupChanneledClean() {
640 $this->m
->cleanupChanneled();
641 $this->assertOutputPrePostShutdown( "", false );
644 function testCleanupChanneledAfterOutput() {
645 $this->m
->output( "foo" );
646 $this->m
->cleanupChanneled();
647 $this->assertOutputPrePostShutdown( "foo", false );
650 function testCleanupChanneledAfterOutputWNullChannel() {
651 $this->m
->output( "foo", null );
652 $this->m
->cleanupChanneled();
653 $this->assertOutputPrePostShutdown( "foo", false );
656 function testCleanupChanneledAfterOutputWChannel() {
657 $this->m
->output( "foo", "bazChannel" );
658 $this->m
->cleanupChanneled();
659 $this->assertOutputPrePostShutdown( "foo\n", false );
662 function testCleanupChanneledAfterNLOutput() {
663 $this->m
->output( "foo\n" );
664 $this->m
->cleanupChanneled();
665 $this->assertOutputPrePostShutdown( "foo\n", false );
668 function testCleanupChanneledAfterNLOutputWNullChannel() {
669 $this->m
->output( "foo\n", null );
670 $this->m
->cleanupChanneled();
671 $this->assertOutputPrePostShutdown( "foo\n", false );
674 function testCleanupChanneledAfterNLOutputWChannel() {
675 $this->m
->output( "foo\n", "bazChannel" );
676 $this->m
->cleanupChanneled();
677 $this->assertOutputPrePostShutdown( "foo\n", false );
680 function testCleanupChanneledAfterOutputChanneledWOChannel() {
681 $this->m
->outputChanneled( "foo" );
682 $this->m
->cleanupChanneled();
683 $this->assertOutputPrePostShutdown( "foo\n", false );
686 function testCleanupChanneledAfterOutputChanneledWNullChannel() {
687 $this->m
->outputChanneled( "foo", null );
688 $this->m
->cleanupChanneled();
689 $this->assertOutputPrePostShutdown( "foo\n", false );
692 function testCleanupChanneledAfterOutputChanneledWChannel() {
693 $this->m
->outputChanneled( "foo", "bazChannel" );
694 $this->m
->cleanupChanneled();
695 $this->assertOutputPrePostShutdown( "foo\n", false );
698 function testMultipleMaintenanceObjectsInteractionOutput() {
699 $m2 = new MaintenanceFixup( $this );
701 $this->m
->output( "foo" );
702 $m2->output( "bar" );
704 $this->assertEquals( "foobar", $this->getActualOutput(),
705 "Output before shutdown simulation (m2)" );
706 $m2->simulateShutdown();
707 $this->assertOutputPrePostShutdown( "foobar", false );
710 function testMultipleMaintenanceObjectsInteractionOutputWNullChannel() {
711 $m2 = new MaintenanceFixup( $this );
713 $this->m
->output( "foo", null );
714 $m2->output( "bar", null );
716 $this->assertEquals( "foobar", $this->getActualOutput(),
717 "Output before shutdown simulation (m2)" );
718 $m2->simulateShutdown();
719 $this->assertOutputPrePostShutdown( "foobar", false );
722 function testMultipleMaintenanceObjectsInteractionOutputWChannel() {
723 $m2 = new MaintenanceFixup( $this );
725 $this->m
->output( "foo", "bazChannel" );
726 $m2->output( "bar", "bazChannel" );
728 $this->assertEquals( "foobar", $this->getActualOutput(),
729 "Output before shutdown simulation (m2)" );
730 $m2->simulateShutdown();
731 $this->assertOutputPrePostShutdown( "foobar\n", true );
734 function testMultipleMaintenanceObjectsInteractionOutputWNullChannelNL() {
735 $m2 = new MaintenanceFixup( $this );
737 $this->m
->output( "foo\n", null );
738 $m2->output( "bar\n", null );
740 $this->assertEquals( "foo\nbar\n", $this->getActualOutput(),
741 "Output before shutdown simulation (m2)" );
742 $m2->simulateShutdown();
743 $this->assertOutputPrePostShutdown( "foo\nbar\n", false );
746 function testMultipleMaintenanceObjectsInteractionOutputWChannelNL() {
747 $m2 = new MaintenanceFixup( $this );
749 $this->m
->output( "foo\n", "bazChannel" );
750 $m2->output( "bar\n", "bazChannel" );
752 $this->assertEquals( "foobar", $this->getActualOutput(),
753 "Output before shutdown simulation (m2)" );
754 $m2->simulateShutdown();
755 $this->assertOutputPrePostShutdown( "foobar\n", true );
758 function testMultipleMaintenanceObjectsInteractionOutputChanneled() {
759 $m2 = new MaintenanceFixup( $this );
761 $this->m
->outputChanneled( "foo" );
762 $m2->outputChanneled( "bar" );
764 $this->assertEquals( "foo\nbar\n", $this->getActualOutput(),
765 "Output before shutdown simulation (m2)" );
766 $m2->simulateShutdown();
767 $this->assertOutputPrePostShutdown( "foo\nbar\n", false );
770 function testMultipleMaintenanceObjectsInteractionOutputChanneledWNullChannel() {
771 $m2 = new MaintenanceFixup( $this );
773 $this->m
->outputChanneled( "foo", null );
774 $m2->outputChanneled( "bar", null );
776 $this->assertEquals( "foo\nbar\n", $this->getActualOutput(),
777 "Output before shutdown simulation (m2)" );
778 $m2->simulateShutdown();
779 $this->assertOutputPrePostShutdown( "foo\nbar\n", false );
782 function testMultipleMaintenanceObjectsInteractionOutputChanneledWChannel() {
783 $m2 = new MaintenanceFixup( $this );
785 $this->m
->outputChanneled( "foo", "bazChannel" );
786 $m2->outputChanneled( "bar", "bazChannel" );
788 $this->assertEquals( "foobar", $this->getActualOutput(),
789 "Output before shutdown simulation (m2)" );
790 $m2->simulateShutdown();
791 $this->assertOutputPrePostShutdown( "foobar\n", true );
794 function testMultipleMaintenanceObjectsInteractionCleanupChanneledWChannel() {
795 $m2 = new MaintenanceFixup( $this );
797 $this->m
->outputChanneled( "foo", "bazChannel" );
798 $m2->outputChanneled( "bar", "bazChannel" );
800 $this->assertEquals( "foobar", $this->getActualOutput(),
801 "Output before first cleanup" );
802 $this->m
->cleanupChanneled();
803 $this->assertEquals( "foobar\n", $this->getActualOutput(),
804 "Output after first cleanup" );
805 $m2->cleanupChanneled();
806 $this->assertEquals( "foobar\n\n", $this->getActualOutput(),
807 "Output after second cleanup" );
809 $m2->simulateShutdown();
810 $this->assertOutputPrePostShutdown( "foobar\n\n", false );
814 * @covers Maintenance::getConfig
816 public function testGetConfig() {
817 $this->assertInstanceOf( 'Config', $this->m
->getConfig() );
819 ConfigFactory
::getDefaultInstance()->makeConfig( 'main' ),
820 $this->m
->getConfig()
825 * @covers Maintenance::setConfig
827 public function testSetConfig() {
828 $conf = $this->getMock( 'Config' );
829 $this->m
->setConfig( $conf );
830 $this->assertSame( $conf, $this->m
->getConfig() );