-
Notifications
You must be signed in to change notification settings - Fork 98
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Command line tools for XML sync testing between languages #222
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,71 @@ | ||||||||||||||||||
<?php /* | ||||||||||||||||||
+----------------------------------------------------------------------+ | ||||||||||||||||||
| Copyright (c) 1997-2025 The PHP Group | | ||||||||||||||||||
+----------------------------------------------------------------------+ | ||||||||||||||||||
| This source file is subject to version 3.01 of the PHP license, | | ||||||||||||||||||
| that is bundled with this package in the file LICENSE, and is | | ||||||||||||||||||
| available through the world-wide-web at the following url: | | ||||||||||||||||||
| https://www.php.net/license/3_01.txt. | | ||||||||||||||||||
| If you did not receive a copy of the PHP license and are unable to | | ||||||||||||||||||
| obtain it through the world-wide-web, please send a note to | | ||||||||||||||||||
| [email protected], so we can mail you a copy immediately. | | ||||||||||||||||||
+----------------------------------------------------------------------+ | ||||||||||||||||||
| Authors: André L F S Bacci <ae php.net> | | ||||||||||||||||||
+----------------------------------------------------------------------+ | ||||||||||||||||||
|
||||||||||||||||||
# Description | ||||||||||||||||||
|
||||||||||||||||||
Compare processing instructions usage between two XML files. */ | ||||||||||||||||||
|
||||||||||||||||||
require_once __DIR__ . '/libqa/all.php'; | ||||||||||||||||||
|
||||||||||||||||||
$argv = new ArgvParser( $argv ); | ||||||||||||||||||
$ignore = new OutputIgnore( $argv ); // may exit. | ||||||||||||||||||
$argv->complete(); | ||||||||||||||||||
|
||||||||||||||||||
$list = SyncFileList::load(); | ||||||||||||||||||
|
||||||||||||||||||
foreach ( $list as $file ) | ||||||||||||||||||
{ | ||||||||||||||||||
$source = $file->sourceDir . '/' . $file->file; | ||||||||||||||||||
$target = $file->targetDir . '/' . $file->file; | ||||||||||||||||||
$output = new OutputBuffer( "# qaxml.p" , $target , $ignore ); | ||||||||||||||||||
|
||||||||||||||||||
[ $s , $_ , $_ ] = XmlFrag::loadXmlFragmentFile( $source ); | ||||||||||||||||||
[ $t , $_ , $_ ] = XmlFrag::loadXmlFragmentFile( $target ); | ||||||||||||||||||
|
||||||||||||||||||
$s = XmlFrag::listNodes( $s , XML_PI_NODE ); | ||||||||||||||||||
$t = XmlFrag::listNodes( $t , XML_PI_NODE ); | ||||||||||||||||||
Comment on lines
+37
to
+38
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Suggested change
Please don't use single-character variable names. |
||||||||||||||||||
|
||||||||||||||||||
$s = extractPiData( $s ); | ||||||||||||||||||
$t = extractPiData( $t ); | ||||||||||||||||||
|
||||||||||||||||||
if ( implode( "\n" , $s ) == implode( "\n" , $t ) ) | ||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Shouldn't this be |
||||||||||||||||||
continue; | ||||||||||||||||||
|
||||||||||||||||||
$sideCount = array(); | ||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||
|
||||||||||||||||||
foreach( $s as $v ) | ||||||||||||||||||
$sideCount[$v] = [ 0 , 0 ]; | ||||||||||||||||||
foreach( $t as $v ) | ||||||||||||||||||
Comment on lines
+48
to
+50
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't understand this coding style. Usually it would be something like:
Suggested change
|
||||||||||||||||||
$sideCount[$v] = [ 0 , 0 ]; | ||||||||||||||||||
|
||||||||||||||||||
foreach( $s as $v ) | ||||||||||||||||||
$sideCount[$v][0] += 1; | ||||||||||||||||||
foreach( $t as $v ) | ||||||||||||||||||
$sideCount[$v][1] += 1; | ||||||||||||||||||
|
||||||||||||||||||
foreach( $sideCount as $k => $v ) | ||||||||||||||||||
if ( $v[0] != $v[1] ) | ||||||||||||||||||
$output->addDiff( $k , $v[0] , $v[1] ); | ||||||||||||||||||
|
||||||||||||||||||
$output->print(); | ||||||||||||||||||
} | ||||||||||||||||||
|
||||||||||||||||||
function extractPiData( array $list ) | ||||||||||||||||||
{ | ||||||||||||||||||
$ret = array(); | ||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||
foreach( $list as $elem ) | ||||||||||||||||||
$ret[] = "{$elem->target} {$elem->data}"; | ||||||||||||||||||
return $ret; | ||||||||||||||||||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why are you reusing the variable
$_
twice? It's just going to overwrite it. And I don't think you are actually using this variable anywhere so why assign it at all?