Skip to content

Commit 2545d47

Browse files
author
Petr Kotek
committed
Tests: add test covering area we're going to change
1 parent f4db229 commit 2545d47

File tree

4 files changed

+86
-7
lines changed

4 files changed

+86
-7
lines changed

composer.json

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,19 @@
11
{
22
"name": "chrisboulton/php-diff",
3-
"type": "library",
3+
"type": "library",
44
"description": "A comprehensive library for generating differences between two hashable objects (strings or arrays).",
55
"authors": [
66
{
77
"name": "Chris Boulton",
88
"email": "@chrisboulton"
99
}
1010
],
11-
"autoload": {
12-
"psr-0": {
13-
"Diff": "lib/"
14-
}
15-
}
16-
}
11+
"autoload": {
12+
"psr-0": {
13+
"Diff": "lib/"
14+
}
15+
},
16+
"require-dev": {
17+
"phpunit/phpunit": "~5.5"
18+
}
19+
}

phpunit.xml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<phpunit bootstrap="vendor/autoload.php">
2+
<testsuites>
3+
<testsuite name="unit">
4+
<directory>tests</directory>
5+
</testsuite>
6+
</testsuites>
7+
</phpunit>
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
<?php
2+
3+
namespace Tests\Diff\Renderer\Html;
4+
5+
class ArrayTest extends \PHPUnit_Framework_TestCase
6+
{
7+
public function testRenderSimpleDelete()
8+
{
9+
$htmlRenderer = new \Diff_Renderer_Html_Array();
10+
$htmlRenderer->diff = new \Diff(
11+
array('a'),
12+
array()
13+
);
14+
15+
$result = $htmlRenderer->render();
16+
17+
static::assertEquals(array(
18+
array(
19+
array(
20+
'tag' => 'delete',
21+
'base' => array(
22+
'offset' => 0,
23+
'lines' => array(
24+
'a'
25+
)
26+
),
27+
'changed' => array(
28+
'offset' => 0,
29+
'lines' => array()
30+
)
31+
)
32+
)
33+
), $result);
34+
}
35+
36+
public function testRenderFixesSpaces()
37+
{
38+
$htmlRenderer = new \Diff_Renderer_Html_Array();
39+
$htmlRenderer->diff = new \Diff(
40+
array(' a'),
41+
array('a')
42+
);
43+
44+
$result = $htmlRenderer->render();
45+
46+
static::assertEquals(array(
47+
array(
48+
array(
49+
'tag' => 'replace',
50+
'base' => array(
51+
'offset' => 0,
52+
'lines' => array(
53+
'<del>&nbsp; &nbsp;</del>a',
54+
)
55+
),
56+
'changed' => array(
57+
'offset' => 0,
58+
'lines' => array(
59+
'<ins></ins>a'
60+
)
61+
)
62+
)
63+
)
64+
), $result);
65+
}
66+
}

tests/bootstrap.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<?php
2+
3+
require_once __DIR__ . '/../vendor/autoload.php';

0 commit comments

Comments
 (0)