Skip to content
Browse files

suppressEolIssues

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.
  • Loading branch information...
1 parent 88a2d12 commit b76035226237739b209d0b90654631d3ae6a2d2b @hans-d hans-d committed
Showing with 28 additions and 0 deletions.
  1. +28 −0 test/Unit.php
View
28 test/Unit.php
@@ -238,6 +238,22 @@ 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 _suppressEolIssues(&$expected, &$result) {
+ $expected = preg_replace('/\r\n/', "\n", $expected);
+ $result = preg_replace('/\r\n/', "\n", $result);
+ }
+
+ /**
* Checks that the actual result is equal, but not neccessarily identical, to the expected
* result.
*
@@ -246,6 +262,9 @@ public function fail($message = false) {
* @param string|boolean $message
*/
public function assertEqual($expected, $result, $message = false) {
+ if (is_string($expected) && is_string($result)) {
+ $this->_suppressEolIssues($expected, $result);
+ }
$data = ($expected != $result) ? $this->_compare('equal', $expected, $result) : null;
$this->assert($expected == $result, $message, $data);
}
@@ -258,6 +277,9 @@ public function assertEqual($expected, $result, $message = false) {
* @param string|boolean $message
*/
public function assertNotEqual($expected, $result, $message = false) {
+ if (is_string($expected) && is_string($result)) {
+ $this->_suppressEolIssues($expected, $result);
+ }
$this->assert($result != $expected, $message, compact('expected', 'result'));
}
@@ -340,6 +362,9 @@ public function assertNull($result, $message = '{:message}') {
* @param string $message
*/
public function assertNoPattern($expected, $result, $message = '{:message}') {
+ if (is_string($expected) && is_string($result)) {
+ $this->_suppressEolIssues($expected, $result);
+ }
$this->assert(!preg_match($expected, $result), $message, compact('expected', 'result'));
}
@@ -351,6 +376,9 @@ public function assertNoPattern($expected, $result, $message = '{:message}') {
* @param string $message
*/
public function assertPattern($expected, $result, $message = '{:message}') {
+ if (is_string($expected) && is_string($result)) {
+ $this->_suppressEolIssues($expected, $result);
+ }
$this->assert(!!preg_match($expected, $result), $message, compact('expected', 'result'));
}

0 comments on commit b760352

Please sign in to comment.
Something went wrong with that request. Please try again.