jenkins-bot has submitted this change and it was merged.

Change subject: Make generating Parser test class names more robust
......................................................................


Make generating Parser test class names more robust

This includes the extension name, and it also does much
more stringent validation. In the (now rather unlikely)
event of a duplicate name, it will append a number.

This is important, as it is very confusing when this bug strikes.
There exists extensions like CharRangeSpan which will trigger this bug.

Bug: 42174
Change-Id: Idf14b4cbdb8ec103340d48855e0361acf707b101
---
M tests/phpunit/includes/parser/MediaWikiParserTest.php
1 file changed, 20 insertions(+), 6 deletions(-)

Approvals:
  Reedy: Looks good to me, approved
  Nemo bis: Looks good to me, but someone else must approve
  jenkins-bot: Verified



diff --git a/tests/phpunit/includes/parser/MediaWikiParserTest.php 
b/tests/phpunit/includes/parser/MediaWikiParserTest.php
index a450972..df891f5 100644
--- a/tests/phpunit/includes/parser/MediaWikiParserTest.php
+++ b/tests/phpunit/includes/parser/MediaWikiParserTest.php
@@ -83,14 +83,28 @@
                        . implode( ' ', $filesToTest ) );
 
                $suite = new PHPUnit_Framework_TestSuite;
+               $testList = array();
+               $counter = 0;
                foreach ( $filesToTest as $fileName ) {
-                       $testsName = basename( $fileName, '.txt' );
+                       // Call the highest level directory the extension name.
+                       // It may or may not actually be, but it should be close
+                       // enough to cause there to be separate names for 
different
+                       // things, which is good enough for our purposes.
+                       $extensionName = basename( dirname( $fileName ) );
+                       $testsName = $extensionName . '⁄' . basename( 
$fileName, '.txt' );
                        $escapedFileName = strtr( $fileName, array( "'" => 
"\\'", '\\' => '\\\\' ) );
-                       /* This used to be ucfirst( basename( dirname( 
$filename ) ) )
-                        * and then was ucfirst( basename( $filename, '.txt' )
-                        * but that didn't work with names like foo.tests.txt
-                        */
-                       $parserTestClassName = str_replace( '.', '_', ucfirst( 
$testsName ) );
+                       $parserTestClassName = ucfirst( $testsName );
+                       // Official spec for class names: 
http://php.net/manual/en/language.oop5.basic.php
+                       // Prepend 'ParserTest_' to be paranoid about it not 
starting with a number
+                       $parserTestClassName = 'ParserTest_' . preg_replace( 
'/[^a-zA-Z0-9_\x7f-\xff]/', '_', $parserTestClassName );
+                       if ( isset( $testList[$parserTestClassName] ) ) {
+                               // If a conflict happens, gives a very unclear 
fatal.
+                               // So as a last ditch effort to prevent that 
eventuality, if there
+                               // is a conflict, append a number.
+                               $counter++;
+                               $parserTestClassName .= $counter;
+                       }
+                       $testList[$parserTestClassName] = true;
                        $parserTestClassDefinition = <<<EOT
 /**
  * @group Database

-- 
To view, visit https://gerrit.wikimedia.org/r/67098
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: Idf14b4cbdb8ec103340d48855e0361acf707b101
Gerrit-PatchSet: 9
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Brian Wolff <[email protected]>
Gerrit-Reviewer: Aaron Schulz <[email protected]>
Gerrit-Reviewer: Addshore <[email protected]>
Gerrit-Reviewer: Brian Wolff <[email protected]>
Gerrit-Reviewer: Hashar <[email protected]>
Gerrit-Reviewer: Nemo bis <[email protected]>
Gerrit-Reviewer: Reedy <[email protected]>
Gerrit-Reviewer: Tim Starling <[email protected]>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to