Skip to content

Commit 0c75757

Browse files
committed
add unit test for cli output
1 parent ec897dd commit 0c75757

File tree

2 files changed

+58
-0
lines changed

2 files changed

+58
-0
lines changed

tests/Diff/Renderer/Text/TextRenderersTest.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,4 +67,20 @@ public function testUnified()
6767

6868
$this->assertStringEqualsFile('tests/resources/textUnified.txt', $result);
6969
}
70+
71+
public function testUnifiedCli()
72+
{
73+
$diff = new Diff(
74+
file_get_contents('tests/resources/a.txt'),
75+
file_get_contents('tests/resources/b.txt')
76+
);
77+
78+
$renderer = new Diff\Renderer\Text\UnifiedCli();
79+
$result = $diff->render($renderer);
80+
if ($this->genOutputFiles) {
81+
file_put_contents('textUnifiedCli.txt', $result);
82+
}
83+
$this->assertStringEqualsFile('tests/resources/ab.diff', $result);
84+
}
7085
}
86+

tests/resources/ab.diff

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
@@ -1,22 +1,22 @@
2+
<html>
3+
<head>
4+
<meta http-equiv="Content-type" content="text/html; charset=utf-8"/>
5+
- <title>Hello World!</title>
6+
+ <title>Hello You!</title>
7+
</head>
8+
<body>
9+
<h1>This is demo content to show features of the php-diff package.</h1>
10+
- <h2>This line is removed from version2.</h2>
11+
<h2>This line is the same for both versions.</h2>
12+
- <h2>This line has inline differences between both versions.</h2>
13+
+ <h2>This line has differences between both versions.</h2>
14+
<h2>This line is the same for both versions.</h2>
15+
- <h2>This line also has inline differences between both versions.</h2>
16+
+ <h2>This line also has InLine differences between both versions.</h2>
17+
<h2>This line is the same for both versions.</h2>
18+
+ <h2>This line is added to version2.</h2>
19+
20+
<p>
21+
It's also compatible with multibyte characters (like Chinese and emoji) as shown below:
22+
- 另外我覺得那個評價的白色櫃子有點沒有必要欸。外觀我就不說了 ,怎麼連空間都那麼狹隘。不過倒是從這個地方看出所謂的“改革”
23+
- Do you know what "金槍魚罐頭" means in Chinese?
24+
- 🍏🍎🙂
25+
+ 另外我覺得那個評鑑的白色櫃子有點沒有必要欸。外觀我就不說了 ,怎麼連空間都那麼狹隘。不過倒是從這個地方看出所謂的“改革”
26+
+ Do you know what "魚の缶詰" means in Chinese?
27+
+ 🍎🍏🙂
28+
</p>
29+
30+
<p>Just some lines to demonstrate the collapsing of a block of lines which are the same in both versions.</p>
31+
@@ -25,9 +25,9 @@
32+
<p>Just some lines to demonstrate the collapsing of a block of lines which are the same in both versions.</p>
33+
<p>Just some lines to demonstrate the collapsing of a block of lines which are the same in both versions.</p>
34+
<p>Just some lines to demonstrate the collapsing of a block of lines which are the same in both versions.</p>
35+
- <h2>This line also has inline differences between both versions. It's the whitespace in front.</h2>
36+
+ <h2>This line also has inline differences between both versions. It's the whitespace in front.</h2>
37+
<h2>This line is the same for both versions.</h2>
38+
- <h2>This line also has inline differences between both versions.</h2>
39+
+ <h2>This line also has inline differences between both versions!</h2>
40+
</body>
41+
</html>
42+

0 commit comments

Comments
 (0)