Skip to content

Commit de175a4

Browse files
authored
Merge pull request #6 from JBlond/unittests
Unittests
2 parents fe69c4f + 77323c6 commit de175a4

File tree

5 files changed

+78
-5
lines changed

5 files changed

+78
-5
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/vendor

composer.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,12 @@
2121
"php" : ">= 5.4",
2222
"ext-mbstring": "*"
2323
},
24+
"require-dev": {
25+
"phpunit/phpunit": "7.*"
26+
},
2427
"autoload": {
25-
"psr-0": {
26-
"Diff": "lib/"
28+
"psr-4": {
29+
"jblond\\Diff\\": "lib/jblond"
2730
}
2831
}
2932
}

lib/jblond/Diff/Renderer/Html/HtmlArray.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ private function getChangeExtent($fromLine, $toLine)
218218
/**
219219
* Format a series of lines suitable for output in a HTML rendered diff.
220220
* This involves replacing tab characters with spaces, making the HTML safe
221-
* for output, ensuring that double spaces are replaced with   etc.
221+
* for output, ensuring that double spaces are replaced with   etc.
222222
*
223223
* @param array $lines Array of lines to format.
224224
* @return array Array of the formatted lines.
@@ -236,7 +236,7 @@ protected function formatLines($lines)
236236
}
237237

238238
/**
239-
* Replace a string containing spaces with a HTML representation using  .
239+
* Replace a string containing spaces with a HTML representation using  .
240240
*
241241
* @param array $matches The string of spaces.
242242
* @return string The HTML representation of the string.
@@ -252,7 +252,7 @@ protected function fixSpaces($matches)
252252
}
253253
$div = floor($count / 2);
254254
$mod = $count % 2;
255-
$buffer .= str_repeat('  ', $div).str_repeat(' ', $mod);
255+
$buffer .= str_repeat('  ', $div).str_repeat(' ', $mod);
256256
}
257257

258258
$div = floor($count / 2);

tests/Diff/Renderer/ArrayTest.php

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
<?php
2+
namespace Tests\Diff\Renderer\Html;
3+
use jblond\Autoloader;
4+
use jblond\Diff\Renderer\Html\HtmlArray;
5+
use PHPUnit\Framework\TestCase;
6+
7+
require "../../../lib/Autoloader.php";
8+
new Autoloader();
9+
10+
class ArrayTest extends TestCase
11+
{
12+
public function testRenderSimpleDelete()
13+
{
14+
$htmlRenderer = new HtmlArray();
15+
$htmlRenderer->diff = new \jblond\Diff(
16+
array('a'),
17+
array()
18+
);
19+
$result = $htmlRenderer->render();
20+
static::assertEquals(array(
21+
array(
22+
array(
23+
'tag' => 'delete',
24+
'base' => array(
25+
'offset' => 0,
26+
'lines' => array(
27+
'a'
28+
)
29+
),
30+
'changed' => array(
31+
'offset' => 0,
32+
'lines' => array()
33+
)
34+
)
35+
)
36+
), $result);
37+
}
38+
public function testRenderFixesSpaces()
39+
{
40+
$htmlRenderer = new HtmlArray();
41+
$htmlRenderer->diff = new \jblond\Diff(
42+
array(' a'),
43+
array('a')
44+
);
45+
$result = $htmlRenderer->render();
46+
static::assertEquals(array(
47+
array(
48+
array(
49+
'tag' => 'replace',
50+
'base' => array(
51+
'offset' => 0,
52+
'lines' => array(
53+
'<del>&#xA0; &#xA0;</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+
//require_once __DIR__ .
3+
require_once '../lib/Autoloader.php';

0 commit comments

Comments
 (0)