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.
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:
$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.