private $loggers = [];
/**
- * @var LoggerInterface
+ * The CLI arguments passed through from phpunit.php
+ * @var array
*/
- private $testLogger;
+ private $cliArgs = [];
/**
* Table name prefixes. Oracle likes it shorter.
$this->backupGlobals = false;
$this->backupStaticAttributes = false;
- $this->testLogger = self::getTestLogger();
- }
-
- private static function getTestLogger() {
- return LoggerFactory::getInstance( 'tests-phpunit' );
}
public function __destruct() {
}
public function run( PHPUnit_Framework_TestResult $result = null ) {
+ if ( $result instanceof MediaWikiTestResult ) {
+ $this->cliArgs = $result->getMediaWikiCliArgs();
+ }
$this->overrideMwServices();
- $needsResetDB = false;
+ if ( $this->needsDB() && !$this->isTestInDatabaseGroup() ) {
+ throw new Exception(
+ get_class( $this ) . ' apparently needsDB but is not in the Database group'
+ );
+ }
+ $needsResetDB = false;
if ( !self::$dbSetup || $this->needsDB() ) {
// set up a DB connection for this test to use
- $this->testLogger->info( "Setting up DB for " . $this->toString() );
self::$useTemporaryTables = !$this->getCliArg( 'use-normal-tables' );
self::$reuseDB = $this->getCliArg( 'reuse-db' );
$needsResetDB = true;
}
- $this->testLogger->info( "Starting test " . $this->toString() );
parent::run( $result );
- $this->testLogger->info( "Finished test " . $this->toString() );
if ( $needsResetDB ) {
- $this->testLogger->info( "Resetting DB" );
$this->resetDB( $this->db, $this->tablesUsed );
}
*/
public function needsDB() {
// If the test says it uses database tables, it needs the database
- if ( $this->tablesUsed ) {
- return true;
- }
+ return $this->tablesUsed || $this->isTestInDatabaseGroup();
+ }
+ /**
+ * @return bool
+ * @since 1.32
+ */
+ protected function isTestInDatabaseGroup() {
// If the test class says it belongs to the Database group, it needs the database.
// NOTE: This ONLY checks for the group in the class level doc comment.
$rc = new ReflectionClass( $this );
- if ( preg_match( '/@group +Database/im', $rc->getDocComment() ) ) {
- return true;
- }
-
- return false;
+ return (bool)preg_match( '/@group +Database/im', $rc->getDocComment() );
}
/**
* @since 1.32
*/
protected function addCoreDBData() {
- $this->testLogger->info( __METHOD__ );
if ( $this->db->getType() == 'oracle' ) {
# Insert 0 user to prevent FK violations
# Anonymous user
$originalTables = $db->listTables( $db->_originalTablePrefix, __METHOD__ );
if ( $prefix === 'unprefixed' ) {
- $originalPrefixRegex = '/^' . preg_quote( $db->_originalTablePrefix ) . '/';
+ $originalPrefixRegex = '/^' . preg_quote( $db->_originalTablePrefix, '/' ) . '/';
$originalTables = array_map(
function ( $pt ) use ( $originalPrefixRegex ) {
return preg_replace( $originalPrefixRegex, '', $pt );
* @return mixed
*/
public function getCliArg( $offset ) {
- if ( isset( PHPUnitMaintClass::$additionalOptions[$offset] ) ) {
- return PHPUnitMaintClass::$additionalOptions[$offset];
- }
-
- return null;
+ return $this->cliArgs[$offset] ?? null;
}
/**
* @param mixed $value
*/
public function setCliArg( $offset, $value ) {
- PHPUnitMaintClass::$additionalOptions[$offset] = $value;
+ $this->cliArgs[$offset] = $value;
}
/**
protected function assertFileContains(
$fileName,
$actualData,
- $createIfMissing = true,
+ $createIfMissing = false,
$msg = ''
) {
if ( $createIfMissing ) {