The Artima Developer Community
Sponsored Link

PHP Buzz Forum
Visualizing Text Differences in PHPUnit 3

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
Sebastian Bergmann

Posts: 313
Nickname: sbergmann
Registered: Sep, 2004

Sebastian Bergmann is the developer of PHPUnit.
Visualizing Text Differences in PHPUnit 3 Posted: Aug 23, 2006 8:04 AM
Reply to this message Reply

This post originated from an RSS feed registered with PHP Buzz by Sebastian Bergmann.
Original Post: Visualizing Text Differences in PHPUnit 3
Feed Title: Sebastian Bergmann
Feed URL: http://sebastian-bergmann.de/
Feed Description: Geek by nature, PHP by choice.
Latest PHP Buzz Posts
Latest PHP Buzz Posts by Sebastian Bergmann
Latest Posts From Sebastian Bergmann

Advertisement
A long-standing feature request for PHPUnit has been the generation of a real diff between strings that span multiple lines.

Ideally this would be done by implementing the diff algorithm in PHP. But since Derick needed a working solution quickly, the two of us came up with a "hack": we just use GNU diff and invoke the diff command via shell_exec(). Let us look at an example:
<?php
class TextComparisonTest extends PHPUnit_Framework_TestCase {
    public function testTextComparison() {
        $expected = "<html>
  <head>
    <title>Foo</title>
  </head>
  <body>
    Foo
  </body>
</html>
";
 
        $actual = "<html>
  <head>
    <title>Foo</title>
  </head>
  <body>
    Bar
  </body>
</html>
";
 
        $this->assertEquals($expected, $actual);
    }
}
?>
The above test will give the following result:
PHPUnit 3.0.0 by Sebastian Bergmann.

F

Time: 00:00
There was 1 failure:
1) testTextComparison(TextComparisonTest)
failed asserting that <text> is equal to <text>
--- Expected
+++ Actual
@@ -3,6 +3,6 @@
     <title>Foo</title>
   </head>
   <body>
-    Foo
+    Bar
   </body>
 </html>

/home/sb/TextComparisonTest.php:24

FAILURES!
Tests: 1, Failures: 1.
I would appreciate it if someone would provide with me a PHP implementation of the diff algorithm that I can use for this. I know that there is a package called Text_Diff in PEAR, but that is more than I need.

Read: Visualizing Text Differences in PHPUnit 3

Topic: WordPress Translator Plugin Update Previous Topic   Next Topic Topic: Introduction to PHPUnit on A/R/T

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use