MediaWiki  REL1_31
MaintenanceBaseTestCase.php
Go to the documentation of this file.
1 <?php
2 
4 
7 use Wikimedia\TestingAccessWrapper;
8 
9 abstract class MaintenanceBaseTestCase extends MediaWikiTestCase {
10 
16  protected $maintenance;
17 
18  protected function setUp() {
19  parent::setUp();
20 
21  $this->maintenance = $this->createMaintenance();
22  }
23 
28  protected function tearDown() {
29  if ( $this->maintenance ) {
30  $this->maintenance->cleanupChanneled();
31  }
32 
33  // This is smelly, but maintenance scripts usually produce output, so
34  // we anticipate and ignore with a regex that will catch everything.
35  //
36  // If you call $this->expectOutputRegex in your subclass, this guard
37  // won't be triggered, and your specific pattern will be respected.
38  if ( !$this->hasExpectationOnOutput() ) {
39  $this->expectOutputRegex( '/.*/' );
40  }
41 
42  parent::tearDown();
43  }
44 
55  abstract protected function getMaintenanceClass();
56 
62  protected function createMaintenance() {
63  $className = $this->getMaintenanceClass();
64  $obj = new $className();
65 
66  // We use TestingAccessWrapper in order to access protected internals
67  // such as `output()`.
68  return TestingAccessWrapper::newFromObject( $obj );
69  }
70 
83  protected function assertOutputPrePostShutdown( $preShutdownOutput, $expectNLAppending ) {
84  $this->assertEquals( $preShutdownOutput, $this->getActualOutput(),
85  "Output before shutdown simulation" );
86 
87  $this->maintenance->cleanupChanneled();
88 
89  $postShutdownOutput = $preShutdownOutput . ( $expectNLAppending ? "\n" : "" );
90  $this->expectOutputString( $postShutdownOutput );
91  }
92 
93 }
MediaWiki\Tests\Maintenance\MaintenanceBaseTestCase\$maintenance
Maintenance $maintenance
The main Maintenance instance that is used for testing, wrapped and mockable.
Definition: MaintenanceBaseTestCase.php:16
use
Apache License January AND DISTRIBUTION Definitions License shall mean the terms and conditions for use
Definition: APACHE-LICENSE-2.0.txt:10
MediaWiki\Tests\Maintenance\MaintenanceBaseTestCase\getMaintenanceClass
getMaintenanceClass()
MediaWiki\Tests\Maintenance\MaintenanceBaseTestCase\setUp
setUp()
Definition: MaintenanceBaseTestCase.php:18
MediaWiki\Tests\Maintenance\MaintenanceBaseTestCase\createMaintenance
createMaintenance()
Called by setUp to initialize $this->maintenance.
Definition: MaintenanceBaseTestCase.php:62
Maintenance
Abstract maintenance class for quickly writing and churning out maintenance scripts with minimal effo...
Definition: maintenance.txt:39
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:37
MediaWiki\Tests\Maintenance
Definition: backup_LogTest.php:3
MediaWiki\Tests\Maintenance\MaintenanceBaseTestCase
Definition: MaintenanceBaseTestCase.php:9
MediaWikiTestCase
Definition: MediaWikiTestCase.php:17
MediaWiki\Tests\Maintenance\MaintenanceBaseTestCase\tearDown
tearDown()
Do a little stream cleanup to prevent output in case the child class hasn't tested the capture buffer...
Definition: MaintenanceBaseTestCase.php:28
MediaWiki\Tests\Maintenance\MaintenanceBaseTestCase\assertOutputPrePostShutdown
assertOutputPrePostShutdown( $preShutdownOutput, $expectNLAppending)
Asserts the output before and after simulating shutdown.
Definition: MaintenanceBaseTestCase.php:83