Skip to content
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

DOMNodeComparator::nodeToText Refactoring #56

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

Ovsyanka
Copy link
Contributor

  1. I removed

    $document->formatOutput = true;
    $document->normalizeDocument();

Because the unit-tests not failed after that and I don't see why it needed.
2. I removed a lot of checks instanceof DOMDocument because in fact there is always DOMDocument in the $node variable in case if canonicalize is true (and it is always true).
3. I removed $canonicalize because in fact it is always true and the unused argument just make the code maintenance harder. Especially without corresponding unit-tests.

1. I removed

    $document->formatOutput = true;
    $document->normalizeDocument();

Because the unit-tests not failed after that and I don't see why it needed.
2. I removed a lot of checks instanceof DOMDocument because in fact there is always DOMDocument in the $node variable in case if canonicalize is true (and it is always true).
3. I removed $canonicalize because in fact it is always true and the unused argument just make the code maintenance harder. Especially without corresponding unit-tests.
@codecov-io
Copy link

codecov-io commented May 23, 2018

Codecov Report

Merging #56 into master will increase coverage by 0.48%.
The diff coverage is 22.22%.

Impacted file tree graph

@@             Coverage Diff              @@
##             master      #56      +/-   ##
============================================
+ Coverage     79.14%   79.62%   +0.48%     
+ Complexity      122      120       -2     
============================================
  Files            15       15              
  Lines           326      324       -2     
============================================
  Hits            258      258              
+ Misses           68       66       -2
Impacted Files Coverage Δ Complexity Δ
src/DOMNodeComparator.php 63.63% <22.22%> (+5.3%) 8 <3> (-2) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 48a0188...133b441. Read the comment docs.

@sebastianbergmann
Copy link
Owner

$canonicalize is an optional parameter of PHPUnit\Framework\TestCase::assertEquals() (see https://github.com/sebastianbergmann/phpunit/blob/master/src/Framework/Assert.php#L546). From there, it is passed to PHPUnit\Framework\Constraint\IsEqual (see https://github.com/sebastianbergmann/phpunit/blob/master/src/Framework/Constraint/IsEqual.php#L56). Finally, it is passed to the Comparator object in https://github.com/sebastianbergmann/phpunit/blob/master/src/Framework/Constraint/IsEqual.php#L102.

SebastianBergmann\Comparator\DOMNodeComparator::assertEquals() should pass $canonicalize on to SebastianBergmann\Comparator\DOMNodeComparator::nodeToText() -- but it does not. So, indeed, inside that private method it is always true.

I think that $canonicalize should be passed to nodeToText(). I did not remember the details about why it is not passed on until I did some digging in the Git history:

sebastianbergmann/phpunit#1236 (comment)

At least I agree with myself from four years ago :-)

I think the right thing to do here is to release a new major version of this component (that passes $canonicalize to nodeToText()) alongside PHPUnit 8.0. This will be backward compatibility break.

Maybe feeec2d needs to be reverted until that time, too.

@sebastianbergmann
Copy link
Owner

$document->formatOutput = true; and $document->normalizeDocument(); are needed to make the output in case of a failure readable.

@Ovsyanka
Copy link
Contributor Author

I investigated that history too, but decided to not interfere with that at this point.

I think that $canonicalize should be passed to nodeToText()

I believe I agree with you that it is point. But I think it is a good idea to aplly that refactoring untill we solve the issue whith $canonicalize passing in the next major version. Because with that refactoring it will be simpler to solve issue #21 and maybe some other if they would appear.

Besides that I think that it is complex question how the DOMComparator should act with different arguments and needs some discussions or, at leat, better documentaion. I haven't good understanding about intent of $canonicalize=false and $ignoreCase=true at this moment. I believe that $canonicalize=true should made nesessary changes in the xml to make it comparable as xml structure and it is the only thing I expect from DOMNodeComparator. But what should $canonicalize=false do?

And I don't see the intent of $ignoreCase=true. It is contradictory with the $canonicalize=true because <A /> and <a /> will be considered as equal but in terms of xml structure it is not true.

$document->formatOutput = true; and $document->normalizeDocument(); are needed to make the output in case of a failure readable.

Could you give some examples? I am sure that there should be tests for that and I could write some, but I didn't get the issue yet.

@Ovsyanka
Copy link
Contributor Author

Ovsyanka commented May 23, 2018

Maybe feeec2d needs to be reverted until that time, too.

Personally I am not sure what I think about that. The error was implemented in the c42cbbe and I don't know how much users relay on the new behavior. In my case I updated from the PHPUnit5 to the PHPUnit6 and instantly faced with that issue (uexpected case conversion) and came here. I saw existed PR #53 about that and decided to wait.

So, my point is - maybe it is a good idea to leave this PR #53 merged because that was obviously an error and in case you didn't get issues about that - the most of users just didn't notice that error and they will not notice the fix, but it is better to have fixed code.

On other hand, if it is like this from start of the current major version - maybe you shouldn't change it. If someone was hurted about that - he wrote the workaround I believe. I did =)

$this->assertEquals($expectedDom, $xmlDom, "", 0.0, 10, true, true);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants