/**
* Called after each test
* @param string $test
+ * @param integer $subtest
* @param bool $result
*/
- public function record( $test, $result );
+ public function record( $test, $subtest, $result );
/**
* Called before finishing the test run
$this->success = 0;
}
- function record( $test, $result ) {
+ function record( $test, $subtest, $result ) {
$this->total++;
$this->success += ( $result ? 1 : 0 );
}
$this->prevRun = $this->db->selectField( 'testrun', 'MAX(tr_id)' );
}
- $this->results = array();
+ $this->results = [];
}
- function record( $test, $result ) {
- parent::record( $test, $result );
- $this->results[$test] = $result;
+ function getName( $test, $subtest ) {
+ if ( $subtest ) {
+ return "$test subtest #$subtest";
+ } else {
+ return $test;
+ }
+ }
+
+ function record( $test, $subtest, $result ) {
+ parent::record( $test, $subtest, $result );
+ $this->results[ $this->getName( $test, $subtest ) ] = $result;
}
function report() {
if ( $this->prevRun ) {
// f = fail, p = pass, n = nonexistent
// codes show before then after
- $table = array(
+ $table = [
'fp' => 'previously failing test(s) now PASSING! :)',
'pn' => 'previously PASSING test(s) removed o_O',
'np' => 'new PASSING test(s) :)',
'fn' => 'previously FAILING test(s) removed O_o',
'nf' => 'new FAILING test(s) :(',
'ff' => 'still FAILING test(s) :(',
- );
+ ];
- $prevResults = array();
+ $prevResults = [];
- $res = $this->db->select( 'testitem', array( 'ti_name', 'ti_success' ),
- array( 'ti_run' => $this->prevRun ), __METHOD__ );
+ $res = $this->db->select( 'testitem', [ 'ti_name', 'ti_success' ],
+ [ 'ti_run' => $this->prevRun ], __METHOD__ );
foreach ( $res as $row ) {
if ( !$this->parent->regex
$combined = array_keys( $this->results + $prevResults );
# Determine breakdown by change type
- $breakdown = array();
+ $breakdown = [];
foreach ( $combined as $test ) {
if ( !isset( $prevResults[$test] ) ) {
$before = 'n';
if ( $after == 'n' ) {
$changedRun = $this->db->selectField( 'testitem',
'MIN(ti_run)',
- array( 'ti_name' => $testname ),
+ [ 'ti_name' => $testname ],
__METHOD__ );
$appear = $this->db->selectRow( 'testrun',
- array( 'tr_date', 'tr_mw_version' ),
- array( 'tr_id' => $changedRun ),
+ [ 'tr_date', 'tr_mw_version' ],
+ [ 'tr_id' => $changedRun ],
__METHOD__ );
return "First recorded appearance: "
// Otherwise, this test has previous recorded results.
// See when this test last had a different result to what we're seeing now.
- $conds = array(
+ $conds = [
'ti_name' => $testname,
- 'ti_success' => ( $after == 'f' ? "1" : "0" ) );
+ 'ti_success' => ( $after == 'f' ? "1" : "0" ) ];
if ( $this->curRun ) {
$conds[] = "ti_run != " . $this->db->addQuotes( $this->curRun );
// (i.e. it used to work, but now doesn't; or used to fail, but is now fixed.)
// In this situation, give as much info as we can as to when it changed status.
$pre = $this->db->selectRow( 'testrun',
- array( 'tr_date', 'tr_mw_version' ),
- array( 'tr_id' => $changedRun ),
+ [ 'tr_date', 'tr_mw_version' ],
+ [ 'tr_id' => $changedRun ],
__METHOD__ );
$post = $this->db->selectRow( 'testrun',
- array( 'tr_date', 'tr_mw_version' ),
- array( "tr_id > " . $this->db->addQuotes( $changedRun ) ),
+ [ 'tr_date', 'tr_mw_version' ],
+ [ "tr_id > " . $this->db->addQuotes( $changedRun ) ],
__METHOD__,
- array( "LIMIT" => 1, "ORDER BY" => 'tr_id' )
+ [ "LIMIT" => 1, "ORDER BY" => 'tr_id' ]
);
if ( $post ) {
}
/**
- * Commit transaction and clean up for result recording
+ * Close the DB connection
*/
function end() {
- $this->lb->commitMasterChanges();
$this->lb->closeAll();
parent::end();
}
parent::start();
$this->db->insert( 'testrun',
- array(
+ [
'tr_date' => $this->db->timestamp(),
'tr_mw_version' => $this->version,
'tr_php_version' => PHP_VERSION,
'tr_db_version' => $this->db->getServerVersion(),
'tr_uname' => php_uname()
- ),
+ ],
__METHOD__ );
if ( $this->db->getType() === 'postgres' ) {
$this->curRun = $this->db->currentSequenceValue( 'testrun_id_seq' );
* @param string $test
* @param bool $result
*/
- function record( $test, $result ) {
- parent::record( $test, $result );
+ function record( $test, $subtest, $result ) {
+ parent::record( $test, $subtest, $result );
$this->db->insert( 'testitem',
- array(
+ [
'ti_run' => $this->curRun,
- 'ti_name' => $test,
+ 'ti_name' => $this->getName( $test, $subtest ),
'ti_success' => $result ? 1 : 0,
- ),
+ ],
__METHOD__ );
}
+
+ /**
+ * Commit transaction and clean up for result recording
+ */
+ function end() {
+ $this->db->commit( __METHOD__ );
+ parent::end();
+ }
}
class TestFileIterator implements Iterator {
private $test;
private $section = null;
/** String|null: current test section being analyzed */
- private $sectionData = array();
+ private $sectionData = [];
private $lineNum;
private $eof;
# Create a fake parser tests which never run anything unless
function setupCurrentTest() {
// "input" and "result" are old section names allowed
// for backwards-compatibility.
- $input = $this->checkSection( array( 'wikitext', 'input' ), false );
- $result = $this->checkSection( array( 'html/php', 'html/*', 'html', 'result' ), false );
+ $input = $this->checkSection( [ 'wikitext', 'input' ], false );
+ $result = $this->checkSection( [ 'html/php', 'html/*', 'html', 'result' ], false );
// some tests have "with tidy" and "without tidy" variants
- $tidy = $this->checkSection( array( 'html/php+tidy', 'html+tidy' ), false );
+ $tidy = $this->checkSection( [ 'html/php+tidy', 'html+tidy' ], false );
if ( $tidy != false ) {
if ( $this->nextSubTest == 0 ) {
if ( $result != false ) {
throw new MWException( "Problem running requested parser hook from the test file" );
}
- $this->test = array(
+ $this->test = [
'test' => ParserTest::chomp( $this->sectionData['test'] ),
+ 'subtest' => $this->nextSubTest,
'input' => ParserTest::chomp( $this->sectionData[$input] ),
'result' => ParserTest::chomp( $this->sectionData[$result] ),
'options' => ParserTest::chomp( $this->sectionData['options'] ),
'config' => ParserTest::chomp( $this->sectionData['config'] ),
- );
+ ];
if ( $tidy != false ) {
$this->test['options'] .= " tidy";
}
while ( false !== ( $line = fgets( $this->fh ) ) ) {
$this->lineNum++;
- $matches = array();
+ $matches = [];
if ( preg_match( '/^!!\s*(\S+)/', $line, $matches ) ) {
$this->section = strtolower( $matches[1] );
* Clear section name and its data
*/
private function clearSection() {
- $this->sectionData = array();
+ $this->sectionData = [];
$this->section = null;
}
throw new MWException( __METHOD__ . " can not verify a null section!\n" );
}
if ( !is_array( $tokens ) ) {
- $tokens = array( $tokens );
+ $tokens = [ $tokens ];
}
if ( count( $tokens ) == 0 ) {
throw new MWException( __METHOD__ . " can not verify zero sections!\n" );
) );
}
- $tokens = array_values( $tokens );
- return $tokens[0];
+ return array_values( $tokens )[0];
+ }
+}
+
+/**
+ * An iterator for use as a phpunit data provider. Provides the test arguments
+ * in the order expected by NewParserTest::testParserTest().
+ */
+class TestFileDataProvider extends TestFileIterator {
+ function current() {
+ $test = parent::current();
+ if ( $test ) {
+ return [
+ $test['test'],
+ $test['input'],
+ $test['result'],
+ $test['options'],
+ $test['config'],
+ ];
+ } else {
+ return $test;
+ }
}
}
* Call to this will erase any hooks function that were pending.
*/
public function reset() {
- $this->hooks = array();
- $this->fnHooks = array();
- $this->transparentHooks = array();
+ $this->hooks = [];
+ $this->fnHooks = [];
+ $this->transparentHooks = [];
}
/**
class_exists( 'tidy' ) && !wfIsHHVM();
$this->externalTidy = is_executable( $wgTidyBin ) ||
- Installer::locateExecutableInDefaultPaths( array( $wgTidyBin ) )
+ Installer::locateExecutableInDefaultPaths( [ $wgTidyBin ] )
!== false;
}