wiki.techinc.nl/tests/phpunit/suites/ParserTestFileSuite.php
C. Scott Ananian 02ec9de651 Parser tests: Update TestFileReader to the latest reader from Parsoid
This replaces the 'requirements' from parser tests (hooks and
functionhooks) with a more flexible 'options' clause to allow
additional file-level requirements/options to support running parser
tests in multiple modes.  (For example, with the legacy parser or in
one of two parsoid modes.)

Bug: T254181
Depends-On: I636bd1f2c8aee327acbbd1636e2ac76355f1d80e
Change-Id: I58373d135c3a804f4ce9967112c338435f5cd4b6
2020-12-14 18:49:11 -05:00

48 lines
1.3 KiB
PHP

<?php
use PHPUnit\Framework\TestSuite;
/**
* This is the suite class for running tests 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;
public function __construct( $runner, $name, $fileName ) {
parent::__construct( $name );
$this->ptRunner = $runner;
$this->ptFileName = $fileName;
try {
$this->ptFileInfo = TestFileReader::read( $this->ptFileName );
} catch ( \Exception $e ) {
// Friendlier wrapping for any syntax errors that might occur.
throw new MWException(
$fileName . ': ' . $e->getMessage()
);
}
if ( !$this->ptRunner->meetsRequirements( $this->ptFileInfo['fileOptions']['requirements'] ?? [] ) ) {
$skipMessage = 'required extension not enabled';
} else {
$skipMessage = null;
}
foreach ( $this->ptFileInfo['tests'] as $test ) {
$this->addTest( new ParserIntegrationTest( $runner, $fileName, $test, $skipMessage ),
[ 'Database', 'Parser', 'ParserTests' ] );
}
}
protected function setUp() : void {
$this->ptRunner->addArticles( $this->ptFileInfo[ 'articles'] );
}
protected function tearDown() : void {
$this->ptRunner->cleanupArticles( $this->ptFileInfo[ 'articles'] );
}
}