Skip to content

Commit

Permalink
Fixes #581: Windows diffs where polluted with extra newlines
Browse files Browse the repository at this point in the history
  • Loading branch information
edorian committed Sep 6, 2012
1 parent 5f0a76f commit 6f60604
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 1 deletion.
1 change: 1 addition & 0 deletions ChangeLog.markdown
Expand Up @@ -28,6 +28,7 @@ PHPUnit 3.7.0
* Fixed #322 #320 thanks to #607: Commandline option now override group/exclude settings in phpunit.xml
* Fixed #440: Possible crash when using `--process-isolation` with PHP 5.3 and `detect_unicode=on`.
* Fixed #523: `assertAttributeEquals()` now works with classes extending internal classes like `ArrayIterator`.
* Fixed #581: Generating a diffs could add extra newlines in Windows.
* It is possible again to expect the generic `Exception` class.
* Removed `addUncoveredFilesFromWhitelist` configuration setting.
* Removed deprecated `--skeleton-class` and `--skeleton-test` switches. The functionality is now provided by the `phpunit-skel` command of the `PHPUnit_SkeletonGenerator` package.
Expand Down
2 changes: 1 addition & 1 deletion PHPUnit/Util/Type.php
Expand Up @@ -133,7 +133,7 @@ protected static function recursiveExport($value, $indentation, &$processedObjec
}

return "'" .
str_replace(array("\n\r", "\r"), array("\n", "\n"), $value) .
str_replace(array("\r\n", "\n\r", "\r"), array("\n", "\n", "\n"), $value) .
"'";
}

Expand Down
43 changes: 43 additions & 0 deletions Tests/Regression/GitHub/581.phpt
@@ -0,0 +1,43 @@
--TEST--
GH-581: PHPUnit_Util_Type::export adds extra newlines in Windows
--FILE--
<?php

$_SERVER['argv'][1] = '--no-configuration';
$_SERVER['argv'][2] = 'Issue581Test';
$_SERVER['argv'][3] = dirname(__FILE__).'/581/Issue581Test.php';

require_once dirname(dirname(dirname(dirname(__FILE__)))) . '/PHPUnit/Autoload.php';
PHPUnit_TextUI_Command::main();
?>
--EXPECTF--
PHPUnit %s by Sebastian Bergmann.

F

Time: %i %s, Memory: %sMb

There was 1 failure:

1) Issue581Test::testExportingObjectsDoesNotBreakWindowsLineFeeds
Failed asserting that two objects are equal.
--- Expected
+++ Actual
@@ @@
stdClass Object (
0 => 1
1 => 2
2 => 'Test\n'
3 => 4
- 4 => 5
+ 4 => 1
5 => 6
6 => 7
7 => 8
)

%s:%i

FAILURES!
Tests: 1, Assertions: 1, Failures: 1.

10 changes: 10 additions & 0 deletions Tests/Regression/GitHub/581/Issue581Test.php
@@ -0,0 +1,10 @@
<?php
class Issue581Test extends PHPUnit_Framework_TestCase
{
public function testExportingObjectsDoesNotBreakWindowsLineFeeds() {
$this->assertEquals(
(object)array(1,2,"Test\r\n",4,5,6,7,8),
(object)array(1,2,"Test\r\n",4,1,6,7,8)
);
}
}

0 comments on commit 6f60604

Please sign in to comment.