wiki.techinc.nl/tests/phpunit/suites/ParserTestFileSuite.php
C. Scott Ananian ce663741bc Allow independent parser test files to (re)define articles w/ the same names
It leads to surprising results when the definitions in one parser test
file leak into all the others.  This can cause spurious test failures
when you happen to have two extensions which define conflicting
article fixtures, and prevents you from using parser tests to test
patches like I50ff8a7b6be95901ebb14ffbe64940a0f499cfac, where you
deliberately want to set up and test two different definitions for the
same template name.

Change-Id: I958c6305a95ca32418d83b7f33f7c180a3b370cd
2020-09-15 16:15:44 -04: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['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'] );
}
}