Skip to content

Commit 8793911

Browse files
authored
Merge pull request #46 from JBlond/cli-unittest
Cli unittest
2 parents ec897dd + 7ec0dbb commit 8793911

File tree

3 files changed

+79
-0
lines changed

3 files changed

+79
-0
lines changed

tests/Diff/Renderer/Html/HtmlRenderersTest.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ public function __construct($name = null, array $data = [], $dataName = '')
3737
parent::__construct($name, $data, $dataName);
3838
}
3939

40+
/**
41+
* @covers \jblond\Diff\Renderer\Html\SideBySide
42+
*/
4043
public function testSideBySide()
4144
{
4245
$diff = new Diff(
@@ -53,6 +56,9 @@ public function testSideBySide()
5356
$this->assertStringEqualsFile('tests/resources/htmlSideBySide.txt', $result);
5457
}
5558

59+
/**
60+
* @covers \jblond\Diff\Renderer\Html\Inline
61+
*/
5662
public function testInline()
5763
{
5864
$diff = new Diff(
@@ -69,6 +75,9 @@ public function testInline()
6975
$this->assertStringEqualsFile('tests/resources/htmlInline.txt', $result);
7076
}
7177

78+
/**
79+
* @covers \jblond\Diff\Renderer\Html\Unified
80+
*/
7281
public function testUnified()
7382
{
7483
$diff = new Diff(

tests/Diff/Renderer/Text/TextRenderersTest.php

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,10 @@ public function __construct($name = null, array $data = [], $dataName = '')
3636
parent::__construct($name, $data, $dataName);
3737
}
3838

39+
/**
40+
* Test context
41+
* @covers \jblond\Diff\Renderer\Text\Context
42+
*/
3943
public function testContext()
4044
{
4145
$diff = new Diff(
@@ -52,6 +56,10 @@ public function testContext()
5256
$this->assertStringEqualsFile('tests/resources/textContext.txt', $result);
5357
}
5458

59+
/**
60+
* Test Unified
61+
* @covers \jblond\Diff\Renderer\Text\Unified
62+
*/
5563
public function testUnified()
5664
{
5765
$diff = new Diff(
@@ -67,4 +75,24 @@ public function testUnified()
6775

6876
$this->assertStringEqualsFile('tests/resources/textUnified.txt', $result);
6977
}
78+
79+
/**
80+
* Test Unified Cli
81+
* @covers \jblond\Diff\Renderer\Text\UnifiedCli
82+
*/
83+
public function testUnifiedCli()
84+
{
85+
$diff = new Diff(
86+
file_get_contents('tests/resources/a.txt'),
87+
file_get_contents('tests/resources/b.txt')
88+
);
89+
90+
$renderer = new Diff\Renderer\Text\UnifiedCli();
91+
$result = $diff->render($renderer);
92+
if ($this->genOutputFiles) {
93+
file_put_contents('textUnifiedCli.txt', $result);
94+
}
95+
$this->assertStringEqualsFile('tests/resources/ab.diff', $result);
96+
}
7097
}
98+

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)