Skip to content

Cli unittest #46

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

Merged
merged 2 commits into from
Jul 13, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions tests/Diff/Renderer/Html/HtmlRenderersTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ public function __construct($name = null, array $data = [], $dataName = '')
parent::__construct($name, $data, $dataName);
}

/**
* @covers \jblond\Diff\Renderer\Html\SideBySide
*/
public function testSideBySide()
{
$diff = new Diff(
Expand All @@ -53,6 +56,9 @@ public function testSideBySide()
$this->assertStringEqualsFile('tests/resources/htmlSideBySide.txt', $result);
}

/**
* @covers \jblond\Diff\Renderer\Html\Inline
*/
public function testInline()
{
$diff = new Diff(
Expand All @@ -69,6 +75,9 @@ public function testInline()
$this->assertStringEqualsFile('tests/resources/htmlInline.txt', $result);
}

/**
* @covers \jblond\Diff\Renderer\Html\Unified
*/
public function testUnified()
{
$diff = new Diff(
Expand Down
28 changes: 28 additions & 0 deletions tests/Diff/Renderer/Text/TextRenderersTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ public function __construct($name = null, array $data = [], $dataName = '')
parent::__construct($name, $data, $dataName);
}

/**
* Test context
* @covers \jblond\Diff\Renderer\Text\Context
*/
public function testContext()
{
$diff = new Diff(
Expand All @@ -52,6 +56,10 @@ public function testContext()
$this->assertStringEqualsFile('tests/resources/textContext.txt', $result);
}

/**
* Test Unified
* @covers \jblond\Diff\Renderer\Text\Unified
*/
public function testUnified()
{
$diff = new Diff(
Expand All @@ -67,4 +75,24 @@ public function testUnified()

$this->assertStringEqualsFile('tests/resources/textUnified.txt', $result);
}

/**
* Test Unified Cli
* @covers \jblond\Diff\Renderer\Text\UnifiedCli
*/
public function testUnifiedCli()
{
$diff = new Diff(
file_get_contents('tests/resources/a.txt'),
file_get_contents('tests/resources/b.txt')
);

$renderer = new Diff\Renderer\Text\UnifiedCli();
$result = $diff->render($renderer);
if ($this->genOutputFiles) {
file_put_contents('textUnifiedCli.txt', $result);
}
$this->assertStringEqualsFile('tests/resources/ab.diff', $result);
}
}

42 changes: 42 additions & 0 deletions tests/resources/ab.diff
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
@@ -1,22 +1,22 @@
<html>
<head>
<meta http-equiv="Content-type" content="text/html; charset=utf-8"/>
- <title>Hello World!</title>
+ <title>Hello You!</title>
</head>
<body>
<h1>This is demo content to show features of the php-diff package.</h1>
- <h2>This line is removed from version2.</h2>
<h2>This line is the same for both versions.</h2>
- <h2>This line has inline differences between both versions.</h2>
+ <h2>This line has differences between both versions.</h2>
<h2>This line is the same for both versions.</h2>
- <h2>This line also has inline differences between both versions.</h2>
+ <h2>This line also has InLine differences between both versions.</h2>
<h2>This line is the same for both versions.</h2>
+ <h2>This line is added to version2.</h2>

<p>
It's also compatible with multibyte characters (like Chinese and emoji) as shown below:
- 另外我覺得那個評價的白色櫃子有點沒有必要欸。外觀我就不說了 ,怎麼連空間都那麼狹隘。不過倒是從這個地方看出所謂的“改革”
- Do you know what "金槍魚罐頭" means in Chinese?
- 🍏🍎🙂
+ 另外我覺得那個評鑑的白色櫃子有點沒有必要欸。外觀我就不說了 ,怎麼連空間都那麼狹隘。不過倒是從這個地方看出所謂的“改革”
+ Do you know what "魚の缶詰" means in Chinese?
+ 🍎🍏🙂
</p>

<p>Just some lines to demonstrate the collapsing of a block of lines which are the same in both versions.</p>
@@ -25,9 +25,9 @@
<p>Just some lines to demonstrate the collapsing of a block of lines which are the same in both versions.</p>
<p>Just some lines to demonstrate the collapsing of a block of lines which are the same in both versions.</p>
<p>Just some lines to demonstrate the collapsing of a block of lines which are the same in both versions.</p>
- <h2>This line also has inline differences between both versions. It's the whitespace in front.</h2>
+ <h2>This line also has inline differences between both versions. It's the whitespace in front.</h2>
<h2>This line is the same for both versions.</h2>
- <h2>This line also has inline differences between both versions.</h2>
+ <h2>This line also has inline differences between both versions!</h2>
</body>
</html>