Merge "Make dataProvider in EnWikiFormulaeTest static"

This commit is contained in:
jenkins-bot 2023-10-22 13:24:30 +00:00 committed by Gerrit Code Review
commit 30c156a0a8

View file

@ -16,10 +16,11 @@ use MediaWikiUnitTestCase;
* @group Stub * @group Stub
*/ */
class EnWikiFormulaeTest extends MediaWikiUnitTestCase { class EnWikiFormulaeTest extends MediaWikiUnitTestCase {
private $ACTIVE = true; # indicate whether this test is active /** indicate whether this test is active */
private $FILENAME = "en-wiki-formulae-good.json"; private const ACTIVE = true;
private $REF_FILENAME = "en-wiki-formulae-good-reference.json"; private const FILENAME = "en-wiki-formulae-good.json";
private $CHUNKSIZE = 1000; private const REF_FILENAME = "en-wiki-formulae-good-reference.json";
private const CHUNKSIZE = 1000;
/** /**
* Reads the json file to an object * Reads the json file to an object
@ -27,7 +28,7 @@ class EnWikiFormulaeTest extends MediaWikiUnitTestCase {
* @throws InvalidArgumentException File with testcases does not exist. * @throws InvalidArgumentException File with testcases does not exist.
* @return array json with testcases * @return array json with testcases
*/ */
private function getJSON( $filePath ): array { private static function getJSON( $filePath ): array {
if ( !file_exists( $filePath ) ) { if ( !file_exists( $filePath ) ) {
throw new InvalidArgumentException( "No testfile found at specified path: " . $filePath ); throw new InvalidArgumentException( "No testfile found at specified path: " . $filePath );
} }
@ -36,13 +37,13 @@ class EnWikiFormulaeTest extends MediaWikiUnitTestCase {
return $json; return $json;
} }
public function provideTestCases(): \Generator { public static function provideTestCases(): \Generator {
$group = []; $group = [];
$groupNo = 1; $groupNo = 1;
$references = $this->getJSON( __DIR__ . '/' . $this->REF_FILENAME ); $references = self::getJSON( __DIR__ . '/' . self::REF_FILENAME );
foreach ( $this->getJSON( __DIR__ . '/' . $this->FILENAME ) as $key => $elem ) { foreach ( self::getJSON( __DIR__ . '/' . self::FILENAME ) as $key => $elem ) {
$group[$key] = [ $elem , $references[ $key ] ]; $group[$key] = [ $elem , $references[ $key ] ];
if ( count( $group ) >= $this->CHUNKSIZE ) { if ( count( $group ) >= self::CHUNKSIZE ) {
yield "Group $groupNo" => [ $group ]; yield "Group $groupNo" => [ $group ];
$groupNo++; $groupNo++;
$group = []; $group = [];
@ -57,7 +58,7 @@ class EnWikiFormulaeTest extends MediaWikiUnitTestCase {
* @dataProvider provideTestCases * @dataProvider provideTestCases
*/ */
public function testRunCases( $testcase ) { public function testRunCases( $testcase ) {
if ( !$this->ACTIVE ) { if ( !$this::ACTIVE ) {
$this->markTestSkipped( "All MediaWiki formulae en test not active and skipped. This is expected." ); $this->markTestSkipped( "All MediaWiki formulae en test not active and skipped. This is expected." );
} }