wiki.techinc.nl/tests/parser/ParserTestResult.php
C. Scott Ananian a5a04f56bd Pass <Test,TestMode> as argument pair, deprecate old TestFileReader
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
2022-06-03 17:15:38 -04:00

51 lines
1.2 KiB
PHP

<?php
/**
* @file
*
* @copyright Copyright © 2013, Antoine Musso
* @copyright Copyright © 2013, Wikimedia Foundation Inc.
*/
use MediaWiki\Tests\TestMode as ParserTestMode;
use Wikimedia\Parsoid\ParserTests\Test as ParserTest;
/**
* Represent the result of a parser test.
*
* @since 1.22
*/
class ParserTestResult {
/** @var ParserTest The test info */
public $test;
/** @var ParserTestMode The test mode */
public $mode;
/** @var string Text that was expected */
public $expected;
/** @var string Actual text rendered */
public $actual;
/**
* @param ParserTest $test The test info class
* @param ParserTestMode $mode The test mode
* @param string $expected The normalized expected output
* @param string $actual The actual output
*/
public function __construct( $test, $mode, $expected, $actual ) {
$this->test = $test;
$this->mode = $mode;
$this->expected = $expected;
$this->actual = $actual;
}
/**
* Whether the test passed
* @return bool
*/
public function isSuccess() {
return $this->expected === $this->actual;
}
public function getDescription() {
return ( $this->test->comment ?? '' ) .
"{$this->test->testName} [{$this->mode}]";
}
}