We introduced a new type for "ParserTestMode" and then uniformly pass this around alongside the ParserTest object itself. (We started by using a string for the $mode but the "explicit changetree" mode requires more structured data. We *could* encode this in JSON just to keep the string type around, but it seems cleaner and more future proof to wrap this in a proper class type.) Removed the old TestFileReader wrapper class, which served only as a thunk to convert the new Test class into the same sort of array which the legacy parser test runner code expected. There's still some remaining ::testToArray() usage here for the TestRecorder framework, but that will be cleaned up in a future patch. Also updated the TestRecorder with stronger types: use the same <Test,TestMode> pair when invoking the TestRecorder, instead of the loosely typed array we'd used previously. Change-Id: Iec4c0c7972a655b4faccacc67bdc3ca66d4c163d
68 lines
1.8 KiB
PHP
68 lines
1.8 KiB
PHP
<?php
|
|
|
|
use MediaWiki\Tests\TestMode as ParserTestMode;
|
|
use PHPUnit\Framework\TestSuite;
|
|
use Wikimedia\Parsoid\ParserTests\TestFileReader;
|
|
use Wikimedia\ScopedCallback;
|
|
|
|
/**
|
|
* This is the suite class for running tests with the legacy parser
|
|
* within a single .txt source file.
|
|
* It is not invoked directly. Use --filter to select files, or
|
|
* use parserTests.php.
|
|
*/
|
|
class ParserTestFileSuite extends TestSuite {
|
|
use SuiteEventsTrait;
|
|
|
|
private $ptRunner;
|
|
private $ptFileName;
|
|
private $ptFileInfo;
|
|
|
|
/** @var ScopedCallback */
|
|
private $ptTeardownScope;
|
|
|
|
public function __construct( $runner, $name, $fileName ) {
|
|
parent::__construct( $name );
|
|
$this->ptRunner = $runner;
|
|
$this->ptFileName = $fileName;
|
|
try {
|
|
$this->ptFileInfo = TestFileReader::read( $this->ptFileName, static function ( $msg ) {
|
|
wfDeprecatedMsg( $msg, '1.35', false, false );
|
|
} );
|
|
} catch ( \Exception $e ) {
|
|
// Friendlier wrapping for any syntax errors that might occur.
|
|
throw new MWException(
|
|
$fileName . ': ' . $e->getMessage()
|
|
);
|
|
}
|
|
|
|
$skipMessage = $this->ptRunner->getFileSkipMessage(
|
|
true, /* legacy parser */
|
|
$this->ptFileInfo->fileOptions,
|
|
$fileName
|
|
);
|
|
// Don't bother doing anything else if a skip message is set.
|
|
if ( $skipMessage !== null ) {
|
|
return;
|
|
}
|
|
|
|
$mode = new ParserTestMode( 'legacy' );
|
|
foreach ( $this->ptFileInfo->testCases as $test ) {
|
|
$this->addTest( new ParserIntegrationTest(
|
|
$this->ptRunner, $fileName, $test, $mode, $skipMessage ),
|
|
[ 'Database', 'Parser', 'ParserTests' ] );
|
|
}
|
|
}
|
|
|
|
protected function setUp(): void {
|
|
$this->ptTeardownScope = $this->ptRunner->addArticles(
|
|
$this->ptFileInfo->articles
|
|
);
|
|
}
|
|
|
|
protected function tearDown(): void {
|
|
if ( $this->ptTeardownScope ) {
|
|
ScopedCallback::consume( $this->ptTeardownScope );
|
|
}
|
|
}
|
|
}
|