wiki.techinc.nl/tests/phpunit/suites/ParserTestFileSuite.php
C. Scott Ananian 5a49745add tests/parser/TestMode: move parser test helper class to parsoid library
Depends-On: I6a653889afd42fefb61daefd8ac842107dce8759
Depends-On: I73f320dfb03e5c26971a7bc36564021d2c9f3695
Change-Id: Id3e44a5b419d7f6917819e72c046f94a3a2286fe
2022-08-16 16:26:25 -04:00

68 lines
1.8 KiB
PHP

<?php
use PHPUnit\Framework\TestSuite;
use Wikimedia\Parsoid\ParserTests\TestFileReader;
use Wikimedia\Parsoid\ParserTests\TestMode as ParserTestMode;
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 );
}
}
}