Skip to content

Unittests #6

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 5 commits into from
Jan 15, 2019
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/vendor
7 changes: 5 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,12 @@
"php" : ">= 5.4",
"ext-mbstring": "*"
},
"require-dev": {
"phpunit/phpunit": "7.*"
},
"autoload": {
"psr-0": {
"Diff": "lib/"
"psr-4": {
"jblond\\Diff\\": "lib/jblond"
}
}
}
2 changes: 1 addition & 1 deletion lib/jblond/Diff.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
* @author Chris Boulton <[email protected]>
* @copyright (c) 2009 Chris Boulton
* @license New BSD License http://www.opensource.org/licenses/bsd-license.php
* @version 1.4
* @version 1.5
* @link https://github.com/JBlond/php-diff
*/

Expand Down
8 changes: 4 additions & 4 deletions lib/jblond/Diff/Renderer/Html/HtmlArray.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
* @author Chris Boulton <[email protected]>
* @copyright (c) 2009 Chris Boulton
* @license New BSD License http://www.opensource.org/licenses/bsd-license.php
* @version 1.4
* @version 1.5
* @link https://github.com/JBlond/php-diff
*/

Expand Down Expand Up @@ -218,7 +218,7 @@ private function getChangeExtent($fromLine, $toLine)
/**
* Format a series of lines suitable for output in a HTML rendered diff.
* This involves replacing tab characters with spaces, making the HTML safe
* for output, ensuring that double spaces are replaced with &nbsp; etc.
* for output, ensuring that double spaces are replaced with &#xA0; etc.
*
* @param array $lines Array of lines to format.
* @return array Array of the formatted lines.
Expand All @@ -236,7 +236,7 @@ protected function formatLines($lines)
}

/**
* Replace a string containing spaces with a HTML representation using &nbsp;.
* Replace a string containing spaces with a HTML representation using &#xA0;.
*
* @param array $matches The string of spaces.
* @return string The HTML representation of the string.
Expand All @@ -252,7 +252,7 @@ protected function fixSpaces($matches)
}
$div = floor($count / 2);
$mod = $count % 2;
$buffer .= str_repeat('&nbsp; ', $div).str_repeat('&#xA0;', $mod);
$buffer .= str_repeat('&#xA0; ', $div).str_repeat('&#xA0;', $mod);
}

$div = floor($count / 2);
Expand Down
2 changes: 1 addition & 1 deletion lib/jblond/Diff/Renderer/Html/Inline.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
* @author Chris Boulton <[email protected]>
* @copyright (c) 2009 Chris Boulton
* @license New BSD License http://www.opensource.org/licenses/bsd-license.php
* @version 1.4
* @version 1.5
* @link https://github.com/JBlond/php-diff
*/

Expand Down
2 changes: 1 addition & 1 deletion lib/jblond/Diff/Renderer/Html/SideBySide.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
* @author Chris Boulton <[email protected]>
* @copyright (c) 2009 Chris Boulton
* @license New BSD License http://www.opensource.org/licenses/bsd-license.php
* @version 1.4
* @version 1.5
* @link https://github.com/JBlond/php-diff
*/

Expand Down
2 changes: 1 addition & 1 deletion lib/jblond/Diff/Renderer/RendererAbstract.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
* @author Chris Boulton <[email protected]>
* @copyright (c) 2009 Chris Boulton
* @license New BSD License http://www.opensource.org/licenses/bsd-license.php
* @version 1.4
* @version 1.5
* @link https://github.com/JBlond/php-diff
*/

Expand Down
2 changes: 1 addition & 1 deletion lib/jblond/Diff/Renderer/Text/Context.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
* @author Chris Boulton <[email protected]>
* @copyright (c) 2009 Chris Boulton
* @license New BSD License http://www.opensource.org/licenses/bsd-license.php
* @version 1.4
* @version 1.5
* @link https://github.com/JBlond/php-diff
*/

Expand Down
2 changes: 1 addition & 1 deletion lib/jblond/Diff/Renderer/Text/Unified.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
* @author Chris Boulton <[email protected]>
* @copyright (c) 2009 Chris Boulton
* @license New BSD License http://www.opensource.org/licenses/bsd-license.php
* @version 1.4
* @version 1.5
* @link https://github.com/JBlond/php-diff
*/

Expand Down
2 changes: 1 addition & 1 deletion lib/jblond/Diff/SequenceMatcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
* @author Chris Boulton <[email protected]>
* @copyright (c) 2009 Chris Boulton
* @license New BSD License http://www.opensource.org/licenses/bsd-license.php
* @version 1.4
* @version 1.5
* @link https://github.com/JBlond/php-diff
*/

Expand Down
66 changes: 66 additions & 0 deletions tests/Diff/Renderer/ArrayTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
<?php
namespace Tests\Diff\Renderer\Html;
use jblond\Autoloader;
use jblond\Diff\Renderer\Html\HtmlArray;
use PHPUnit\Framework\TestCase;

require "../../../lib/Autoloader.php";
new Autoloader();

class ArrayTest extends TestCase
{
public function testRenderSimpleDelete()
{
$htmlRenderer = new HtmlArray();
$htmlRenderer->diff = new \jblond\Diff(
array('a'),
array()
);
$result = $htmlRenderer->render();
static::assertEquals(array(
array(
array(
'tag' => 'delete',
'base' => array(
'offset' => 0,
'lines' => array(
'a'
)
),
'changed' => array(
'offset' => 0,
'lines' => array()
)
)
)
), $result);
}
public function testRenderFixesSpaces()
{
$htmlRenderer = new HtmlArray();
$htmlRenderer->diff = new \jblond\Diff(
array(' a'),
array('a')
);
$result = $htmlRenderer->render();
static::assertEquals(array(
array(
array(
'tag' => 'replace',
'base' => array(
'offset' => 0,
'lines' => array(
'<del>&#xA0; &#xA0;</del>a',
)
),
'changed' => array(
'offset' => 0,
'lines' => array(
'<ins></ins>a'
)
)
)
)
), $result);
}
}
3 changes: 3 additions & 0 deletions tests/bootstrap.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<?php
//require_once __DIR__ .
require_once '../lib/Autoloader.php';