summaryrefslogtreecommitdiff
path: root/extensions/LocalisationUpdate/tests/tokenTest.php
diff options
context:
space:
mode:
Diffstat (limited to 'extensions/LocalisationUpdate/tests/tokenTest.php')
-rw-r--r--extensions/LocalisationUpdate/tests/tokenTest.php61
1 files changed, 35 insertions, 26 deletions
diff --git a/extensions/LocalisationUpdate/tests/tokenTest.php b/extensions/LocalisationUpdate/tests/tokenTest.php
index 1112313c..2b71cc46 100644
--- a/extensions/LocalisationUpdate/tests/tokenTest.php
+++ b/extensions/LocalisationUpdate/tests/tokenTest.php
@@ -4,47 +4,53 @@ $IP = strval( getenv( 'MW_INSTALL_PATH' ) ) !== ''
? getenv( 'MW_INSTALL_PATH' )
: realpath( dirname( __FILE__ ) . "/../../../" );
-require_once( "$IP/maintenance/commandLine.inc" );
+require_once "$IP/maintenance/commandLine.inc";
function evalExtractArray( $php, $varname ) {
eval( $php );
- return @$$varname;
+ wfSuppressWarnings();
+
+ return $$varname;
+ wfRestoreWarnings();
}
function confExtractArray( $php, $varname ) {
try {
- $ce = new ConfEditor("<?php $php");
+ $ce = new ConfEditor( "<?php $php" );
$vars = $ce->getVars();
- $retval = @$vars[$varname];
- } catch( Exception $e ) {
+ wfSuppressWarnings();
+ $retval = $vars[$varname];
+ wfRestoreWarnings();
+ } catch ( Exception $e ) {
print $e . "\n";
$retval = null;
}
+
return $retval;
}
function quickTokenExtractArray( $php, $varname ) {
- $reader = new QuickArrayReader("<?php $php");
+ $reader = new QuickArrayReader( "<?php $php" );
+
return $reader->getVar( $varname );
}
-
-if( count( $args ) ) {
+if ( count( $args ) ) {
$sources = $args;
} else {
$sources =
array_merge(
- glob("$IP/extensions/*/*.i18n.php"),
- glob("$IP/languages/messages/Messages*.php") );
+ glob( "$IP/extensions/*/*.i18n.php" ),
+ glob( "$IP/languages/messages/Messages*.php" ) );
}
-foreach( $sources as $sourceFile ) {
+foreach ( $sources as $sourceFile ) {
$rel = basename( $sourceFile );
$out = str_replace( '/', '-', $rel );
$sourceData = file_get_contents( $sourceFile );
- if( preg_match( '!extensions/!', $sourceFile ) ) {
+ if ( preg_match( '!extensions/!', $sourceFile ) ) {
$sourceData = LocalisationUpdate::cleanupExtensionFile( $sourceData );
$items = 'langs';
} else {
@@ -54,30 +60,33 @@ foreach( $sources as $sourceFile ) {
file_put_contents( "$out.txt", $sourceData );
- $start = microtime(true);
+ $start = microtime( true );
$eval = evalExtractArray( $sourceData, 'messages' );
- $deltaEval = microtime(true) - $start;
+ $deltaEval = microtime( true ) - $start;
- $start = microtime(true);
+ $start = microtime( true );
$quick = quickTokenExtractArray( $sourceData, 'messages' );
- $deltaQuick = microtime(true) - $start;
+ $deltaQuick = microtime( true ) - $start;
- $start = microtime(true);
+ $start = microtime( true );
$token = confExtractArray( $sourceData, 'messages' );
- $deltaToken = microtime(true) - $start;
+ $deltaToken = microtime( true ) - $start;
- $hashEval = md5(serialize($eval));
- $hashToken = md5(serialize($token));
- $hashQuick = md5(serialize($quick));
- $countEval = count( (array)$eval);
+ $hashEval = md5( serialize( $eval ) );
+ $hashToken = md5( serialize( $token ) );
+ $hashQuick = md5( serialize( $quick ) );
+ $countEval = count( (array)$eval );
$countToken = count( (array)$token );
$countQuick = count( (array)$quick );
- printf( "%s %s %d $items - %0.1fms - eval\n", $rel, $hashEval, $countEval, $deltaEval * 1000 );
- printf( "%s %s %d $items - %0.1fms - QuickArrayReader\n", $rel, $hashQuick, $countQuick, $deltaQuick * 1000 );
- printf( "%s %s %d $items - %0.1fms - ConfEditor\n", $rel, $hashToken, $countToken, $deltaToken * 1000 );
+ printf( "%s %s %d $items - %0.1fms - eval\n",
+ $rel, $hashEval, $countEval, $deltaEval * 1000 );
+ printf( "%s %s %d $items - %0.1fms - QuickArrayReader\n",
+ $rel, $hashQuick, $countQuick, $deltaQuick * 1000 );
+ printf( "%s %s %d $items - %0.1fms - ConfEditor\n",
+ $rel, $hashToken, $countToken, $deltaToken * 1000 );
- if( $hashEval !== $hashToken || $hashEval !== $hashQuick ) {
+ if ( $hashEval !== $hashToken || $hashEval !== $hashQuick ) {
echo "FAILED on $rel\n";
file_put_contents( "$out-eval.txt", var_export( $eval, true ) );
file_put_contents( "$out-token.txt", var_export( $token, true ) );