wiki.techinc.nl/tests/phpunit/includes/Storage/PreMcrSchemaOverride.php
daniel 32e9266d8d Introduce per-schema unit tests for revision storage.
This introduces traits for testing different schema variations.
These are not very useful in this patch, but make it much easier
to add tests for MCR schema migration in subsequent patches.

The code in this patch was previously part of If259b1e1c49ceaa4.

Change-Id: I239572f75bebbc9c731a3e3860c4eff179dc15e4
2018-06-07 13:31:16 +00:00

54 lines
1.1 KiB
PHP

<?php
namespace MediaWiki\Tests\Storage;
use Wikimedia\Rdbms\IMaintainableDatabase;
use MediaWiki\DB\PatchFileLocation;
/**
* Trait providing schema overrides that allow tests to run against the pre-MCR database schema.
*/
trait PreMcrSchemaOverride {
use PatchFileLocation;
use McrSchemaDetection;
/**
* @return int
*/
protected function getMcrMigrationStage() {
return MIGRATION_OLD;
}
/**
* @return string[]
*/
protected function getMcrTablesToReset() {
return [];
}
/**
* @override MediaWikiTestCase::getSchemaOverrides
* @return array[]
*/
protected function getSchemaOverrides( IMaintainableDatabase $db ) {
$overrides = [
'scripts' => [],
'drop' => [],
'create' => [],
'alter' => [],
];
if ( $this->hasMcrTables( $db ) ) {
$overrides['drop'] = [ 'slots', 'content', 'slot_roles', 'content_models', ];
$overrides['scripts'][] = $this->getSqlPatchPath( $db, '/drop-mcr-tables', __DIR__ );
}
if ( !$this->hasPreMcrFields( $db ) ) {
$overrides['alter'][] = 'revision';
$overrides['scripts'][] = $this->getSqlPatchPath( $db, '/create-pre-mcr-fields', __DIR__ );
}
return $overrides;
}
}