Permalink
Browse files

Merge pull request #479 from hans-d/fix_win_eol

Fix win eol
  • Loading branch information...
2 parents 6c5ff22 + b338b7f commit 00fe3a3a77976f89e6218225f2f0211818db7b90 @nateabele nateabele committed May 23, 2012
Showing with 23 additions and 0 deletions.
  1. +23 −0 test/Unit.php
View
@@ -238,6 +238,25 @@ public function fail($message = false) {
}
/**
+ * Fixes some issues regarding the used EOL character(s).
+ *
+ * On linux EOL is LF, on Windows it is normally CRLF, but the latter may depend also
+ * on the git config core.autocrlf setting. As some tests use heredoc style (<<<) to
+ * specify multiline expectations, this EOL issue may cause tests to fail only because
+ * of a difference in EOL's used.
+ *
+ * in assertEqual, assertNotEqual, assertPattern and assertNotPattern this function is
+ * called to get rid of any EOL differences.
+ */
+ protected function _normalizeLineEndings($expected, $result) {
+ if (is_string($expected) && is_string($result)) {
+ $expected = preg_replace('/\r\n/', "\n", $expected);
+ $result = preg_replace('/\r\n/', "\n", $result);
+ }
+ return array($expected, $result);
+ }
+
+ /**
* Checks that the actual result is equal, but not neccessarily identical, to the expected
* result.
*
@@ -246,6 +265,7 @@ public function fail($message = false) {
* @param string|boolean $message
*/
public function assertEqual($expected, $result, $message = false) {
+ list($expected, $result) = $this->_normalizeLineEndings($expected, $result);
$data = ($expected != $result) ? $this->_compare('equal', $expected, $result) : null;
$this->assert($expected == $result, $message, $data);
}
@@ -258,6 +278,7 @@ public function assertEqual($expected, $result, $message = false) {
* @param string|boolean $message
*/
public function assertNotEqual($expected, $result, $message = false) {
+ list($expected, $result) = $this->_normalizeLineEndings($expected, $result);
$this->assert($result != $expected, $message, compact('expected', 'result'));
}
@@ -340,6 +361,7 @@ public function assertNull($result, $message = '{:message}') {
* @param string $message
*/
public function assertNoPattern($expected, $result, $message = '{:message}') {
+ list($expected, $result) = $this->_normalizeLineEndings($expected, $result);
$this->assert(!preg_match($expected, $result), $message, compact('expected', 'result'));
}
@@ -351,6 +373,7 @@ public function assertNoPattern($expected, $result, $message = '{:message}') {
* @param string $message
*/
public function assertPattern($expected, $result, $message = '{:message}') {
+ list($expected, $result) = $this->_normalizeLineEndings($expected, $result);
$this->assert(!!preg_match($expected, $result), $message, compact('expected', 'result'));
}

0 comments on commit 00fe3a3

Please sign in to comment.