Permalink
Browse files

Removed Constants from Diff, put into tests for readability

  • Loading branch information...
1 parent f68d44e commit 5b2cb846603bfa60831ead027cb2e71282c542e8 @pscheit pscheit committed Feb 9, 2012
Showing with 31 additions and 31 deletions.
  1. +10 −15 PHPUnit/Util/Diff.php
  2. +21 −16 Tests/Util/DiffTest.php
View
@@ -59,11 +59,6 @@
*/
class PHPUnit_Util_Diff
{
-
- const REMOVED = 2;
- const ADDED = 1;
- const OLD = 0;
-
/**
* Returns the diff between two arrays or strings as string.
*
@@ -81,7 +76,7 @@ public static function diff($from, $to)
$old = array();
foreach ($diff as $line) {
- if ($line[1] === self::OLD) {
+ if ($line[1] === 0 /* OLD */) {
if ($inOld === FALSE) {
$inOld = $i;
}
@@ -120,11 +115,11 @@ public static function diff($from, $to)
$newChunk = FALSE;
}
- if ($diff[$i][1] === self::ADDED) {
+ if ($diff[$i][1] === 1 /* ADDED */) {
$buffer .= '+' . $diff[$i][0] . "\n";
}
- else if ($diff[$i][1] === self::REMOVED) {
+ else if ($diff[$i][1] === 2 /* REMOVED */) {
$buffer .= '-' . $diff[$i][0] . "\n";
}
@@ -195,37 +190,37 @@ public static function diffToArray($from, $to) {
$line = 0;
foreach ($start as $token) {
- $diff[] = array($token, self::OLD);
+ $diff[] = array($token, 0 /* OLD */);
}
reset($from);
reset($to);
foreach ($common as $token) {
while ((($fromToken = reset($from)) !== $token)) {
- $diff[] = array(array_shift($from), self::REMOVED);
+ $diff[] = array(array_shift($from), 2 /* REMOVED */);
}
while ((($toToken = reset($to)) !== $token)) {
- $diff[] = array(array_shift($to), self::ADDED);
+ $diff[] = array(array_shift($to), 1 /* ADDED */);
}
- $diff[] = array($token, self::OLD);
+ $diff[] = array($token, 0 /* OLD */);
array_shift($from);
array_shift($to);
}
while (($token = array_shift($from)) !== NULL) {
- $diff[] = array($token, self::REMOVED);
+ $diff[] = array($token, 2 /* REMOVED */);
}
while (($token = array_shift($to)) !== NULL) {
- $diff[] = array($token, self::ADDED);
+ $diff[] = array($token, 1 /* ADDED */);
}
foreach ($end as $token) {
- $diff[] = array($token, self::OLD);
+ $diff[] = array($token, 0 /* OLD */);
}
return $diff;
@@ -55,6 +55,11 @@
*/
class Util_DiffTest extends PHPUnit_Framework_TestCase
{
+
+ const REMOVED = 2;
+ const ADDED = 1;
+ const OLD = 0;
+
/**
* @covers PHPUnit_Util_Diff::diff
*/
@@ -72,8 +77,8 @@ public function testComparisonErrorMessage()
public function testComparisonErrorMessage_toArray()
{
$diff = array();
- $diff[] = array('a', PHPUnit_Util_DIFF::REMOVED);
- $diff[] = array('b', PHPUnit_Util_DIFF::ADDED);
+ $diff[] = array('a', self::REMOVED);
+ $diff[] = array('b', self::ADDED);
$this->assertEquals(
$diff,
@@ -98,8 +103,8 @@ public function testComparisonErrorStartSame()
public function testComparisonErrorStartSame_toArray()
{
$diff = array();
- $diff[] = array('ba', PHPUnit_Util_DIFF::REMOVED);
- $diff[] = array('bc', PHPUnit_Util_DIFF::ADDED);
+ $diff[] = array('ba', self::REMOVED);
+ $diff[] = array('bc', self::ADDED);
$this->assertEquals(
$diff,
@@ -124,8 +129,8 @@ public function testComparisonErrorEndSame()
public function testComparisonErrorEndSame_toArray()
{
$diff = array();
- $diff[] = array('ab', PHPUnit_Util_DIFF::REMOVED);
- $diff[] = array('cb', PHPUnit_Util_DIFF::ADDED);
+ $diff[] = array('ab', self::REMOVED);
+ $diff[] = array('cb', self::ADDED);
$this->assertEquals(
$diff,
@@ -150,8 +155,8 @@ public function testComparisonErrorStartAndEndSame()
public function testComparisonErrorStartAndEndSame_toArray()
{
$diff = array();
- $diff[] = array('abc', PHPUnit_Util_DIFF::REMOVED);
- $diff[] = array('adc', PHPUnit_Util_DIFF::ADDED);
+ $diff[] = array('abc', self::REMOVED);
+ $diff[] = array('adc', self::ADDED);
$this->assertEquals(
$diff,
@@ -176,8 +181,8 @@ public function testComparisonErrorStartSameComplete()
public function testComparisonErrorStartSameComplete_toArray()
{
$diff = array();
- $diff[] = array('ab', PHPUnit_Util_DIFF::REMOVED);
- $diff[] = array('abc', PHPUnit_Util_DIFF::ADDED);
+ $diff[] = array('ab', self::REMOVED);
+ $diff[] = array('abc', self::ADDED);
$this->assertEquals(
$diff,
@@ -202,8 +207,8 @@ public function testComparisonErrorEndSameComplete()
public function testComparisonErrorEndSameComplete_toArray()
{
$diff = array();
- $diff[] = array('bc', PHPUnit_Util_DIFF::REMOVED);
- $diff[] = array('abc', PHPUnit_Util_DIFF::ADDED);
+ $diff[] = array('bc', self::REMOVED);
+ $diff[] = array('abc', self::ADDED);
$this->assertEquals(
$diff,
@@ -228,8 +233,8 @@ public function testComparisonErrorOverlapingMatches()
public function testComparisonErrorOverlapingMatches_toArray()
{
$diff = array();
- $diff[] = array('abc', PHPUnit_Util_DIFF::REMOVED);
- $diff[] = array('abbc', PHPUnit_Util_DIFF::ADDED);
+ $diff[] = array('abc', self::REMOVED);
+ $diff[] = array('abbc', self::ADDED);
$this->assertEquals(
$diff,
@@ -254,8 +259,8 @@ public function testComparisonErrorOverlapingMatches2()
public function testComparisonErrorOverlapingMatches2_toArray()
{
$diff = array();
- $diff[] = array('abcdde', PHPUnit_Util_DIFF::REMOVED);
- $diff[] = array('abcde', PHPUnit_Util_DIFF::ADDED);
+ $diff[] = array('abcdde', self::REMOVED);
+ $diff[] = array('abcde', self::ADDED);
$this->assertEquals(
$diff,

0 comments on commit 5b2cb84

Please sign in to comment.