Skip to content

Commit ff31bb8

Browse files
committed
Add more tests
1 parent f09e779 commit ff31bb8

File tree

1 file changed

+65
-0
lines changed

1 file changed

+65
-0
lines changed

tests/Diff/DiffTest.php

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
<?php
2+
3+
namespace Tests\Diff;
4+
5+
use jblond\Diff;
6+
use jblond\Diff\Renderer\Text\Unified;
7+
use jblond\Diff\Renderer\Html\SideBySide;
8+
use jblond\Diff\Renderer\Text\Json;
9+
use PHPUnit\Framework\TestCase;
10+
11+
class DiffTest extends TestCase
12+
{
13+
public function testIdenticalStrings()
14+
{
15+
$diff = new Diff("Hello", "Hello");
16+
$this->assertTrue($diff->isIdentical());
17+
$this->assertFalse($diff->render(new Unified()));
18+
}
19+
20+
public function testCompletelyDifferentStrings()
21+
{
22+
$diff = new Diff("A", "B");
23+
$output = $diff->render(new Unified());
24+
$this->assertStringContainsString("-A", $output);
25+
$this->assertStringContainsString("+B", $output);
26+
}
27+
28+
public function testIgnoreWhitespace()
29+
{
30+
$options = ['ignoreWhitespace' => true];
31+
$diff = new Diff("Hello World", "Hello World", $options);
32+
$this->assertTrue($diff->isIdentical());
33+
}
34+
35+
public function testIgnoreCase()
36+
{
37+
$options = ['ignoreCase' => true];
38+
$diff = new Diff("Hello", "hello", $options);
39+
$this->assertTrue($diff->isIdentical());
40+
}
41+
42+
public function testHtmlRendererOutput()
43+
{
44+
$diff = new Diff("foo", "bar");
45+
$output = $diff->render(new SideBySide());
46+
$this->assertStringContainsString("<table", $output);
47+
$this->assertStringContainsString("</table>", $output);
48+
}
49+
50+
public function testJsonRendererOutput()
51+
{
52+
$diff = new Diff("foo", "bar");
53+
$output = $diff->render(new Json());
54+
$decoded = json_decode($output, true);
55+
56+
$this->assertIsArray($decoded);
57+
$this->assertNotEmpty($decoded);
58+
}
59+
60+
public function testEmptyInputs()
61+
{
62+
$diff = new Diff("", "");
63+
$this->assertTrue($diff->isIdentical());
64+
}
65+
}

0 commit comments

Comments
 (0)